summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/system/system.install
blob: 5bbaa8a5436fe198c5d1373d9c41d8388f73a35c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?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);
  }
}