system.install
Same filename and directory in other branches
Install, update and uninstall functions for the system module.
File
-
core/
modules/ system/ system.install
View source
<?php
/**
* @file
* Install, update and uninstall functions for the system module.
*/
use Drupal\Component\Utility\Crypt;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Update\EquivalentUpdate;
// cspell:ignore quickedit
/**
* An array of machine names of modules that were removed from Drupal core.
*/
const DRUPAL_CORE_REMOVED_MODULE_LIST = [
'action' => 'Action UI',
'book' => 'Book',
'aggregator' => 'Aggregator',
'ckeditor' => 'CKEditor',
'color' => 'Color',
'forum' => 'Forum',
'hal' => 'HAL',
'quickedit' => 'Quick Edit',
'rdf' => 'RDF',
'statistics' => 'Statistics',
'tour' => 'Tour',
'tracker' => 'Tracker',
];
/**
* An array of machine names of themes that were removed from Drupal core.
*/
const DRUPAL_CORE_REMOVED_THEME_LIST = [
'bartik' => 'Bartik',
'classy' => 'Classy',
'seven' => 'Seven',
'stable' => 'Stable',
];
/**
* Implements hook_install().
*/
function system_install() : void {
// Populate the cron key state variable.
$cron_key = Crypt::randomBytesBase64(55);
\Drupal::state()->set('system.cron_key', $cron_key);
// Populate the site UUID and default name (if not set).
$site = \Drupal::configFactory()->getEditable('system.site');
$site->set('uuid', \Drupal::service('uuid')->generate());
if (!$site->get('name')) {
$site->set('name', 'Drupal');
}
$site->save(TRUE);
// Populate the dummy query string added to all CSS and JavaScript files.
\Drupal::service('asset.query_string')->reset();
}
/**
* Implements hook_schema().
*/
function system_schema() : array {
// @deprecated The sequences table has been deprecated in drupal:10.2.0 and is
// removed from drupal:12.0.0. See https://www.drupal.org/node/3220378.
// @todo Remove sequences table in Drupal 12. See https://www.drupal.org/i/3335756
$schema['sequences'] = [
'description' => 'Stores IDs.',
'fields' => [
'value' => [
'description' => 'The value of the sequence.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
],
],
'primary key' => [
'value',
],
];
return $schema;
}
/**
* Implements hook_update_last_removed().
*/
function system_update_last_removed() : int {
return 10201;
}
/**
* Add a [time] column to the {simpletest} table, if existing.
*/
function system_update_11200() : void {
$schema = \Drupal::database()->schema();
if ($schema->tableExists('simpletest') && !$schema->fieldExists('simpletest', 'time')) {
$schema->addField('simpletest', 'time', [
'type' => 'float',
'not null' => TRUE,
'default' => 0,
'description' => 'Time elapsed for the execution of the test.',
]);
}
}
/**
* Invalidate container because the module handler has changed.
*/
function system_update_11100() : void {
\Drupal::service('kernel')->invalidateContainer();
}
/**
* Update length of menu_tree fields url and route_param_key from 255 to 2048.
*/
function system_update_11001() : void {
$schema = \Drupal::database()->schema();
$spec = [
'description' => 'The external path this link points to (when not using a route).',
'type' => 'varchar',
'length' => 2048,
'not null' => TRUE,
'default' => '',
];
$schema->changeField('menu_tree', 'url', 'url', $spec);
$spec = [
'description' => 'An encoded string of route parameters for loading by route.',
'type' => 'varchar',
'length' => 2048,
];
$schema->changeField('menu_tree', 'route_param_key', 'route_param_key', $spec);
}
/**
* Equivalent update to 10400.
*/
function system_update_11102() : TranslatableMarkup|null {
// This is a no-op that exists to prevent an upgrade from 10.4+ to 11.0. That
// path is actually a downgrade.
$equivalent_update = \Drupal::service('update.update_hook_registry')->getEquivalentUpdate();
if ($equivalent_update instanceof EquivalentUpdate) {
return $equivalent_update->toSkipMessage();
}
return NULL;
}
/**
* Add the [alias] field to the {router} table.
*/
function system_update_11201() : void {
$schema = \Drupal::database()->schema();
if ($schema->tableExists('router') && !$schema->fieldExists('router', 'alias')) {
$spec = [
'fields' => [
'alias' => [
'description' => 'The alias of the route, if applicable.',
'type' => 'varchar_ascii',
'length' => 255,
],
],
];
$schema->addField('router', 'alias', $spec['fields']['alias']);
$schema->addIndex('router', 'alias', [
'alias',
], $spec);
}
}
Functions
Title | Deprecated | Summary |
---|---|---|
system_install | Implements hook_install(). | |
system_schema | Implements hook_schema(). | |
system_update_11001 | Update length of menu_tree fields url and route_param_key from 255 to 2048. | |
system_update_11100 | Invalidate container because the module handler has changed. | |
system_update_11102 | Equivalent update to 10400. | |
system_update_11200 | Add a [time] column to the {simpletest} table, if existing. | |
system_update_11201 | Add the [alias] field to the {router} table. | |
system_update_last_removed | Implements hook_update_last_removed(). |
Constants
Title | Deprecated | Summary |
---|---|---|
DRUPAL_CORE_REMOVED_MODULE_LIST | An array of machine names of modules that were removed from Drupal core. | |
DRUPAL_CORE_REMOVED_THEME_LIST | An array of machine names of themes that were removed from Drupal core. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.