Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * Install, update and uninstall functions for the system module.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@0
|
8 use Drupal\Component\Utility\Crypt;
|
Chris@0
|
9 use Drupal\Component\Utility\Environment;
|
Chris@0
|
10 use Drupal\Component\FileSystem\FileSystem;
|
Chris@0
|
11 use Drupal\Component\Utility\OpCodeCache;
|
Chris@0
|
12 use Drupal\Component\Utility\Unicode;
|
Chris@0
|
13 use Drupal\Core\Cache\Cache;
|
Chris@0
|
14 use Drupal\Core\Path\AliasStorage;
|
Chris@0
|
15 use Drupal\Core\Url;
|
Chris@0
|
16 use Drupal\Core\Database\Database;
|
Chris@0
|
17 use Drupal\Core\Entity\ContentEntityTypeInterface;
|
Chris@0
|
18 use Drupal\Core\Entity\EntityTypeInterface;
|
Chris@0
|
19 use Drupal\Core\Entity\FieldableEntityInterface;
|
Chris@0
|
20 use Drupal\Core\DrupalKernel;
|
Chris@0
|
21 use Drupal\Core\Field\BaseFieldDefinition;
|
Chris@0
|
22 use Drupal\Core\Site\Settings;
|
Chris@0
|
23 use Drupal\Core\StreamWrapper\PrivateStream;
|
Chris@0
|
24 use Drupal\Core\StreamWrapper\PublicStream;
|
Chris@0
|
25 use Drupal\system\SystemRequirements;
|
Chris@0
|
26 use Symfony\Component\HttpFoundation\Request;
|
Chris@0
|
27
|
Chris@0
|
28 /**
|
Chris@0
|
29 * Implements hook_requirements().
|
Chris@0
|
30 */
|
Chris@0
|
31 function system_requirements($phase) {
|
Chris@0
|
32 global $install_state;
|
Chris@0
|
33 $requirements = [];
|
Chris@0
|
34
|
Chris@0
|
35 // Report Drupal version
|
Chris@0
|
36 if ($phase == 'runtime') {
|
Chris@0
|
37 $requirements['drupal'] = [
|
Chris@0
|
38 'title' => t('Drupal'),
|
Chris@0
|
39 'value' => \Drupal::VERSION,
|
Chris@0
|
40 'severity' => REQUIREMENT_INFO,
|
Chris@0
|
41 'weight' => -10,
|
Chris@0
|
42 ];
|
Chris@0
|
43
|
Chris@0
|
44 // Display the currently active installation profile, if the site
|
Chris@0
|
45 // is not running the default installation profile.
|
Chris@0
|
46 $profile = drupal_get_profile();
|
Chris@0
|
47 if ($profile != 'standard') {
|
Chris@0
|
48 $info = system_get_info('module', $profile);
|
Chris@0
|
49 $requirements['install_profile'] = [
|
Chris@0
|
50 'title' => t('Installation profile'),
|
Chris@0
|
51 'value' => t('%profile_name (%profile-%version)', [
|
Chris@0
|
52 '%profile_name' => $info['name'],
|
Chris@0
|
53 '%profile' => $profile,
|
Chris@0
|
54 '%version' => $info['version']
|
Chris@0
|
55 ]),
|
Chris@0
|
56 'severity' => REQUIREMENT_INFO,
|
Chris@0
|
57 'weight' => -9
|
Chris@0
|
58 ];
|
Chris@0
|
59 }
|
Chris@0
|
60
|
Chris@0
|
61 // Warn if any experimental modules are installed.
|
Chris@0
|
62 $experimental = [];
|
Chris@0
|
63 $enabled_modules = \Drupal::moduleHandler()->getModuleList();
|
Chris@0
|
64 foreach ($enabled_modules as $module => $data) {
|
Chris@0
|
65 $info = system_get_info('module', $module);
|
Chris@0
|
66 if (isset($info['package']) && $info['package'] === 'Core (Experimental)') {
|
Chris@0
|
67 $experimental[$module] = $info['name'];
|
Chris@0
|
68 }
|
Chris@0
|
69 }
|
Chris@0
|
70 if (!empty($experimental)) {
|
Chris@0
|
71 $requirements['experimental'] = [
|
Chris@0
|
72 'title' => t('Experimental modules enabled'),
|
Chris@0
|
73 'value' => t('Experimental modules found: %module_list. <a href=":url">Experimental modules</a> are provided for testing purposes only. Use at your own risk.', ['%module_list' => implode(', ', $experimental), ':url' => 'https://www.drupal.org/core/experimental']),
|
Chris@0
|
74 'severity' => REQUIREMENT_WARNING,
|
Chris@0
|
75 ];
|
Chris@0
|
76 }
|
Chris@0
|
77 }
|
Chris@0
|
78
|
Chris@0
|
79 // Web server information.
|
Chris@0
|
80 $software = \Drupal::request()->server->get('SERVER_SOFTWARE');
|
Chris@0
|
81 $requirements['webserver'] = [
|
Chris@0
|
82 'title' => t('Web server'),
|
Chris@0
|
83 'value' => $software,
|
Chris@0
|
84 ];
|
Chris@0
|
85
|
Chris@0
|
86 // Tests clean URL support.
|
Chris@0
|
87 if ($phase == 'install' && $install_state['interactive'] && !isset($_GET['rewrite']) && strpos($software, 'Apache') !== FALSE) {
|
Chris@0
|
88 // If the Apache rewrite module is not enabled, Apache version must be >=
|
Chris@0
|
89 // 2.2.16 because of the FallbackResource directive in the root .htaccess
|
Chris@0
|
90 // file. Since the Apache version reported by the server is dependent on the
|
Chris@0
|
91 // ServerTokens setting in httpd.conf, we may not be able to determine if a
|
Chris@0
|
92 // given config is valid. Thus we are unable to use version_compare() as we
|
Chris@0
|
93 // need have three possible outcomes: the version of Apache is greater than
|
Chris@0
|
94 // 2.2.16, is less than 2.2.16, or cannot be determined accurately. In the
|
Chris@0
|
95 // first case, we encourage the use of mod_rewrite; in the second case, we
|
Chris@0
|
96 // raise an error regarding the minimum Apache version; in the third case,
|
Chris@0
|
97 // we raise a warning that the current version of Apache may not be
|
Chris@0
|
98 // supported.
|
Chris@0
|
99 $rewrite_warning = FALSE;
|
Chris@0
|
100 $rewrite_error = FALSE;
|
Chris@0
|
101 $apache_version_string = 'Apache';
|
Chris@0
|
102
|
Chris@0
|
103 // Determine the Apache version number: major, minor and revision.
|
Chris@0
|
104 if (preg_match('/Apache\/(\d+)\.?(\d+)?\.?(\d+)?/', $software, $matches)) {
|
Chris@0
|
105 $apache_version_string = $matches[0];
|
Chris@0
|
106
|
Chris@0
|
107 // Major version number
|
Chris@0
|
108 if ($matches[1] < 2) {
|
Chris@0
|
109 $rewrite_error = TRUE;
|
Chris@0
|
110 }
|
Chris@0
|
111 elseif ($matches[1] == 2) {
|
Chris@0
|
112 if (!isset($matches[2])) {
|
Chris@0
|
113 $rewrite_warning = TRUE;
|
Chris@0
|
114 }
|
Chris@0
|
115 elseif ($matches[2] < 2) {
|
Chris@0
|
116 $rewrite_error = TRUE;
|
Chris@0
|
117 }
|
Chris@0
|
118 elseif ($matches[2] == 2) {
|
Chris@0
|
119 if (!isset($matches[3])) {
|
Chris@0
|
120 $rewrite_warning = TRUE;
|
Chris@0
|
121 }
|
Chris@0
|
122 elseif ($matches[3] < 16) {
|
Chris@0
|
123 $rewrite_error = TRUE;
|
Chris@0
|
124 }
|
Chris@0
|
125 }
|
Chris@0
|
126 }
|
Chris@0
|
127 }
|
Chris@0
|
128 else {
|
Chris@0
|
129 $rewrite_warning = TRUE;
|
Chris@0
|
130 }
|
Chris@0
|
131
|
Chris@0
|
132 if ($rewrite_warning) {
|
Chris@0
|
133 $requirements['apache_version'] = [
|
Chris@0
|
134 'title' => t('Apache version'),
|
Chris@0
|
135 'value' => $apache_version_string,
|
Chris@0
|
136 'severity' => REQUIREMENT_WARNING,
|
Chris@0
|
137 'description' => t('Due to the settings for ServerTokens in httpd.conf, it is impossible to accurately determine the version of Apache running on this server. The reported value is @reported, to run Drupal without mod_rewrite, a minimum version of 2.2.16 is needed.', ['@reported' => $apache_version_string]),
|
Chris@0
|
138 ];
|
Chris@0
|
139 }
|
Chris@0
|
140
|
Chris@0
|
141 if ($rewrite_error) {
|
Chris@0
|
142 $requirements['Apache version'] = [
|
Chris@0
|
143 'title' => t('Apache version'),
|
Chris@0
|
144 'value' => $apache_version_string,
|
Chris@0
|
145 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
146 'description' => t('The minimum version of Apache needed to run Drupal without mod_rewrite enabled is 2.2.16. See the <a href=":link">enabling clean URLs</a> page for more information on mod_rewrite.', [':link' => 'http://drupal.org/node/15365']),
|
Chris@0
|
147 ];
|
Chris@0
|
148 }
|
Chris@0
|
149
|
Chris@0
|
150 if (!$rewrite_error && !$rewrite_warning) {
|
Chris@0
|
151 $requirements['rewrite_module'] = [
|
Chris@0
|
152 'title' => t('Clean URLs'),
|
Chris@0
|
153 'value' => t('Disabled'),
|
Chris@0
|
154 'severity' => REQUIREMENT_WARNING,
|
Chris@0
|
155 'description' => t('Your server is capable of using clean URLs, but it is not enabled. Using clean URLs gives an improved user experience and is recommended. <a href=":link">Enable clean URLs</a>', [':link' => 'http://drupal.org/node/15365']),
|
Chris@0
|
156 ];
|
Chris@0
|
157 }
|
Chris@0
|
158 }
|
Chris@0
|
159
|
Chris@14
|
160 // Verify the user is running a supported PHP version.
|
Chris@14
|
161 // If the site is running a recommended version of PHP, just display it
|
Chris@14
|
162 // as an informational message on the status report. This will be overridden
|
Chris@14
|
163 // with an error or warning if the site is running older PHP versions for
|
Chris@14
|
164 // which Drupal has already or will soon drop support.
|
Chris@0
|
165 $phpversion = $phpversion_label = phpversion();
|
Chris@0
|
166 if (function_exists('phpinfo')) {
|
Chris@0
|
167 if ($phase === 'runtime') {
|
Chris@0
|
168 $phpversion_label = t('@phpversion (<a href=":url">more information</a>)', ['@phpversion' => $phpversion, ':url' => (new Url('system.php'))->toString()]);
|
Chris@0
|
169 }
|
Chris@0
|
170 $requirements['php'] = [
|
Chris@0
|
171 'title' => t('PHP'),
|
Chris@0
|
172 'value' => $phpversion_label,
|
Chris@0
|
173 ];
|
Chris@0
|
174 }
|
Chris@0
|
175 else {
|
Chris@14
|
176 // @todo Revisit whether this description makes sense in
|
Chris@14
|
177 // https://www.drupal.org/project/drupal/issues/2927318.
|
Chris@0
|
178 $requirements['php'] = [
|
Chris@0
|
179 'title' => t('PHP'),
|
Chris@0
|
180 'value' => $phpversion_label,
|
Chris@0
|
181 'description' => t('The phpinfo() function has been disabled for security reasons. To see your server\'s phpinfo() information, change your PHP settings or contact your server administrator. For more information, <a href=":phpinfo">Enabling and disabling phpinfo()</a> handbook page.', [':phpinfo' => 'https://www.drupal.org/node/243993']),
|
Chris@0
|
182 'severity' => REQUIREMENT_INFO,
|
Chris@0
|
183 ];
|
Chris@0
|
184 }
|
Chris@0
|
185
|
Chris@0
|
186 if (version_compare($phpversion, DRUPAL_MINIMUM_PHP) < 0) {
|
Chris@0
|
187 $requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version.', ['%version' => DRUPAL_MINIMUM_PHP]);
|
Chris@0
|
188 $requirements['php']['severity'] = REQUIREMENT_ERROR;
|
Chris@0
|
189 // If PHP is old, it's not safe to continue with the requirements check.
|
Chris@0
|
190 return $requirements;
|
Chris@0
|
191 }
|
Chris@14
|
192 if ((version_compare($phpversion, DRUPAL_RECOMMENDED_PHP) < 0) && ($phase === 'install' || $phase === 'runtime')) {
|
Chris@14
|
193 // Warn if still on PHP 5. If at least PHP 7.0, relax from "warning" to
|
Chris@14
|
194 // "info", and show it at runtime only, to not scare users while installing.
|
Chris@14
|
195 if (version_compare($phpversion, '7.0') < 0) {
|
Chris@14
|
196 $requirements['php']['description'] = t('Drupal will drop support for this version on March 6, 2019. Upgrade to PHP version %recommended or higher to ensure your site can receive updates and remain secure. See <a href="http://php.net/supported-versions.php">PHP\'s version support documentation</a> and the <a href=":php_requirements">Drupal 8 PHP requirements handbook page</a> for more information.', ['%recommended' => DRUPAL_RECOMMENDED_PHP, ':php_requirements' => 'https://www.drupal.org/docs/8/system-requirements/php']);
|
Chris@14
|
197 $requirements['php']['severity'] = REQUIREMENT_WARNING;
|
Chris@14
|
198 }
|
Chris@14
|
199 else {
|
Chris@14
|
200 if ($phase === 'runtime') {
|
Chris@14
|
201 $requirements['php']['description'] = t('It is recommended to upgrade to PHP version %recommended or higher for the best ongoing support. See <a href="http://php.net/supported-versions.php">PHP\'s version support documentation</a> and the <a href=":php_requirements">Drupal 8 PHP requirements handbook page</a> for more information.', ['%recommended' => DRUPAL_RECOMMENDED_PHP, ':php_requirements' => 'https://www.drupal.org/docs/8/system-requirements/php']);
|
Chris@14
|
202 $requirements['php']['severity'] = REQUIREMENT_INFO;
|
Chris@14
|
203 }
|
Chris@14
|
204 }
|
Chris@14
|
205 }
|
Chris@0
|
206
|
Chris@0
|
207 // Suggest to update to at least 5.5.21 or 5.6.5 for disabling multiple
|
Chris@0
|
208 // statements.
|
Chris@0
|
209 if (($phase === 'install' || \Drupal::database()->driver() === 'mysql') && !SystemRequirements::phpVersionWithPdoDisallowMultipleStatements($phpversion)) {
|
Chris@14
|
210 $requirements['php_multiple_statement'] = [
|
Chris@0
|
211 'title' => t('PHP (multiple statement disabling)'),
|
Chris@0
|
212 'value' => $phpversion_label,
|
Chris@0
|
213 'description' => t('PHP versions higher than 5.6.5 or 5.5.21 provide built-in SQL injection protection for mysql databases. It is recommended to update.'),
|
Chris@0
|
214 'severity' => REQUIREMENT_INFO,
|
Chris@0
|
215 ];
|
Chris@0
|
216 }
|
Chris@0
|
217
|
Chris@0
|
218 // Test for PHP extensions.
|
Chris@0
|
219 $requirements['php_extensions'] = [
|
Chris@0
|
220 'title' => t('PHP extensions'),
|
Chris@0
|
221 ];
|
Chris@0
|
222
|
Chris@0
|
223 $missing_extensions = [];
|
Chris@0
|
224 $required_extensions = [
|
Chris@0
|
225 'date',
|
Chris@0
|
226 'dom',
|
Chris@0
|
227 'filter',
|
Chris@0
|
228 'gd',
|
Chris@0
|
229 'hash',
|
Chris@0
|
230 'json',
|
Chris@0
|
231 'pcre',
|
Chris@0
|
232 'pdo',
|
Chris@0
|
233 'session',
|
Chris@0
|
234 'SimpleXML',
|
Chris@0
|
235 'SPL',
|
Chris@0
|
236 'tokenizer',
|
Chris@0
|
237 'xml',
|
Chris@0
|
238 ];
|
Chris@0
|
239 foreach ($required_extensions as $extension) {
|
Chris@0
|
240 if (!extension_loaded($extension)) {
|
Chris@0
|
241 $missing_extensions[] = $extension;
|
Chris@0
|
242 }
|
Chris@0
|
243 }
|
Chris@0
|
244
|
Chris@0
|
245 if (!empty($missing_extensions)) {
|
Chris@0
|
246 $description = t('Drupal requires you to enable the PHP extensions in the following list (see the <a href=":system_requirements">system requirements page</a> for more information):', [
|
Chris@0
|
247 ':system_requirements' => 'https://www.drupal.org/requirements',
|
Chris@0
|
248 ]);
|
Chris@0
|
249
|
Chris@0
|
250 // We use twig inline_template to avoid twig's autoescape.
|
Chris@0
|
251 $description = [
|
Chris@0
|
252 '#type' => 'inline_template',
|
Chris@0
|
253 '#template' => '{{ description }}{{ missing_extensions }}',
|
Chris@0
|
254 '#context' => [
|
Chris@0
|
255 'description' => $description,
|
Chris@0
|
256 'missing_extensions' => [
|
Chris@0
|
257 '#theme' => 'item_list',
|
Chris@0
|
258 '#items' => $missing_extensions,
|
Chris@0
|
259 ],
|
Chris@0
|
260 ],
|
Chris@0
|
261 ];
|
Chris@0
|
262
|
Chris@0
|
263 $requirements['php_extensions']['value'] = t('Disabled');
|
Chris@0
|
264 $requirements['php_extensions']['severity'] = REQUIREMENT_ERROR;
|
Chris@0
|
265 $requirements['php_extensions']['description'] = $description;
|
Chris@0
|
266 }
|
Chris@0
|
267 else {
|
Chris@0
|
268 $requirements['php_extensions']['value'] = t('Enabled');
|
Chris@0
|
269 }
|
Chris@0
|
270
|
Chris@0
|
271 if ($phase == 'install' || $phase == 'runtime') {
|
Chris@0
|
272 // Check to see if OPcache is installed.
|
Chris@0
|
273 if (!OpCodeCache::isEnabled()) {
|
Chris@0
|
274 $requirements['php_opcache'] = [
|
Chris@0
|
275 'value' => t('Not enabled'),
|
Chris@0
|
276 'severity' => REQUIREMENT_WARNING,
|
Chris@0
|
277 'description' => t('PHP OPcode caching can improve your site\'s performance considerably. It is <strong>highly recommended</strong> to have <a href="http://php.net/manual/opcache.installation.php" target="_blank">OPcache</a> installed on your server.'),
|
Chris@0
|
278 ];
|
Chris@0
|
279 }
|
Chris@0
|
280 else {
|
Chris@0
|
281 $requirements['php_opcache']['value'] = t('Enabled');
|
Chris@0
|
282 }
|
Chris@0
|
283 $requirements['php_opcache']['title'] = t('PHP OPcode caching');
|
Chris@0
|
284 }
|
Chris@0
|
285
|
Chris@0
|
286 if ($phase != 'update') {
|
Chris@0
|
287 // Test whether we have a good source of random bytes.
|
Chris@0
|
288 $requirements['php_random_bytes'] = [
|
Chris@0
|
289 'title' => t('Random number generation'),
|
Chris@0
|
290 ];
|
Chris@0
|
291 try {
|
Chris@0
|
292 $bytes = random_bytes(10);
|
Chris@0
|
293 if (strlen($bytes) != 10) {
|
Chris@0
|
294 throw new \Exception(t('Tried to generate 10 random bytes, generated @count', ['@count' => strlen($bytes)]));
|
Chris@0
|
295 }
|
Chris@0
|
296 $requirements['php_random_bytes']['value'] = t('Successful');
|
Chris@0
|
297 }
|
Chris@0
|
298 catch (\Exception $e) {
|
Chris@0
|
299 // If /dev/urandom is not available on a UNIX-like system, check whether
|
Chris@0
|
300 // open_basedir restrictions are the cause.
|
Chris@0
|
301 $open_basedir_blocks_urandom = FALSE;
|
Chris@0
|
302 if (DIRECTORY_SEPARATOR === '/' && !@is_readable('/dev/urandom')) {
|
Chris@0
|
303 $open_basedir = ini_get('open_basedir');
|
Chris@0
|
304 if ($open_basedir) {
|
Chris@0
|
305 $open_basedir_paths = explode(PATH_SEPARATOR, $open_basedir);
|
Chris@0
|
306 $open_basedir_blocks_urandom = !array_intersect(['/dev', '/dev/', '/dev/urandom'], $open_basedir_paths);
|
Chris@0
|
307 }
|
Chris@0
|
308 }
|
Chris@0
|
309 $args = [
|
Chris@0
|
310 ':drupal-php' => 'https://www.drupal.org/docs/7/system-requirements/php#csprng',
|
Chris@0
|
311 '%exception_message' => $e->getMessage(),
|
Chris@0
|
312 ];
|
Chris@0
|
313 if ($open_basedir_blocks_urandom) {
|
Chris@0
|
314 $requirements['php_random_bytes']['description'] = t('Drupal is unable to generate highly randomized numbers, which means certain security features like password reset URLs are not as secure as they should be. Instead, only a slow, less-secure fallback generator is available. The most likely cause is that open_basedir restrictions are in effect and /dev/urandom is not on the whitelist. See the <a href=":drupal-php">system requirements</a> page for more information. %exception_message', $args);
|
Chris@0
|
315 }
|
Chris@0
|
316 else {
|
Chris@0
|
317 $requirements['php_random_bytes']['description'] = t('Drupal is unable to generate highly randomized numbers, which means certain security features like password reset URLs are not as secure as they should be. Instead, only a slow, less-secure fallback generator is available. See the <a href=":drupal-php">system requirements</a> page for more information. %exception_message', $args);
|
Chris@0
|
318 }
|
Chris@0
|
319 $requirements['php_random_bytes']['value'] = t('Less secure');
|
Chris@0
|
320 $requirements['php_random_bytes']['severity'] = REQUIREMENT_ERROR;
|
Chris@0
|
321 }
|
Chris@0
|
322 }
|
Chris@0
|
323
|
Chris@0
|
324 if ($phase == 'install' || $phase == 'update') {
|
Chris@0
|
325 // Test for PDO (database).
|
Chris@0
|
326 $requirements['database_extensions'] = [
|
Chris@0
|
327 'title' => t('Database support'),
|
Chris@0
|
328 ];
|
Chris@0
|
329
|
Chris@0
|
330 // Make sure PDO is available.
|
Chris@0
|
331 $database_ok = extension_loaded('pdo');
|
Chris@0
|
332 if (!$database_ok) {
|
Chris@0
|
333 $pdo_message = t('Your web server does not appear to support PDO (PHP Data Objects). Ask your hosting provider if they support the native PDO extension. See the <a href=":link">system requirements</a> page for more information.', [
|
Chris@0
|
334 ':link' => 'https://www.drupal.org/requirements/pdo',
|
Chris@0
|
335 ]);
|
Chris@0
|
336 }
|
Chris@0
|
337 else {
|
Chris@0
|
338 // Make sure at least one supported database driver exists.
|
Chris@0
|
339 $drivers = drupal_detect_database_types();
|
Chris@0
|
340 if (empty($drivers)) {
|
Chris@0
|
341 $database_ok = FALSE;
|
Chris@0
|
342 $pdo_message = t('Your web server does not appear to support any common PDO database extensions. Check with your hosting provider to see if they support PDO (PHP Data Objects) and offer any databases that <a href=":drupal-databases">Drupal supports</a>.', [
|
Chris@0
|
343 ':drupal-databases' => 'https://www.drupal.org/requirements/database',
|
Chris@0
|
344 ]);
|
Chris@0
|
345 }
|
Chris@0
|
346 // Make sure the native PDO extension is available, not the older PEAR
|
Chris@0
|
347 // version. (See install_verify_pdo() for details.)
|
Chris@0
|
348 if (!defined('PDO::ATTR_DEFAULT_FETCH_MODE')) {
|
Chris@0
|
349 $database_ok = FALSE;
|
Chris@0
|
350 $pdo_message = t('Your web server seems to have the wrong version of PDO installed. Drupal requires the PDO extension from PHP core. This system has the older PECL version. See the <a href=":link">system requirements</a> page for more information.', [
|
Chris@0
|
351 ':link' => 'https://www.drupal.org/requirements/pdo#pecl',
|
Chris@0
|
352 ]);
|
Chris@0
|
353 }
|
Chris@0
|
354 }
|
Chris@0
|
355
|
Chris@0
|
356 if (!$database_ok) {
|
Chris@0
|
357 $requirements['database_extensions']['value'] = t('Disabled');
|
Chris@0
|
358 $requirements['database_extensions']['severity'] = REQUIREMENT_ERROR;
|
Chris@0
|
359 $requirements['database_extensions']['description'] = $pdo_message;
|
Chris@0
|
360 }
|
Chris@0
|
361 else {
|
Chris@0
|
362 $requirements['database_extensions']['value'] = t('Enabled');
|
Chris@0
|
363 }
|
Chris@0
|
364 }
|
Chris@0
|
365 else {
|
Chris@0
|
366 // Database information.
|
Chris@0
|
367 $class = Database::getConnection()->getDriverClass('Install\\Tasks');
|
Chris@0
|
368 $tasks = new $class();
|
Chris@0
|
369 $requirements['database_system'] = [
|
Chris@0
|
370 'title' => t('Database system'),
|
Chris@0
|
371 'value' => $tasks->name(),
|
Chris@0
|
372 ];
|
Chris@0
|
373 $requirements['database_system_version'] = [
|
Chris@0
|
374 'title' => t('Database system version'),
|
Chris@0
|
375 'value' => Database::getConnection()->version(),
|
Chris@0
|
376 ];
|
Chris@0
|
377 }
|
Chris@0
|
378
|
Chris@0
|
379 // Test PHP memory_limit
|
Chris@0
|
380 $memory_limit = ini_get('memory_limit');
|
Chris@0
|
381 $requirements['php_memory_limit'] = [
|
Chris@0
|
382 'title' => t('PHP memory limit'),
|
Chris@0
|
383 'value' => $memory_limit == -1 ? t('-1 (Unlimited)') : $memory_limit,
|
Chris@0
|
384 ];
|
Chris@0
|
385
|
Chris@0
|
386 if (!Environment::checkMemoryLimit(DRUPAL_MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) {
|
Chris@0
|
387 $description = [];
|
Chris@0
|
388 if ($phase == 'install') {
|
Chris@0
|
389 $description['phase'] = t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the installation process.', ['%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT]);
|
Chris@0
|
390 }
|
Chris@0
|
391 elseif ($phase == 'update') {
|
Chris@0
|
392 $description['phase'] = t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the update process.', ['%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT]);
|
Chris@0
|
393 }
|
Chris@0
|
394 elseif ($phase == 'runtime') {
|
Chris@0
|
395 $description['phase'] = t('Depending on your configuration, Drupal can run with a %memory_limit PHP memory limit. However, a %memory_minimum_limit PHP memory limit or above is recommended, especially if your site uses additional custom or contributed modules.', ['%memory_limit' => $memory_limit, '%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT]);
|
Chris@0
|
396 }
|
Chris@0
|
397
|
Chris@0
|
398 if (!empty($description['phase'])) {
|
Chris@0
|
399 if ($php_ini_path = get_cfg_var('cfg_file_path')) {
|
Chris@0
|
400 $description['memory'] = t('Increase the memory limit by editing the memory_limit parameter in the file %configuration-file and then restart your web server (or contact your system administrator or hosting provider for assistance).', ['%configuration-file' => $php_ini_path]);
|
Chris@0
|
401 }
|
Chris@0
|
402 else {
|
Chris@0
|
403 $description['memory'] = t('Contact your system administrator or hosting provider for assistance with increasing your PHP memory limit.');
|
Chris@0
|
404 }
|
Chris@0
|
405
|
Chris@0
|
406 $handbook_link = t('For more information, see the online handbook entry for <a href=":memory-limit">increasing the PHP memory limit</a>.', [':memory-limit' => 'https://www.drupal.org/node/207036']);
|
Chris@0
|
407
|
Chris@0
|
408 $description = [
|
Chris@0
|
409 '#type' => 'inline_template',
|
Chris@0
|
410 '#template' => '{{ description_phase }} {{ description_memory }} {{ handbook }}',
|
Chris@0
|
411 '#context' => [
|
Chris@0
|
412 'description_phase' => $description['phase'],
|
Chris@0
|
413 'description_memory' => $description['memory'],
|
Chris@0
|
414 'handbook' => $handbook_link,
|
Chris@0
|
415 ],
|
Chris@0
|
416 ];
|
Chris@0
|
417
|
Chris@0
|
418 $requirements['php_memory_limit']['description'] = $description;
|
Chris@0
|
419 $requirements['php_memory_limit']['severity'] = REQUIREMENT_WARNING;
|
Chris@0
|
420 }
|
Chris@0
|
421 }
|
Chris@0
|
422
|
Chris@0
|
423 // Test configuration files and directory for writability.
|
Chris@0
|
424 if ($phase == 'runtime') {
|
Chris@0
|
425 $conf_errors = [];
|
Chris@0
|
426 // Find the site path. Kernel service is not always available at this point,
|
Chris@0
|
427 // but is preferred, when available.
|
Chris@0
|
428 if (\Drupal::hasService('kernel')) {
|
Chris@0
|
429 $site_path = \Drupal::service('site.path');
|
Chris@0
|
430 }
|
Chris@0
|
431 else {
|
Chris@0
|
432 $site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
|
Chris@0
|
433 }
|
Chris@0
|
434 // Allow system administrators to disable permissions hardening for the site
|
Chris@0
|
435 // directory. This allows additional files in the site directory to be
|
Chris@0
|
436 // updated when they are managed in a version control system.
|
Chris@0
|
437 if (Settings::get('skip_permissions_hardening')) {
|
Chris@0
|
438 $conf_errors[] = t('Protection disabled');
|
Chris@0
|
439 // If permissions hardening is disabled, then only show a warning for a
|
Chris@0
|
440 // writable file, as a reminder, rather than an error.
|
Chris@0
|
441 $file_protection_severity = REQUIREMENT_WARNING;
|
Chris@0
|
442 }
|
Chris@0
|
443 else {
|
Chris@0
|
444 // In normal operation, writable files or directories are an error.
|
Chris@0
|
445 $file_protection_severity = REQUIREMENT_ERROR;
|
Chris@0
|
446 if (!drupal_verify_install_file($site_path, FILE_NOT_WRITABLE, 'dir')) {
|
Chris@0
|
447 $conf_errors[] = t("The directory %file is not protected from modifications and poses a security risk. You must change the directory's permissions to be non-writable.", ['%file' => $site_path]);
|
Chris@0
|
448 }
|
Chris@0
|
449 }
|
Chris@0
|
450 foreach (['settings.php', 'settings.local.php', 'services.yml'] as $conf_file) {
|
Chris@0
|
451 $full_path = $site_path . '/' . $conf_file;
|
Chris@0
|
452 if (file_exists($full_path) && (Settings::get('skip_permissions_hardening') || !drupal_verify_install_file($full_path, FILE_EXIST | FILE_READABLE | FILE_NOT_WRITABLE))) {
|
Chris@0
|
453 $conf_errors[] = t("The file %file is not protected from modifications and poses a security risk. You must change the file's permissions to be non-writable.", ['%file' => $full_path]);
|
Chris@0
|
454 }
|
Chris@0
|
455 }
|
Chris@0
|
456 if (!empty($conf_errors)) {
|
Chris@0
|
457 if (count($conf_errors) == 1) {
|
Chris@0
|
458 $description = $conf_errors[0];
|
Chris@0
|
459 }
|
Chris@0
|
460 else {
|
Chris@0
|
461 // We use twig inline_template to avoid double escaping.
|
Chris@0
|
462 $description = [
|
Chris@0
|
463 '#type' => 'inline_template',
|
Chris@0
|
464 '#template' => '{{ configuration_error_list }}',
|
Chris@0
|
465 '#context' => [
|
Chris@0
|
466 'configuration_error_list' => [
|
Chris@0
|
467 '#theme' => 'item_list',
|
Chris@0
|
468 '#items' => $conf_errors,
|
Chris@0
|
469 ],
|
Chris@0
|
470 ],
|
Chris@0
|
471 ];
|
Chris@0
|
472 }
|
Chris@0
|
473 $requirements['configuration_files'] = [
|
Chris@0
|
474 'value' => t('Not protected'),
|
Chris@0
|
475 'severity' => $file_protection_severity,
|
Chris@0
|
476 'description' => $description,
|
Chris@0
|
477 ];
|
Chris@0
|
478 }
|
Chris@0
|
479 else {
|
Chris@0
|
480 $requirements['configuration_files'] = [
|
Chris@0
|
481 'value' => t('Protected'),
|
Chris@0
|
482 ];
|
Chris@0
|
483 }
|
Chris@0
|
484 $requirements['configuration_files']['title'] = t('Configuration files');
|
Chris@0
|
485 }
|
Chris@0
|
486
|
Chris@0
|
487 // Test the contents of the .htaccess files.
|
Chris@0
|
488 if ($phase == 'runtime') {
|
Chris@0
|
489 // Try to write the .htaccess files first, to prevent false alarms in case
|
Chris@0
|
490 // (for example) the /tmp directory was wiped.
|
Chris@0
|
491 file_ensure_htaccess();
|
Chris@14
|
492 $file_system = \Drupal::service('file_system');
|
Chris@0
|
493 $htaccess_files['public://.htaccess'] = [
|
Chris@0
|
494 'title' => t('Public files directory'),
|
Chris@14
|
495 'directory' => $file_system->realpath('public://'),
|
Chris@0
|
496 ];
|
Chris@0
|
497 if (PrivateStream::basePath()) {
|
Chris@0
|
498 $htaccess_files['private://.htaccess'] = [
|
Chris@0
|
499 'title' => t('Private files directory'),
|
Chris@14
|
500 'directory' => $file_system->realpath('private://'),
|
Chris@0
|
501 ];
|
Chris@0
|
502 }
|
Chris@0
|
503 $htaccess_files['temporary://.htaccess'] = [
|
Chris@0
|
504 'title' => t('Temporary files directory'),
|
Chris@14
|
505 'directory' => $file_system->realpath('temporary://'),
|
Chris@0
|
506 ];
|
Chris@0
|
507 foreach ($htaccess_files as $htaccess_file => $info) {
|
Chris@0
|
508 // Check for the string which was added to the recommended .htaccess file
|
Chris@0
|
509 // in the latest security update.
|
Chris@0
|
510 if (!file_exists($htaccess_file) || !($contents = @file_get_contents($htaccess_file)) || strpos($contents, 'Drupal_Security_Do_Not_Remove_See_SA_2013_003') === FALSE) {
|
Chris@0
|
511 $url = 'https://www.drupal.org/SA-CORE-2013-003';
|
Chris@0
|
512 $requirements[$htaccess_file] = [
|
Chris@0
|
513 'title' => $info['title'],
|
Chris@0
|
514 'value' => t('Not fully protected'),
|
Chris@0
|
515 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
516 'description' => t('See <a href=":url">@url</a> for information about the recommended .htaccess file which should be added to the %directory directory to help protect against arbitrary code execution.', [':url' => $url, '@url' => $url, '%directory' => $info['directory']]),
|
Chris@0
|
517 ];
|
Chris@0
|
518 }
|
Chris@0
|
519 }
|
Chris@0
|
520 }
|
Chris@0
|
521
|
Chris@0
|
522 // Report cron status.
|
Chris@0
|
523 if ($phase == 'runtime') {
|
Chris@0
|
524 $cron_config = \Drupal::config('system.cron');
|
Chris@0
|
525 // Cron warning threshold defaults to two days.
|
Chris@0
|
526 $threshold_warning = $cron_config->get('threshold.requirements_warning');
|
Chris@0
|
527 // Cron error threshold defaults to two weeks.
|
Chris@0
|
528 $threshold_error = $cron_config->get('threshold.requirements_error');
|
Chris@0
|
529
|
Chris@0
|
530 // Determine when cron last ran.
|
Chris@0
|
531 $cron_last = \Drupal::state()->get('system.cron_last');
|
Chris@0
|
532 if (!is_numeric($cron_last)) {
|
Chris@0
|
533 $cron_last = \Drupal::state()->get('install_time', 0);
|
Chris@0
|
534 }
|
Chris@0
|
535
|
Chris@0
|
536 // Determine severity based on time since cron last ran.
|
Chris@0
|
537 $severity = REQUIREMENT_INFO;
|
Chris@0
|
538 if (REQUEST_TIME - $cron_last > $threshold_error) {
|
Chris@0
|
539 $severity = REQUIREMENT_ERROR;
|
Chris@0
|
540 }
|
Chris@0
|
541 elseif (REQUEST_TIME - $cron_last > $threshold_warning) {
|
Chris@0
|
542 $severity = REQUIREMENT_WARNING;
|
Chris@0
|
543 }
|
Chris@0
|
544
|
Chris@0
|
545 // Set summary and description based on values determined above.
|
Chris@0
|
546 $summary = t('Last run @time ago', ['@time' => \Drupal::service('date.formatter')->formatTimeDiffSince($cron_last)]);
|
Chris@0
|
547
|
Chris@0
|
548 $requirements['cron'] = [
|
Chris@0
|
549 'title' => t('Cron maintenance tasks'),
|
Chris@0
|
550 'severity' => $severity,
|
Chris@0
|
551 'value' => $summary,
|
Chris@0
|
552 ];
|
Chris@0
|
553 if ($severity != REQUIREMENT_INFO) {
|
Chris@0
|
554 $requirements['cron']['description'][] = [
|
Chris@0
|
555 [
|
Chris@0
|
556 '#markup' => t('Cron has not run recently.'),
|
Chris@0
|
557 '#suffix' => ' ',
|
Chris@0
|
558 ],
|
Chris@0
|
559 [
|
Chris@0
|
560 '#markup' => t('For more information, see the online handbook entry for <a href=":cron-handbook">configuring cron jobs</a>.', [':cron-handbook' => 'https://www.drupal.org/cron']),
|
Chris@0
|
561 '#suffix' => ' ',
|
Chris@0
|
562 ],
|
Chris@0
|
563 ];
|
Chris@0
|
564 }
|
Chris@0
|
565 $requirements['cron']['description'][] = [
|
Chris@0
|
566 [
|
Chris@0
|
567 '#type' => 'link',
|
Chris@0
|
568 '#prefix' => '(',
|
Chris@0
|
569 '#title' => t('more information'),
|
Chris@0
|
570 '#suffix' => ')',
|
Chris@0
|
571 '#url' => Url::fromRoute('system.cron_settings'),
|
Chris@0
|
572 ],
|
Chris@0
|
573 [
|
Chris@0
|
574 '#prefix' => '<span class="cron-description__run-cron">',
|
Chris@0
|
575 '#suffix' => '</span>',
|
Chris@0
|
576 '#type' => 'link',
|
Chris@0
|
577 '#title' => t('Run cron'),
|
Chris@0
|
578 '#url' => Url::fromRoute('system.run_cron'),
|
Chris@0
|
579 ],
|
Chris@0
|
580 ];
|
Chris@0
|
581 }
|
Chris@0
|
582 if ($phase != 'install') {
|
Chris@0
|
583 $filesystem_config = \Drupal::config('system.file');
|
Chris@0
|
584 $directories = [
|
Chris@0
|
585 PublicStream::basePath(),
|
Chris@0
|
586 // By default no private files directory is configured. For private files
|
Chris@0
|
587 // to be secure the admin needs to provide a path outside the webroot.
|
Chris@0
|
588 PrivateStream::basePath(),
|
Chris@0
|
589 file_directory_temp(),
|
Chris@0
|
590 ];
|
Chris@0
|
591 }
|
Chris@0
|
592
|
Chris@0
|
593 // During an install we need to make assumptions about the file system
|
Chris@0
|
594 // unless overrides are provided in settings.php.
|
Chris@0
|
595 if ($phase == 'install') {
|
Chris@0
|
596 $directories = [];
|
Chris@0
|
597 if ($file_public_path = Settings::get('file_public_path')) {
|
Chris@0
|
598 $directories[] = $file_public_path;
|
Chris@0
|
599 }
|
Chris@0
|
600 else {
|
Chris@0
|
601 // If we are installing Drupal, the settings.php file might not exist yet
|
Chris@0
|
602 // in the intended site directory, so don't require it.
|
Chris@0
|
603 $request = Request::createFromGlobals();
|
Chris@0
|
604 $site_path = DrupalKernel::findSitePath($request);
|
Chris@0
|
605 $directories[] = $site_path . '/files';
|
Chris@0
|
606 }
|
Chris@0
|
607 if ($file_private_path = Settings::get('file_private_path')) {
|
Chris@0
|
608 $directories[] = $file_private_path;
|
Chris@0
|
609 }
|
Chris@0
|
610 if (!empty($GLOBALS['config']['system.file']['path']['temporary'])) {
|
Chris@0
|
611 $directories[] = $GLOBALS['config']['system.file']['path']['temporary'];
|
Chris@0
|
612 }
|
Chris@0
|
613 else {
|
Chris@0
|
614 // If the temporary directory is not overridden use an appropriate
|
Chris@0
|
615 // temporary path for the system.
|
Chris@0
|
616 $directories[] = FileSystem::getOsTemporaryDirectory();
|
Chris@0
|
617 }
|
Chris@0
|
618 }
|
Chris@0
|
619
|
Chris@0
|
620 // Check the config directory if it is defined in settings.php. If it isn't
|
Chris@0
|
621 // defined, the installer will create a valid config directory later, but
|
Chris@0
|
622 // during runtime we must always display an error.
|
Chris@0
|
623 if (!empty($GLOBALS['config_directories'])) {
|
Chris@0
|
624 foreach (array_keys(array_filter($GLOBALS['config_directories'])) as $type) {
|
Chris@0
|
625 $directory = config_get_config_directory($type);
|
Chris@0
|
626 // If we're installing Drupal try and create the config sync directory.
|
Chris@0
|
627 if (!is_dir($directory) && $phase == 'install') {
|
Chris@0
|
628 file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
|
Chris@0
|
629 }
|
Chris@0
|
630 if (!is_dir($directory)) {
|
Chris@0
|
631 if ($phase == 'install') {
|
Chris@0
|
632 $description = t('An automated attempt to create the directory %directory failed, possibly due to a permissions problem. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see INSTALL.txt or the <a href=":handbook_url">online handbook</a>.', ['%directory' => $directory, ':handbook_url' => 'https://www.drupal.org/server-permissions']);
|
Chris@0
|
633 }
|
Chris@0
|
634 else {
|
Chris@0
|
635 $description = t('The directory %directory does not exist.', ['%directory' => $directory]);
|
Chris@0
|
636 }
|
Chris@0
|
637 $requirements['config directory ' . $type] = [
|
Chris@0
|
638 'title' => t('Configuration directory: %type', ['%type' => $type]),
|
Chris@0
|
639 'description' => $description,
|
Chris@0
|
640 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
641 ];
|
Chris@0
|
642 }
|
Chris@0
|
643 }
|
Chris@0
|
644 }
|
Chris@0
|
645 if ($phase != 'install' && (empty($GLOBALS['config_directories']) || empty($GLOBALS['config_directories'][CONFIG_SYNC_DIRECTORY]))) {
|
Chris@0
|
646 $requirements['config directories'] = [
|
Chris@0
|
647 'title' => t('Configuration directories'),
|
Chris@0
|
648 'value' => t('Not present'),
|
Chris@0
|
649 'description' => t('Your %file file must define the $config_directories variable as an array containing the names of directories in which configuration files can be found. It must contain a %sync_key key.', ['%file' => $site_path . '/settings.php', '%sync_key' => CONFIG_SYNC_DIRECTORY]),
|
Chris@0
|
650 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
651 ];
|
Chris@0
|
652 }
|
Chris@0
|
653
|
Chris@0
|
654 $requirements['file system'] = [
|
Chris@0
|
655 'title' => t('File system'),
|
Chris@0
|
656 ];
|
Chris@0
|
657
|
Chris@0
|
658 $error = '';
|
Chris@0
|
659 // For installer, create the directories if possible.
|
Chris@0
|
660 foreach ($directories as $directory) {
|
Chris@0
|
661 if (!$directory) {
|
Chris@0
|
662 continue;
|
Chris@0
|
663 }
|
Chris@0
|
664 if ($phase == 'install') {
|
Chris@0
|
665 file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
|
Chris@0
|
666 }
|
Chris@0
|
667 $is_writable = is_writable($directory);
|
Chris@0
|
668 $is_directory = is_dir($directory);
|
Chris@0
|
669 if (!$is_writable || !$is_directory) {
|
Chris@0
|
670 $description = '';
|
Chris@0
|
671 $requirements['file system']['value'] = t('Not writable');
|
Chris@0
|
672 if (!$is_directory) {
|
Chris@0
|
673 $error = t('The directory %directory does not exist.', ['%directory' => $directory]);
|
Chris@0
|
674 }
|
Chris@0
|
675 else {
|
Chris@0
|
676 $error = t('The directory %directory is not writable.', ['%directory' => $directory]);
|
Chris@0
|
677 }
|
Chris@0
|
678 // The files directory requirement check is done only during install and runtime.
|
Chris@0
|
679 if ($phase == 'runtime') {
|
Chris@0
|
680 $description = t('You may need to set the correct directory at the <a href=":admin-file-system">file system settings page</a> or change the current directory\'s permissions so that it is writable.', [':admin-file-system' => \Drupal::url('system.file_system_settings')]);
|
Chris@0
|
681 }
|
Chris@0
|
682 elseif ($phase == 'install') {
|
Chris@0
|
683 // For the installer UI, we need different wording. 'value' will
|
Chris@0
|
684 // be treated as version, so provide none there.
|
Chris@0
|
685 $description = t('An automated attempt to create this directory failed, possibly due to a permissions problem. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see INSTALL.txt or the <a href=":handbook_url">online handbook</a>.', [':handbook_url' => 'https://www.drupal.org/server-permissions']);
|
Chris@0
|
686 $requirements['file system']['value'] = '';
|
Chris@0
|
687 }
|
Chris@0
|
688 if (!empty($description)) {
|
Chris@0
|
689 $description = [
|
Chris@0
|
690 '#type' => 'inline_template',
|
Chris@0
|
691 '#template' => '{{ error }} {{ description }}',
|
Chris@0
|
692 '#context' => [
|
Chris@0
|
693 'error' => $error,
|
Chris@0
|
694 'description' => $description,
|
Chris@0
|
695 ],
|
Chris@0
|
696 ];
|
Chris@0
|
697 $requirements['file system']['description'] = $description;
|
Chris@0
|
698 $requirements['file system']['severity'] = REQUIREMENT_ERROR;
|
Chris@0
|
699 }
|
Chris@0
|
700 }
|
Chris@0
|
701 else {
|
Chris@0
|
702 // This function can be called before the config_cache table has been
|
Chris@0
|
703 // created.
|
Chris@0
|
704 if ($phase == 'install' || file_default_scheme() == 'public') {
|
Chris@0
|
705 $requirements['file system']['value'] = t('Writable (<em>public</em> download method)');
|
Chris@0
|
706 }
|
Chris@0
|
707 else {
|
Chris@0
|
708 $requirements['file system']['value'] = t('Writable (<em>private</em> download method)');
|
Chris@0
|
709 }
|
Chris@0
|
710 }
|
Chris@0
|
711 }
|
Chris@0
|
712
|
Chris@0
|
713 // See if updates are available in update.php.
|
Chris@0
|
714 if ($phase == 'runtime') {
|
Chris@0
|
715 $requirements['update'] = [
|
Chris@0
|
716 'title' => t('Database updates'),
|
Chris@0
|
717 'value' => t('Up to date'),
|
Chris@0
|
718 ];
|
Chris@0
|
719
|
Chris@0
|
720 // Check installed modules.
|
Chris@0
|
721 $has_pending_updates = FALSE;
|
Chris@0
|
722 foreach (\Drupal::moduleHandler()->getModuleList() as $module => $filename) {
|
Chris@0
|
723 $updates = drupal_get_schema_versions($module);
|
Chris@0
|
724 if ($updates !== FALSE) {
|
Chris@0
|
725 $default = drupal_get_installed_schema_version($module);
|
Chris@0
|
726 if (max($updates) > $default) {
|
Chris@0
|
727 $has_pending_updates = TRUE;
|
Chris@0
|
728 break;
|
Chris@0
|
729 }
|
Chris@0
|
730 }
|
Chris@0
|
731 }
|
Chris@0
|
732 if (!$has_pending_updates) {
|
Chris@0
|
733 /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */
|
Chris@0
|
734 $post_update_registry = \Drupal::service('update.post_update_registry');
|
Chris@0
|
735 $missing_post_update_functions = $post_update_registry->getPendingUpdateFunctions();
|
Chris@0
|
736 if (!empty($missing_post_update_functions)) {
|
Chris@0
|
737 $has_pending_updates = TRUE;
|
Chris@0
|
738 }
|
Chris@0
|
739 }
|
Chris@0
|
740
|
Chris@0
|
741 if ($has_pending_updates) {
|
Chris@0
|
742 $requirements['update']['severity'] = REQUIREMENT_ERROR;
|
Chris@0
|
743 $requirements['update']['value'] = t('Out of date');
|
Chris@0
|
744 $requirements['update']['description'] = t('Some modules have database schema updates to install. You should run the <a href=":update">database update script</a> immediately.', [':update' => \Drupal::url('system.db_update')]);
|
Chris@0
|
745 }
|
Chris@0
|
746
|
Chris@0
|
747 $requirements['entity_update'] = [
|
Chris@0
|
748 'title' => t('Entity/field definitions'),
|
Chris@0
|
749 'value' => t('Up to date'),
|
Chris@0
|
750 ];
|
Chris@0
|
751 // Verify that no entity updates are pending.
|
Chris@0
|
752 if ($change_list = \Drupal::entityDefinitionUpdateManager()->getChangeSummary()) {
|
Chris@0
|
753 $build = [];
|
Chris@0
|
754 foreach ($change_list as $entity_type_id => $changes) {
|
Chris@0
|
755 $entity_type = \Drupal::entityManager()->getDefinition($entity_type_id);
|
Chris@0
|
756 $build[] = [
|
Chris@0
|
757 '#theme' => 'item_list',
|
Chris@0
|
758 '#title' => $entity_type->getLabel(),
|
Chris@0
|
759 '#items' => $changes,
|
Chris@0
|
760 ];
|
Chris@0
|
761 }
|
Chris@0
|
762
|
Chris@0
|
763 $entity_update_issues = \Drupal::service('renderer')->renderPlain($build);
|
Chris@0
|
764 $requirements['entity_update']['severity'] = REQUIREMENT_ERROR;
|
Chris@0
|
765 $requirements['entity_update']['value'] = t('Mismatched entity and/or field definitions');
|
Chris@0
|
766 $requirements['entity_update']['description'] = t('The following changes were detected in the entity type and field definitions. @updates', ['@updates' => $entity_update_issues]);
|
Chris@0
|
767 }
|
Chris@0
|
768 }
|
Chris@0
|
769
|
Chris@0
|
770 // Verify the update.php access setting
|
Chris@0
|
771 if ($phase == 'runtime') {
|
Chris@0
|
772 if (Settings::get('update_free_access')) {
|
Chris@0
|
773 $requirements['update access'] = [
|
Chris@0
|
774 'value' => t('Not protected'),
|
Chris@0
|
775 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
776 'description' => t('The update.php script is accessible to everyone without authentication check, which is a security risk. You must change the @settings_name value in your settings.php back to FALSE.', ['@settings_name' => '$settings[\'update_free_access\']']),
|
Chris@0
|
777 ];
|
Chris@0
|
778 }
|
Chris@0
|
779 else {
|
Chris@0
|
780 $requirements['update access'] = [
|
Chris@0
|
781 'value' => t('Protected'),
|
Chris@0
|
782 ];
|
Chris@0
|
783 }
|
Chris@0
|
784 $requirements['update access']['title'] = t('Access to update.php');
|
Chris@0
|
785 }
|
Chris@0
|
786
|
Chris@0
|
787 // Display an error if a newly introduced dependency in a module is not resolved.
|
Chris@0
|
788 if ($phase == 'update') {
|
Chris@0
|
789 $profile = drupal_get_profile();
|
Chris@0
|
790 $files = system_rebuild_module_data();
|
Chris@0
|
791 foreach ($files as $module => $file) {
|
Chris@0
|
792 // Ignore disabled modules and installation profiles.
|
Chris@0
|
793 if (!$file->status || $module == $profile) {
|
Chris@0
|
794 continue;
|
Chris@0
|
795 }
|
Chris@0
|
796 // Check the module's PHP version.
|
Chris@0
|
797 $name = $file->info['name'];
|
Chris@0
|
798 $php = $file->info['php'];
|
Chris@0
|
799 if (version_compare($php, PHP_VERSION, '>')) {
|
Chris@0
|
800 $requirements['php']['description'] .= t('@name requires at least PHP @version.', ['@name' => $name, '@version' => $php]);
|
Chris@0
|
801 $requirements['php']['severity'] = REQUIREMENT_ERROR;
|
Chris@0
|
802 }
|
Chris@0
|
803 // Check the module's required modules.
|
Chris@0
|
804 foreach ($file->requires as $requirement) {
|
Chris@0
|
805 $required_module = $requirement['name'];
|
Chris@0
|
806 // Check if the module exists.
|
Chris@0
|
807 if (!isset($files[$required_module])) {
|
Chris@0
|
808 $requirements["$module-$required_module"] = [
|
Chris@0
|
809 'title' => t('Unresolved dependency'),
|
Chris@0
|
810 'description' => t('@name requires this module.', ['@name' => $name]),
|
Chris@0
|
811 'value' => t('@required_name (Missing)', ['@required_name' => $required_module]),
|
Chris@0
|
812 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
813 ];
|
Chris@0
|
814 continue;
|
Chris@0
|
815 }
|
Chris@0
|
816 // Check for an incompatible version.
|
Chris@0
|
817 $required_file = $files[$required_module];
|
Chris@0
|
818 $required_name = $required_file->info['name'];
|
Chris@0
|
819 $version = str_replace(\Drupal::CORE_COMPATIBILITY . '-', '', $required_file->info['version']);
|
Chris@0
|
820 $compatibility = drupal_check_incompatibility($requirement, $version);
|
Chris@0
|
821 if ($compatibility) {
|
Chris@0
|
822 $compatibility = rtrim(substr($compatibility, 2), ')');
|
Chris@0
|
823 $requirements["$module-$required_module"] = [
|
Chris@0
|
824 'title' => t('Unresolved dependency'),
|
Chris@0
|
825 'description' => t('@name requires this module and version. Currently using @required_name version @version', ['@name' => $name, '@required_name' => $required_name, '@version' => $version]),
|
Chris@0
|
826 'value' => t('@required_name (Version @compatibility required)', ['@required_name' => $required_name, '@compatibility' => $compatibility]),
|
Chris@0
|
827 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
828 ];
|
Chris@0
|
829 continue;
|
Chris@0
|
830 }
|
Chris@0
|
831 }
|
Chris@0
|
832 }
|
Chris@0
|
833 }
|
Chris@0
|
834
|
Chris@0
|
835 // Returns Unicode library status and errors.
|
Chris@0
|
836 $libraries = [
|
Chris@0
|
837 Unicode::STATUS_SINGLEBYTE => t('Standard PHP'),
|
Chris@0
|
838 Unicode::STATUS_MULTIBYTE => t('PHP Mbstring Extension'),
|
Chris@0
|
839 Unicode::STATUS_ERROR => t('Error'),
|
Chris@0
|
840 ];
|
Chris@0
|
841 $severities = [
|
Chris@0
|
842 Unicode::STATUS_SINGLEBYTE => REQUIREMENT_WARNING,
|
Chris@0
|
843 Unicode::STATUS_MULTIBYTE => NULL,
|
Chris@0
|
844 Unicode::STATUS_ERROR => REQUIREMENT_ERROR,
|
Chris@0
|
845 ];
|
Chris@0
|
846 $failed_check = Unicode::check();
|
Chris@0
|
847 $library = Unicode::getStatus();
|
Chris@0
|
848
|
Chris@0
|
849 $requirements['unicode'] = [
|
Chris@0
|
850 'title' => t('Unicode library'),
|
Chris@0
|
851 'value' => $libraries[$library],
|
Chris@0
|
852 'severity' => $severities[$library],
|
Chris@0
|
853 ];
|
Chris@0
|
854 switch ($failed_check) {
|
Chris@0
|
855 case 'mb_strlen':
|
Chris@0
|
856 $requirements['unicode']['description'] = t('Operations on Unicode strings are emulated on a best-effort basis. Install the <a href="http://php.net/mbstring">PHP mbstring extension</a> for improved Unicode support.');
|
Chris@0
|
857 break;
|
Chris@0
|
858
|
Chris@0
|
859 case 'mbstring.func_overload':
|
Chris@0
|
860 $requirements['unicode']['description'] = t('Multibyte string function overloading in PHP is active and must be disabled. Check the php.ini <em>mbstring.func_overload</em> setting. Please refer to the <a href="http://php.net/mbstring">PHP mbstring documentation</a> for more information.');
|
Chris@0
|
861 break;
|
Chris@0
|
862
|
Chris@0
|
863 case 'mbstring.encoding_translation':
|
Chris@0
|
864 $requirements['unicode']['description'] = t('Multibyte string input conversion in PHP is active and must be disabled. Check the php.ini <em>mbstring.encoding_translation</em> setting. Please refer to the <a href="http://php.net/mbstring">PHP mbstring documentation</a> for more information.');
|
Chris@0
|
865 break;
|
Chris@0
|
866
|
Chris@0
|
867 case 'mbstring.http_input':
|
Chris@0
|
868 $requirements['unicode']['description'] = t('Multibyte string input conversion in PHP is active and must be disabled. Check the php.ini <em>mbstring.http_input</em> setting. Please refer to the <a href="http://php.net/mbstring">PHP mbstring documentation</a> for more information.');
|
Chris@0
|
869 break;
|
Chris@0
|
870
|
Chris@0
|
871 case 'mbstring.http_output':
|
Chris@0
|
872 $requirements['unicode']['description'] = t('Multibyte string output conversion in PHP is active and must be disabled. Check the php.ini <em>mbstring.http_output</em> setting. Please refer to the <a href="http://php.net/mbstring">PHP mbstring documentation</a> for more information.');
|
Chris@0
|
873 break;
|
Chris@0
|
874 }
|
Chris@0
|
875
|
Chris@0
|
876 if ($phase == 'runtime') {
|
Chris@0
|
877 // Check for update status module.
|
Chris@0
|
878 if (!\Drupal::moduleHandler()->moduleExists('update')) {
|
Chris@0
|
879 $requirements['update status'] = [
|
Chris@0
|
880 'value' => t('Not enabled'),
|
Chris@0
|
881 'severity' => REQUIREMENT_WARNING,
|
Chris@0
|
882 'description' => t('Update notifications are not enabled. It is <strong>highly recommended</strong> that you enable the Update Manager module from the <a href=":module">module administration page</a> in order to stay up-to-date on new releases. For more information, <a href=":update">Update status handbook page</a>.', [
|
Chris@0
|
883 ':update' => 'https://www.drupal.org/documentation/modules/update',
|
Chris@0
|
884 ':module' => \Drupal::url('system.modules_list'),
|
Chris@0
|
885 ]),
|
Chris@0
|
886 ];
|
Chris@0
|
887 }
|
Chris@0
|
888 else {
|
Chris@0
|
889 $requirements['update status'] = [
|
Chris@0
|
890 'value' => t('Enabled'),
|
Chris@0
|
891 ];
|
Chris@0
|
892 }
|
Chris@0
|
893 $requirements['update status']['title'] = t('Update notifications');
|
Chris@0
|
894
|
Chris@0
|
895 if (Settings::get('rebuild_access')) {
|
Chris@0
|
896 $requirements['rebuild access'] = [
|
Chris@0
|
897 'title' => t('Rebuild access'),
|
Chris@0
|
898 'value' => t('Enabled'),
|
Chris@0
|
899 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
900 'description' => t('The rebuild_access setting is enabled in settings.php. It is recommended to have this setting disabled unless you are performing a rebuild.'),
|
Chris@0
|
901 ];
|
Chris@0
|
902 }
|
Chris@0
|
903 }
|
Chris@0
|
904
|
Chris@0
|
905 // See if trusted hostnames have been configured, and warn the user if they
|
Chris@0
|
906 // are not set.
|
Chris@0
|
907 if ($phase == 'runtime') {
|
Chris@0
|
908 $trusted_host_patterns = Settings::get('trusted_host_patterns');
|
Chris@0
|
909 if (empty($trusted_host_patterns)) {
|
Chris@0
|
910 $requirements['trusted_host_patterns'] = [
|
Chris@0
|
911 'title' => t('Trusted Host Settings'),
|
Chris@0
|
912 'value' => t('Not enabled'),
|
Chris@0
|
913 'description' => t('The trusted_host_patterns setting is not configured in settings.php. This can lead to security vulnerabilities. It is <strong>highly recommended</strong> that you configure this. See <a href=":url">Protecting against HTTP HOST Header attacks</a> for more information.', [':url' => 'https://www.drupal.org/node/1992030']),
|
Chris@0
|
914 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
915 ];
|
Chris@0
|
916 }
|
Chris@0
|
917 else {
|
Chris@0
|
918 $requirements['trusted_host_patterns'] = [
|
Chris@0
|
919 'title' => t('Trusted Host Settings'),
|
Chris@0
|
920 'value' => t('Enabled'),
|
Chris@0
|
921 'description' => t('The trusted_host_patterns setting is set to allow %trusted_host_patterns', ['%trusted_host_patterns' => implode(', ', $trusted_host_patterns)]),
|
Chris@0
|
922 ];
|
Chris@0
|
923 }
|
Chris@0
|
924 }
|
Chris@0
|
925
|
Chris@0
|
926 // Check xdebug.max_nesting_level, as some pages will not work if it is too
|
Chris@0
|
927 // low.
|
Chris@0
|
928 if (extension_loaded('xdebug')) {
|
Chris@0
|
929 // Setting this value to 256 was considered adequate on Xdebug 2.3
|
Chris@0
|
930 // (see http://bugs.xdebug.org/bug_view_page.php?bug_id=00001100)
|
Chris@0
|
931 $minimum_nesting_level = 256;
|
Chris@0
|
932 $current_nesting_level = ini_get('xdebug.max_nesting_level');
|
Chris@0
|
933
|
Chris@0
|
934 if ($current_nesting_level < $minimum_nesting_level) {
|
Chris@0
|
935 $requirements['xdebug_max_nesting_level'] = [
|
Chris@0
|
936 'title' => t('Xdebug settings'),
|
Chris@0
|
937 'value' => t('xdebug.max_nesting_level is set to %value.', ['%value' => $current_nesting_level]),
|
Chris@0
|
938 'description' => t('Set <code>xdebug.max_nesting_level=@level</code> in your PHP configuration as some pages in your Drupal site will not work when this setting is too low.', ['@level' => $minimum_nesting_level]),
|
Chris@0
|
939 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
940 ];
|
Chris@0
|
941 }
|
Chris@0
|
942 }
|
Chris@0
|
943
|
Chris@0
|
944 // Warning for httpoxy on IIS with affected PHP versions
|
Chris@0
|
945 // @see https://www.drupal.org/node/2783079
|
Chris@0
|
946 if (strpos($software, 'Microsoft-IIS') !== FALSE
|
Chris@0
|
947 && (
|
Chris@0
|
948 version_compare(PHP_VERSION, '5.5.38', '<')
|
Chris@0
|
949 || (version_compare(PHP_VERSION, '5.6.0', '>=') && version_compare(PHP_VERSION, '5.6.24', '<'))
|
Chris@0
|
950 || (version_compare(PHP_VERSION, '7.0.0', '>=') && version_compare(PHP_VERSION, '7.0.9', '<'))
|
Chris@0
|
951 )) {
|
Chris@0
|
952 $dom = new \DOMDocument('1.0', 'UTF-8');
|
Chris@0
|
953 $webconfig = file_get_contents('web.config');
|
Chris@0
|
954 // If you are here the web.config file must - of course - be well formed.
|
Chris@0
|
955 // But the PHP DOM component will throw warnings on some XML compliant
|
Chris@0
|
956 // stuff, so silently parse the configuration file.
|
Chris@0
|
957 @$dom->loadHTML($webconfig);
|
Chris@0
|
958 $httpoxy_rewrite = FALSE;
|
Chris@0
|
959 foreach ($dom->getElementsByTagName('rule') as $rule) {
|
Chris@0
|
960 foreach ($rule->attributes as $attr) {
|
Chris@0
|
961 if (@$attr->name == 'name' && @$attr->nodeValue == 'Erase HTTP_PROXY') {
|
Chris@0
|
962 $httpoxy_rewrite = TRUE;
|
Chris@0
|
963 break 2;
|
Chris@0
|
964 }
|
Chris@0
|
965 }
|
Chris@0
|
966 }
|
Chris@0
|
967 if (!$httpoxy_rewrite) {
|
Chris@0
|
968 $requirements['iis_httpoxy_protection'] = [
|
Chris@0
|
969 'title' => t('IIS httpoxy protection'),
|
Chris@0
|
970 'value' => t('Your PHP runtime version is affected by the httpoxy vulnerability.'),
|
Chris@0
|
971 'description' => t('Either update your PHP runtime version or uncomment the "Erase HTTP_PROXY" rule in your web.config file and add HTTP_PROXY to the allowed headers list. See more details in the <a href=":link">security advisory</a>.', [':link' => 'https://www.drupal.org/SA-CORE-2016-003']),
|
Chris@0
|
972 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
973 ];
|
Chris@0
|
974 }
|
Chris@0
|
975 }
|
Chris@0
|
976
|
Chris@0
|
977 // Installations on Windows can run into limitations with MAX_PATH if the
|
Chris@0
|
978 // Drupal root directory is too deep in the filesystem. Generally this shows
|
Chris@0
|
979 // up in cached Twig templates and other public files with long directory or
|
Chris@0
|
980 // file names. There is no definite root directory depth below which Drupal is
|
Chris@0
|
981 // guaranteed to function correctly on Windows. Since problems are likely
|
Chris@0
|
982 // with more than 100 characters in the Drupal root path, show an error.
|
Chris@0
|
983 if (substr(PHP_OS, 0, 3) == 'WIN') {
|
Chris@0
|
984 $depth = strlen(realpath(DRUPAL_ROOT . '/' . PublicStream::basePath()));
|
Chris@0
|
985 if ($depth > 120) {
|
Chris@0
|
986 $requirements['max_path_on_windows'] = [
|
Chris@0
|
987 'title' => t('Windows installation depth'),
|
Chris@0
|
988 'description' => t('The public files directory path is %depth characters. Paths longer than 120 characters will cause problems on Windows.', ['%depth' => $depth]),
|
Chris@0
|
989 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
990 ];
|
Chris@0
|
991 }
|
Chris@0
|
992 }
|
Chris@0
|
993 // Check to see if dates will be limited to 1901-2038.
|
Chris@0
|
994 if (PHP_INT_SIZE <= 4) {
|
Chris@0
|
995 $requirements['limited_date_range'] = [
|
Chris@0
|
996 'title' => t('Limited date range'),
|
Chris@0
|
997 'value' => t('Your PHP installation has a limited date range.'),
|
Chris@0
|
998 'description' => t('You are running on a system where PHP is compiled or limited to using 32-bit integers. This will limit the range of dates and timestamps to the years 1901-2038. Read about the <a href=":url">limitations of 32-bit PHP</a>.', [':url' => 'https://www.drupal.org/docs/8/system-requirements/limitations-of-32-bit-php']),
|
Chris@0
|
999 'severity' => REQUIREMENT_WARNING,
|
Chris@0
|
1000 ];
|
Chris@0
|
1001 }
|
Chris@0
|
1002
|
Chris@0
|
1003 return $requirements;
|
Chris@0
|
1004 }
|
Chris@0
|
1005
|
Chris@0
|
1006 /**
|
Chris@0
|
1007 * Implements hook_install().
|
Chris@0
|
1008 */
|
Chris@0
|
1009 function system_install() {
|
Chris@0
|
1010 // Populate the cron key state variable.
|
Chris@0
|
1011 $cron_key = Crypt::randomBytesBase64(55);
|
Chris@0
|
1012 \Drupal::state()->set('system.cron_key', $cron_key);
|
Chris@0
|
1013
|
Chris@0
|
1014 // Populate the site UUID and default name (if not set).
|
Chris@0
|
1015 $site = \Drupal::configFactory()->getEditable('system.site');
|
Chris@0
|
1016 $site->set('uuid', \Drupal::service('uuid')->generate());
|
Chris@0
|
1017 if (!$site->get('name')) {
|
Chris@0
|
1018 $site->set('name', 'Drupal');
|
Chris@0
|
1019 }
|
Chris@0
|
1020 $site->save(TRUE);
|
Chris@0
|
1021 }
|
Chris@0
|
1022
|
Chris@0
|
1023 /**
|
Chris@0
|
1024 * Implements hook_schema().
|
Chris@0
|
1025 */
|
Chris@0
|
1026 function system_schema() {
|
Chris@0
|
1027 $schema['key_value'] = [
|
Chris@0
|
1028 'description' => 'Generic key-value storage table. See the state system for an example.',
|
Chris@0
|
1029 'fields' => [
|
Chris@0
|
1030 'collection' => [
|
Chris@0
|
1031 'description' => 'A named collection of key and value pairs.',
|
Chris@0
|
1032 'type' => 'varchar_ascii',
|
Chris@0
|
1033 'length' => 128,
|
Chris@0
|
1034 'not null' => TRUE,
|
Chris@0
|
1035 'default' => '',
|
Chris@0
|
1036 ],
|
Chris@0
|
1037 'name' => [
|
Chris@0
|
1038 'description' => 'The key of the key-value pair. As KEY is a SQL reserved keyword, name was chosen instead.',
|
Chris@0
|
1039 'type' => 'varchar_ascii',
|
Chris@0
|
1040 'length' => 128,
|
Chris@0
|
1041 'not null' => TRUE,
|
Chris@0
|
1042 'default' => '',
|
Chris@0
|
1043 ],
|
Chris@0
|
1044 'value' => [
|
Chris@0
|
1045 'description' => 'The value.',
|
Chris@0
|
1046 'type' => 'blob',
|
Chris@0
|
1047 'not null' => TRUE,
|
Chris@0
|
1048 'size' => 'big',
|
Chris@0
|
1049 ],
|
Chris@0
|
1050 ],
|
Chris@0
|
1051 'primary key' => ['collection', 'name'],
|
Chris@0
|
1052 ];
|
Chris@0
|
1053
|
Chris@0
|
1054 $schema['key_value_expire'] = [
|
Chris@0
|
1055 'description' => 'Generic key/value storage table with an expiration.',
|
Chris@0
|
1056 'fields' => [
|
Chris@0
|
1057 'collection' => [
|
Chris@0
|
1058 'description' => 'A named collection of key and value pairs.',
|
Chris@0
|
1059 'type' => 'varchar_ascii',
|
Chris@0
|
1060 'length' => 128,
|
Chris@0
|
1061 'not null' => TRUE,
|
Chris@0
|
1062 'default' => '',
|
Chris@0
|
1063 ],
|
Chris@0
|
1064 'name' => [
|
Chris@0
|
1065 // KEY is an SQL reserved word, so use 'name' as the key's field name.
|
Chris@0
|
1066 'description' => 'The key of the key/value pair.',
|
Chris@0
|
1067 'type' => 'varchar_ascii',
|
Chris@0
|
1068 'length' => 128,
|
Chris@0
|
1069 'not null' => TRUE,
|
Chris@0
|
1070 'default' => '',
|
Chris@0
|
1071 ],
|
Chris@0
|
1072 'value' => [
|
Chris@0
|
1073 'description' => 'The value of the key/value pair.',
|
Chris@0
|
1074 'type' => 'blob',
|
Chris@0
|
1075 'not null' => TRUE,
|
Chris@0
|
1076 'size' => 'big',
|
Chris@0
|
1077 ],
|
Chris@0
|
1078 'expire' => [
|
Chris@0
|
1079 'description' => 'The time since Unix epoch in seconds when this item expires. Defaults to the maximum possible time.',
|
Chris@0
|
1080 'type' => 'int',
|
Chris@0
|
1081 'not null' => TRUE,
|
Chris@0
|
1082 'default' => 2147483647,
|
Chris@0
|
1083 ],
|
Chris@0
|
1084 ],
|
Chris@0
|
1085 'primary key' => ['collection', 'name'],
|
Chris@0
|
1086 'indexes' => [
|
Chris@0
|
1087 'all' => ['name', 'collection', 'expire'],
|
Chris@0
|
1088 'expire' => ['expire'],
|
Chris@0
|
1089 ],
|
Chris@0
|
1090 ];
|
Chris@0
|
1091
|
Chris@0
|
1092 $schema['sequences'] = [
|
Chris@0
|
1093 'description' => 'Stores IDs.',
|
Chris@0
|
1094 'fields' => [
|
Chris@0
|
1095 'value' => [
|
Chris@0
|
1096 'description' => 'The value of the sequence.',
|
Chris@0
|
1097 'type' => 'serial',
|
Chris@0
|
1098 'unsigned' => TRUE,
|
Chris@0
|
1099 'not null' => TRUE,
|
Chris@0
|
1100 ],
|
Chris@0
|
1101 ],
|
Chris@0
|
1102 'primary key' => ['value'],
|
Chris@0
|
1103 ];
|
Chris@0
|
1104
|
Chris@0
|
1105 $schema['sessions'] = [
|
Chris@0
|
1106 'description' => "Drupal's session handlers read and write into the sessions table. Each record represents a user session, either anonymous or authenticated.",
|
Chris@0
|
1107 'fields' => [
|
Chris@0
|
1108 'uid' => [
|
Chris@0
|
1109 'description' => 'The {users}.uid corresponding to a session, or 0 for anonymous user.',
|
Chris@0
|
1110 'type' => 'int',
|
Chris@0
|
1111 'unsigned' => TRUE,
|
Chris@0
|
1112 'not null' => TRUE,
|
Chris@0
|
1113 ],
|
Chris@0
|
1114 'sid' => [
|
Chris@0
|
1115 'description' => "A session ID (hashed). The value is generated by Drupal's session handlers.",
|
Chris@0
|
1116 'type' => 'varchar_ascii',
|
Chris@0
|
1117 'length' => 128,
|
Chris@0
|
1118 'not null' => TRUE,
|
Chris@0
|
1119 ],
|
Chris@0
|
1120 'hostname' => [
|
Chris@0
|
1121 'description' => 'The IP address that last used this session ID (sid).',
|
Chris@0
|
1122 'type' => 'varchar_ascii',
|
Chris@0
|
1123 'length' => 128,
|
Chris@0
|
1124 'not null' => TRUE,
|
Chris@0
|
1125 'default' => '',
|
Chris@0
|
1126 ],
|
Chris@0
|
1127 'timestamp' => [
|
Chris@0
|
1128 'description' => 'The Unix timestamp when this session last requested a page. Old records are purged by PHP automatically.',
|
Chris@0
|
1129 'type' => 'int',
|
Chris@0
|
1130 'not null' => TRUE,
|
Chris@0
|
1131 'default' => 0,
|
Chris@0
|
1132 ],
|
Chris@0
|
1133 'session' => [
|
Chris@0
|
1134 'description' => 'The serialized contents of $_SESSION, an array of name/value pairs that persists across page requests by this session ID. Drupal loads $_SESSION from here at the start of each request and saves it at the end.',
|
Chris@0
|
1135 'type' => 'blob',
|
Chris@0
|
1136 'not null' => FALSE,
|
Chris@0
|
1137 'size' => 'big',
|
Chris@0
|
1138 ],
|
Chris@0
|
1139 ],
|
Chris@0
|
1140 'primary key' => [
|
Chris@0
|
1141 'sid',
|
Chris@0
|
1142 ],
|
Chris@0
|
1143 'indexes' => [
|
Chris@0
|
1144 'timestamp' => ['timestamp'],
|
Chris@0
|
1145 'uid' => ['uid'],
|
Chris@0
|
1146 ],
|
Chris@0
|
1147 'foreign keys' => [
|
Chris@0
|
1148 'session_user' => [
|
Chris@0
|
1149 'table' => 'users',
|
Chris@0
|
1150 'columns' => ['uid' => 'uid'],
|
Chris@0
|
1151 ],
|
Chris@0
|
1152 ],
|
Chris@0
|
1153 ];
|
Chris@0
|
1154
|
Chris@0
|
1155 // Create the url_alias table. The alias_storage service can auto-create its
|
Chris@0
|
1156 // table, but this relies on exceptions being thrown. These exceptions will be
|
Chris@0
|
1157 // thrown every request until an alias is created.
|
Chris@0
|
1158 $schema['url_alias'] = AliasStorage::schemaDefinition();
|
Chris@0
|
1159
|
Chris@0
|
1160 return $schema;
|
Chris@0
|
1161 }
|
Chris@0
|
1162
|
Chris@0
|
1163 /**
|
Chris@0
|
1164 * Change two fields on the default menu link storage to be serialized data.
|
Chris@0
|
1165 */
|
Chris@0
|
1166 function system_update_8001(&$sandbox = NULL) {
|
Chris@0
|
1167 $database = \Drupal::database();
|
Chris@0
|
1168 $schema = $database->schema();
|
Chris@0
|
1169 if ($schema->tableExists('menu_tree')) {
|
Chris@0
|
1170
|
Chris@0
|
1171 if (!isset($sandbox['current'])) {
|
Chris@0
|
1172 // Converting directly to blob can cause problems with reading out and
|
Chris@0
|
1173 // serializing the string data later on postgres, so rename the existing
|
Chris@0
|
1174 // columns and create replacement ones to hold the serialized objects.
|
Chris@0
|
1175 $old_fields = [
|
Chris@0
|
1176 'title' => [
|
Chris@0
|
1177 'description' => 'The text displayed for the link.',
|
Chris@0
|
1178 'type' => 'varchar',
|
Chris@0
|
1179 'length' => 255,
|
Chris@0
|
1180 'not null' => TRUE,
|
Chris@0
|
1181 'default' => '',
|
Chris@0
|
1182 ],
|
Chris@0
|
1183 'description' => [
|
Chris@0
|
1184 'description' => 'The description of this link - used for admin pages and title attribute.',
|
Chris@0
|
1185 'type' => 'text',
|
Chris@0
|
1186 'not null' => FALSE,
|
Chris@0
|
1187 ],
|
Chris@0
|
1188 ];
|
Chris@0
|
1189 foreach ($old_fields as $name => $spec) {
|
Chris@0
|
1190 $schema->changeField('menu_tree', $name, 'system_update_8001_' . $name, $spec);
|
Chris@0
|
1191 }
|
Chris@0
|
1192 $spec = [
|
Chris@0
|
1193 'description' => 'The title for the link. May be a serialized TranslatableMarkup.',
|
Chris@0
|
1194 'type' => 'blob',
|
Chris@0
|
1195 'size' => 'big',
|
Chris@0
|
1196 'not null' => FALSE,
|
Chris@0
|
1197 'serialize' => TRUE,
|
Chris@0
|
1198 ];
|
Chris@0
|
1199 $schema->addField('menu_tree', 'title', $spec);
|
Chris@0
|
1200 $spec = [
|
Chris@0
|
1201 'description' => 'The description of this link - used for admin pages and title attribute.',
|
Chris@0
|
1202 'type' => 'blob',
|
Chris@0
|
1203 'size' => 'big',
|
Chris@0
|
1204 'not null' => FALSE,
|
Chris@0
|
1205 'serialize' => TRUE,
|
Chris@0
|
1206 ];
|
Chris@0
|
1207 $schema->addField('menu_tree', 'description', $spec);
|
Chris@0
|
1208
|
Chris@0
|
1209 $sandbox['current'] = 0;
|
Chris@0
|
1210 $sandbox['max'] = $database->query('SELECT COUNT(mlid) FROM {menu_tree}')
|
Chris@0
|
1211 ->fetchField();
|
Chris@0
|
1212 }
|
Chris@0
|
1213
|
Chris@0
|
1214 $menu_links = $database->queryRange('SELECT mlid, system_update_8001_title AS title, system_update_8001_description AS description FROM {menu_tree} ORDER BY mlid ASC', $sandbox['current'], $sandbox['current'] + 50)
|
Chris@0
|
1215 ->fetchAllAssoc('mlid');
|
Chris@0
|
1216
|
Chris@0
|
1217 foreach ($menu_links as $menu_link) {
|
Chris@0
|
1218 $menu_link = (array) $menu_link;
|
Chris@0
|
1219 // Convert title and description to serialized strings.
|
Chris@0
|
1220 $menu_link['title'] = serialize($menu_link['title']);
|
Chris@0
|
1221 $menu_link['description'] = serialize($menu_link['description']);
|
Chris@0
|
1222
|
Chris@0
|
1223 $database->update('menu_tree')
|
Chris@0
|
1224 ->fields($menu_link)
|
Chris@0
|
1225 ->condition('mlid', $menu_link['mlid'])
|
Chris@0
|
1226 ->execute();
|
Chris@0
|
1227
|
Chris@0
|
1228 $sandbox['current']++;
|
Chris@0
|
1229 }
|
Chris@0
|
1230
|
Chris@0
|
1231 $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['current'] / $sandbox['max']);
|
Chris@0
|
1232
|
Chris@0
|
1233 if ($sandbox['#finished'] >= 1) {
|
Chris@0
|
1234 // Drop unnecessary fields from {menu_tree}.
|
Chris@0
|
1235 $schema->dropField('menu_tree', 'system_update_8001_title');
|
Chris@0
|
1236 $schema->dropField('menu_tree', 'title_arguments');
|
Chris@0
|
1237 $schema->dropField('menu_tree', 'title_context');
|
Chris@0
|
1238 $schema->dropField('menu_tree', 'system_update_8001_description');
|
Chris@0
|
1239 }
|
Chris@0
|
1240 return t('Menu links converted');
|
Chris@0
|
1241 }
|
Chris@0
|
1242 else {
|
Chris@0
|
1243 return t('Menu link conversion skipped, because the {menu_tree} table did not exist yet.');
|
Chris@0
|
1244 }
|
Chris@0
|
1245 }
|
Chris@0
|
1246
|
Chris@0
|
1247 /**
|
Chris@0
|
1248 * Removes the system.filter configuration.
|
Chris@0
|
1249 */
|
Chris@0
|
1250 function system_update_8002() {
|
Chris@0
|
1251 \Drupal::configFactory()->getEditable('system.filter')->delete();
|
Chris@0
|
1252 return t('The system.filter configuration has been moved to a container parameter, see default.services.yml for more information.');
|
Chris@0
|
1253 }
|
Chris@0
|
1254
|
Chris@0
|
1255 /**
|
Chris@0
|
1256 * Change the index on the {router} table.
|
Chris@0
|
1257 */
|
Chris@0
|
1258 function system_update_8003() {
|
Chris@0
|
1259 $database = \Drupal::database();
|
Chris@0
|
1260 $database->schema()->dropIndex('router', 'pattern_outline_fit');
|
Chris@0
|
1261 $database->schema()->addIndex(
|
Chris@0
|
1262 'router',
|
Chris@0
|
1263 'pattern_outline_parts',
|
Chris@0
|
1264 ['pattern_outline', 'number_parts'],
|
Chris@0
|
1265 [
|
Chris@0
|
1266 'fields' => [
|
Chris@0
|
1267 'pattern_outline' => [
|
Chris@0
|
1268 'description' => 'The pattern',
|
Chris@0
|
1269 'type' => 'varchar',
|
Chris@0
|
1270 'length' => 255,
|
Chris@0
|
1271 'not null' => TRUE,
|
Chris@0
|
1272 'default' => '',
|
Chris@0
|
1273 ],
|
Chris@0
|
1274 'number_parts' => [
|
Chris@0
|
1275 'description' => 'Number of parts in this router path.',
|
Chris@0
|
1276 'type' => 'int',
|
Chris@0
|
1277 'not null' => TRUE,
|
Chris@0
|
1278 'default' => 0,
|
Chris@0
|
1279 'size' => 'small',
|
Chris@0
|
1280 ],
|
Chris@0
|
1281 ],
|
Chris@0
|
1282 ]
|
Chris@0
|
1283 );
|
Chris@0
|
1284 }
|
Chris@0
|
1285
|
Chris@0
|
1286 /**
|
Chris@0
|
1287 * Add a (id, default_langcode, langcode) composite index to entities.
|
Chris@0
|
1288 */
|
Chris@0
|
1289 function system_update_8004() {
|
Chris@0
|
1290 // \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema was changed in
|
Chris@0
|
1291 // https://www.drupal.org/node/2261669 to include a (id, default_langcode,
|
Chris@0
|
1292 // langcode) compound index, but this update function wasn't added until
|
Chris@0
|
1293 // https://www.drupal.org/node/2542748. Regenerate the related schemas to
|
Chris@0
|
1294 // ensure they match the currently expected status.
|
Chris@0
|
1295 $manager = \Drupal::entityDefinitionUpdateManager();
|
Chris@0
|
1296 foreach (array_keys(\Drupal::entityManager()
|
Chris@0
|
1297 ->getDefinitions()) as $entity_type_id) {
|
Chris@0
|
1298 // Only update the entity type if it already exists. This condition is
|
Chris@0
|
1299 // needed in case new entity types are introduced after this update.
|
Chris@0
|
1300 if ($entity_type = $manager->getEntityType($entity_type_id)) {
|
Chris@0
|
1301 $manager->updateEntityType($entity_type);
|
Chris@0
|
1302 }
|
Chris@0
|
1303 }
|
Chris@0
|
1304 }
|
Chris@0
|
1305
|
Chris@0
|
1306 /**
|
Chris@0
|
1307 * Place local actions and tasks blocks in every theme.
|
Chris@0
|
1308 */
|
Chris@0
|
1309 function system_update_8005() {
|
Chris@0
|
1310 // When block module is not installed, there is nothing that could be done
|
Chris@0
|
1311 // except showing a warning.
|
Chris@0
|
1312 if (!\Drupal::moduleHandler()->moduleExists('block')) {
|
Chris@0
|
1313 return t('Block module is not enabled so local actions and tasks which have been converted to blocks, are not visible anymore.');
|
Chris@0
|
1314 }
|
Chris@0
|
1315 $config_factory = \Drupal::configFactory();
|
Chris@0
|
1316 /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */
|
Chris@0
|
1317 $theme_handler = \Drupal::service('theme_handler');
|
Chris@0
|
1318 $custom_themes_installed = FALSE;
|
Chris@0
|
1319 $message = NULL;
|
Chris@0
|
1320 $langcode = \Drupal::service('language_manager')->getCurrentLanguage()->getId();
|
Chris@0
|
1321
|
Chris@0
|
1322 $local_actions_default_settings = [
|
Chris@0
|
1323 'plugin' => 'local_actions_block',
|
Chris@0
|
1324 'region' => 'content',
|
Chris@0
|
1325 'settings.label' => 'Primary admin actions',
|
Chris@0
|
1326 'settings.label_display' => 0,
|
Chris@0
|
1327 'settings.cache.max_age' => 0,
|
Chris@0
|
1328 'visibility' => [],
|
Chris@0
|
1329 'weight' => 0,
|
Chris@0
|
1330 'langcode' => $langcode,
|
Chris@0
|
1331 ];
|
Chris@0
|
1332 $tabs_default_settings = [
|
Chris@0
|
1333 'plugin' => 'local_tasks_block',
|
Chris@0
|
1334 'region' => 'content',
|
Chris@0
|
1335 'settings.label' => 'Tabs',
|
Chris@0
|
1336 'settings.label_display' => 0,
|
Chris@0
|
1337 'settings.cache.max_age' => 0,
|
Chris@0
|
1338 'visibility' => [],
|
Chris@0
|
1339 'weight' => 0,
|
Chris@0
|
1340 'langcode' => $langcode,
|
Chris@0
|
1341 ];
|
Chris@0
|
1342 foreach ($theme_handler->listInfo() as $theme) {
|
Chris@0
|
1343 $theme_name = $theme->getName();
|
Chris@0
|
1344 switch ($theme_name) {
|
Chris@0
|
1345 case 'bartik':
|
Chris@0
|
1346 $name = 'block.block.bartik_local_actions';
|
Chris@0
|
1347 $values = [
|
Chris@0
|
1348 'id' => 'bartik_local_actions',
|
Chris@0
|
1349 'weight' => -1,
|
Chris@0
|
1350 ] + $local_actions_default_settings;
|
Chris@0
|
1351 _system_update_create_block($name, $theme_name, $values);
|
Chris@0
|
1352
|
Chris@0
|
1353 $name = 'block.block.bartik_local_tasks';
|
Chris@0
|
1354 $values = [
|
Chris@0
|
1355 'id' => 'bartik_local_tasks',
|
Chris@0
|
1356 'weight' => -7,
|
Chris@0
|
1357 ] + $tabs_default_settings;
|
Chris@0
|
1358 _system_update_create_block($name, $theme_name, $values);
|
Chris@0
|
1359
|
Chris@0
|
1360 // Help region has been removed so all the blocks inside has to be moved
|
Chris@0
|
1361 // to content region.
|
Chris@0
|
1362 $weight = -6;
|
Chris@0
|
1363 $blocks = [];
|
Chris@0
|
1364 foreach ($config_factory->listAll('block.block.') as $block_config) {
|
Chris@0
|
1365 $block = $config_factory->getEditable($block_config);
|
Chris@0
|
1366 if ($block->get('theme') == 'bartik' && $block->get('region') == 'help') {
|
Chris@0
|
1367 $blocks[] = $block;
|
Chris@0
|
1368 }
|
Chris@0
|
1369 }
|
Chris@0
|
1370 // Sort blocks by block weight.
|
Chris@0
|
1371 uasort($blocks, function ($a, $b) {
|
Chris@0
|
1372 return $a->get('weight') - $b->get('weight');
|
Chris@0
|
1373 });
|
Chris@0
|
1374 // Move blocks to content region and set them in right order by their
|
Chris@0
|
1375 // weight.
|
Chris@0
|
1376 foreach ($blocks as $block) {
|
Chris@0
|
1377 $block->set('region', 'content');
|
Chris@0
|
1378 $block->set('weight', $weight++);
|
Chris@0
|
1379 $block->save();
|
Chris@0
|
1380 }
|
Chris@0
|
1381 break;
|
Chris@0
|
1382
|
Chris@0
|
1383 case 'seven':
|
Chris@0
|
1384 $name = 'block.block.seven_local_actions';
|
Chris@0
|
1385 $values = [
|
Chris@0
|
1386 'id' => 'seven_local_actions',
|
Chris@0
|
1387 'weight' => -10,
|
Chris@0
|
1388 ] + $local_actions_default_settings;
|
Chris@0
|
1389 _system_update_create_block($name, $theme_name, $values);
|
Chris@0
|
1390
|
Chris@0
|
1391 $name = 'block.block.seven_primary_local_tasks';
|
Chris@0
|
1392 $values = [
|
Chris@0
|
1393 'region' => 'header',
|
Chris@0
|
1394 'id' => 'seven_primary_local_tasks',
|
Chris@0
|
1395 'settings.label' => 'Primary tabs',
|
Chris@0
|
1396 'settings.primary' => TRUE,
|
Chris@0
|
1397 'settings.secondary' => FALSE,
|
Chris@0
|
1398 ] + $tabs_default_settings;
|
Chris@0
|
1399 _system_update_create_block($name, $theme_name, $values);
|
Chris@0
|
1400
|
Chris@0
|
1401 $name = 'block.block.seven_secondary_local_tasks';
|
Chris@0
|
1402 $values = [
|
Chris@0
|
1403 'region' => 'pre_content',
|
Chris@0
|
1404 'id' => 'seven_secondary_local_tasks',
|
Chris@0
|
1405 'settings.label' => 'Secondary tabs',
|
Chris@0
|
1406 'settings.primary' => FALSE,
|
Chris@0
|
1407 'settings.secondary' => TRUE,
|
Chris@0
|
1408 ] + $tabs_default_settings;
|
Chris@0
|
1409 _system_update_create_block($name, $theme_name, $values);
|
Chris@0
|
1410 break;
|
Chris@0
|
1411
|
Chris@0
|
1412 case 'stark':
|
Chris@0
|
1413 $name = 'block.block.stark_local_actions';
|
Chris@0
|
1414 $values = [
|
Chris@0
|
1415 'id' => 'stark_local_actions',
|
Chris@0
|
1416 ] + $local_actions_default_settings;
|
Chris@0
|
1417 _system_update_create_block($name, $theme_name, $values);
|
Chris@0
|
1418
|
Chris@0
|
1419 $name = 'block.block.stark_local_tasks';
|
Chris@0
|
1420 $values = [
|
Chris@0
|
1421 'id' => 'stark_local_tasks',
|
Chris@0
|
1422 ] + $tabs_default_settings;
|
Chris@0
|
1423 _system_update_create_block($name, $theme_name, $values);
|
Chris@0
|
1424 break;
|
Chris@0
|
1425
|
Chris@0
|
1426 case 'classy':
|
Chris@0
|
1427 case 'stable':
|
Chris@0
|
1428 // Don't place any blocks or trigger custom themes installed warning.
|
Chris@0
|
1429 break;
|
Chris@0
|
1430
|
Chris@0
|
1431 default:
|
Chris@0
|
1432 $custom_themes_installed = TRUE;
|
Chris@0
|
1433 $name = 'block.block.' . $theme_name . '_local_actions';
|
Chris@0
|
1434 $values = [
|
Chris@0
|
1435 'id' => $theme_name . '_local_actions',
|
Chris@0
|
1436 'weight' => -10,
|
Chris@0
|
1437 ] + $local_actions_default_settings;
|
Chris@0
|
1438 _system_update_create_block($name, $theme_name, $values);
|
Chris@0
|
1439
|
Chris@0
|
1440 $name = sprintf('block.block.%s_local_tasks', $theme_name);
|
Chris@0
|
1441 $values = [
|
Chris@0
|
1442 'id' => $theme_name . '_local_tasks',
|
Chris@0
|
1443 'weight' => -20,
|
Chris@0
|
1444 ] + $tabs_default_settings;
|
Chris@0
|
1445 _system_update_create_block($name, $theme_name, $values);
|
Chris@0
|
1446 break;
|
Chris@0
|
1447 }
|
Chris@0
|
1448 }
|
Chris@0
|
1449
|
Chris@0
|
1450 if ($custom_themes_installed) {
|
Chris@0
|
1451 $message = t('Because your site has custom theme(s) installed, we had to set local actions and tasks blocks into the content region. Please manually review the block configurations and remove the removed variables from your templates.');
|
Chris@0
|
1452 }
|
Chris@0
|
1453
|
Chris@0
|
1454 return $message;
|
Chris@0
|
1455 }
|
Chris@0
|
1456
|
Chris@0
|
1457 /**
|
Chris@0
|
1458 * Place branding blocks in every theme.
|
Chris@0
|
1459 */
|
Chris@0
|
1460 function system_update_8006() {
|
Chris@0
|
1461 // When block module is not installed, there is nothing that could be done
|
Chris@0
|
1462 // except showing a warning.
|
Chris@0
|
1463 if (!\Drupal::moduleHandler()->moduleExists('block')) {
|
Chris@0
|
1464 return t('Block module is not enabled so site branding elements, which have been converted to a block, are not visible anymore.');
|
Chris@0
|
1465 }
|
Chris@0
|
1466
|
Chris@0
|
1467 /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */
|
Chris@0
|
1468 $theme_handler = \Drupal::service('theme_handler');
|
Chris@0
|
1469 $custom_themes_installed = FALSE;
|
Chris@0
|
1470 $message = NULL;
|
Chris@0
|
1471 $langcode = \Drupal::service('language_manager')->getCurrentLanguage()->getId();
|
Chris@0
|
1472
|
Chris@0
|
1473 $site_branding_default_settings = [
|
Chris@0
|
1474 'plugin' => 'system_branding_block',
|
Chris@0
|
1475 'region' => 'content',
|
Chris@0
|
1476 'settings.label' => 'Site branding',
|
Chris@0
|
1477 'settings.label_display' => 0,
|
Chris@0
|
1478 'visibility' => [],
|
Chris@0
|
1479 'weight' => 0,
|
Chris@0
|
1480 'langcode' => $langcode,
|
Chris@0
|
1481 ];
|
Chris@0
|
1482 foreach ($theme_handler->listInfo() as $theme) {
|
Chris@0
|
1483 $theme_name = $theme->getName();
|
Chris@0
|
1484 switch ($theme_name) {
|
Chris@0
|
1485 case 'bartik':
|
Chris@0
|
1486 $name = 'block.block.bartik_branding';
|
Chris@0
|
1487 $values = [
|
Chris@0
|
1488 'id' => 'bartik_branding',
|
Chris@0
|
1489 'region' => 'header',
|
Chris@0
|
1490 ] + $site_branding_default_settings;
|
Chris@0
|
1491 _system_update_create_block($name, $theme_name, $values);
|
Chris@0
|
1492 break;
|
Chris@0
|
1493
|
Chris@0
|
1494 case 'stark':
|
Chris@0
|
1495 $name = 'block.block.stark_branding';
|
Chris@0
|
1496 $values = [
|
Chris@0
|
1497 'id' => 'stark_branding',
|
Chris@0
|
1498 'region' => 'header',
|
Chris@0
|
1499 ] + $site_branding_default_settings;
|
Chris@0
|
1500 _system_update_create_block($name, $theme_name, $values);
|
Chris@0
|
1501 break;
|
Chris@0
|
1502
|
Chris@0
|
1503 case 'seven':
|
Chris@0
|
1504 case 'classy':
|
Chris@0
|
1505 case 'stable':
|
Chris@0
|
1506 // Don't place any blocks or trigger custom themes installed warning.
|
Chris@0
|
1507 break;
|
Chris@0
|
1508 default:
|
Chris@0
|
1509 $custom_themes_installed = TRUE;
|
Chris@0
|
1510 $name = sprintf('block.block.%s_branding', $theme_name);
|
Chris@0
|
1511 $values = [
|
Chris@0
|
1512 'id' => sprintf('%s_branding', $theme_name),
|
Chris@0
|
1513 'region' => 'content',
|
Chris@0
|
1514 'weight' => '-50',
|
Chris@0
|
1515 ] + $site_branding_default_settings;
|
Chris@0
|
1516 _system_update_create_block($name, $theme_name, $values);
|
Chris@0
|
1517 break;
|
Chris@0
|
1518 }
|
Chris@0
|
1519 }
|
Chris@0
|
1520
|
Chris@0
|
1521 if ($custom_themes_installed) {
|
Chris@0
|
1522 $message = t('Because your site has custom theme(s) installed, we had to set the branding block into the content region. Please manually review the block configuration and remove the site name, slogan, and logo variables from your templates.');
|
Chris@0
|
1523 }
|
Chris@0
|
1524
|
Chris@0
|
1525 return $message;
|
Chris@0
|
1526 }
|
Chris@0
|
1527
|
Chris@0
|
1528 /**
|
Chris@0
|
1529 * Helper function to create block configuration objects for an update.
|
Chris@0
|
1530 *
|
Chris@0
|
1531 * @param string $name
|
Chris@0
|
1532 * The name of the config object.
|
Chris@0
|
1533 * @param string $theme_name
|
Chris@0
|
1534 * The name of the theme the block is associated with.
|
Chris@0
|
1535 * @param array $values
|
Chris@0
|
1536 * The block config values.
|
Chris@0
|
1537 */
|
Chris@0
|
1538 function _system_update_create_block($name, $theme_name, array $values) {
|
Chris@0
|
1539 if (!\Drupal::service('config.storage')->exists($name)) {
|
Chris@0
|
1540 $block = \Drupal::configFactory()->getEditable($name);
|
Chris@0
|
1541 $values['uuid'] = \Drupal::service('uuid')->generate();
|
Chris@0
|
1542 $values['theme'] = $theme_name;
|
Chris@0
|
1543 $values['dependencies.theme'] = [$theme_name];
|
Chris@0
|
1544 foreach ($values as $key => $value) {
|
Chris@0
|
1545 $block->set($key, $value);
|
Chris@0
|
1546 }
|
Chris@0
|
1547 $block->save();
|
Chris@0
|
1548 }
|
Chris@0
|
1549 }
|
Chris@0
|
1550
|
Chris@0
|
1551 /**
|
Chris@0
|
1552 * Set langcode fields to be ASCII-only.
|
Chris@0
|
1553 */
|
Chris@0
|
1554 function system_update_8007() {
|
Chris@0
|
1555 $database = \Drupal::database();
|
Chris@0
|
1556 $database_schema = $database->schema();
|
Chris@0
|
1557 $entity_types = \Drupal::entityManager()->getDefinitions();
|
Chris@0
|
1558
|
Chris@0
|
1559 $schema = \Drupal::keyValue('entity.storage_schema.sql')->getAll();
|
Chris@0
|
1560 $schema_copy = $schema;
|
Chris@0
|
1561 foreach ($schema as $item_name => $item) {
|
Chris@0
|
1562 list($entity_type_id, ,) = explode('.', $item_name);
|
Chris@0
|
1563 if (!isset($entity_types[$entity_type_id])) {
|
Chris@0
|
1564 continue;
|
Chris@0
|
1565 }
|
Chris@0
|
1566 foreach ($item as $table_name => $table_schema) {
|
Chris@0
|
1567 foreach ($table_schema as $schema_key => $schema_data) {
|
Chris@0
|
1568 if ($schema_key == 'fields') {
|
Chris@0
|
1569 foreach ($schema_data as $field_name => $field_data) {
|
Chris@0
|
1570 foreach ($field_data as $field_data_property => $field_data_value) {
|
Chris@0
|
1571 // Langcode fields have the property 'is_ascii' set, instead
|
Chris@0
|
1572 // they should have set the type to 'varchar_ascii'.
|
Chris@0
|
1573 if ($field_data_property == 'is_ascii') {
|
Chris@0
|
1574 unset($schema_copy[$item_name][$table_name]['fields'][$field_name]['is_ascii']);
|
Chris@0
|
1575 $schema_copy[$item_name][$table_name]['fields'][$field_name]['type'] = 'varchar_ascii';
|
Chris@0
|
1576 if ($database->driver() == 'mysql') {
|
Chris@0
|
1577 $database_schema->changeField($table_name, $field_name, $field_name, $schema_copy[$item_name][$table_name]['fields'][$field_name]);
|
Chris@0
|
1578 }
|
Chris@0
|
1579 }
|
Chris@0
|
1580 }
|
Chris@0
|
1581 }
|
Chris@0
|
1582 }
|
Chris@0
|
1583 }
|
Chris@0
|
1584 }
|
Chris@0
|
1585 }
|
Chris@0
|
1586 \Drupal::keyValue('entity.storage_schema.sql')->setMultiple($schema_copy);
|
Chris@0
|
1587
|
Chris@0
|
1588 $definitions = \Drupal::keyValue('entity.definitions.installed')->getAll();
|
Chris@0
|
1589 $definitions_copy = $definitions;
|
Chris@0
|
1590 foreach ($definitions as $item_name => $item_value) {
|
Chris@0
|
1591 $suffix = '.field_storage_definitions';
|
Chris@0
|
1592 if (substr($item_name, -strlen($suffix)) == $suffix) {
|
Chris@0
|
1593 foreach ($item_value as $field_name => $field_definition) {
|
Chris@0
|
1594 $reflection = new \ReflectionObject($field_definition);
|
Chris@0
|
1595 $schema_property = $reflection->getProperty('schema');
|
Chris@0
|
1596 $schema_property->setAccessible(TRUE);
|
Chris@0
|
1597 $schema = $schema_property->getValue($field_definition);
|
Chris@0
|
1598 if (isset($schema['columns']['value']['is_ascii'])) {
|
Chris@0
|
1599 $schema['columns']['value']['type'] = 'varchar_ascii';
|
Chris@0
|
1600 unset($schema['columns']['value']['is_ascii']);
|
Chris@0
|
1601 }
|
Chris@0
|
1602 $schema_property->setValue($field_definition, $schema);
|
Chris@0
|
1603 $schema_property->setAccessible(FALSE);
|
Chris@0
|
1604 $definitions_copy[$item_name][$field_name] = $field_definition;
|
Chris@0
|
1605 }
|
Chris@0
|
1606 }
|
Chris@0
|
1607 }
|
Chris@0
|
1608 \Drupal::keyValue('entity.definitions.installed')->setMultiple($definitions_copy);
|
Chris@0
|
1609 }
|
Chris@0
|
1610
|
Chris@0
|
1611 /**
|
Chris@0
|
1612 * Purge field schema data for uninstalled entity types.
|
Chris@0
|
1613 */
|
Chris@0
|
1614 function system_update_8008() {
|
Chris@0
|
1615 $entity_types = \Drupal::entityManager()->getDefinitions();
|
Chris@0
|
1616 /** @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface $schema */
|
Chris@0
|
1617 $schema = \Drupal::keyValue('entity.storage_schema.sql');
|
Chris@0
|
1618 foreach ($schema->getAll() as $key => $item) {
|
Chris@0
|
1619 list($entity_type_id, ,) = explode('.', $key);
|
Chris@0
|
1620 if (!isset($entity_types[$entity_type_id])) {
|
Chris@0
|
1621 $schema->delete($key);
|
Chris@0
|
1622 }
|
Chris@0
|
1623 }
|
Chris@0
|
1624 }
|
Chris@0
|
1625
|
Chris@0
|
1626 /**
|
Chris@0
|
1627 * Add allowed attributes to existing html filters.
|
Chris@0
|
1628 */
|
Chris@0
|
1629 function system_update_8009() {
|
Chris@0
|
1630 $default_mapping = [
|
Chris@0
|
1631 '<a>' => '<a href hreflang>',
|
Chris@0
|
1632 '<blockquote>' => '<blockquote cite>',
|
Chris@0
|
1633 '<ol>' => '<ol start type>',
|
Chris@0
|
1634 '<ul>' => '<ul type>',
|
Chris@0
|
1635 '<img>' => '<img src alt height width>',
|
Chris@0
|
1636 '<h2>' => '<h2 id>',
|
Chris@0
|
1637 '<h3>' => '<h3 id>',
|
Chris@0
|
1638 '<h4>' => '<h4 id>',
|
Chris@0
|
1639 '<h5>' => '<h5 id>',
|
Chris@0
|
1640 '<h6>' => '<h6 id>',
|
Chris@0
|
1641 ];
|
Chris@0
|
1642 $config_factory = \Drupal::configFactory();
|
Chris@0
|
1643 foreach ($config_factory->listAll('filter.format') as $name) {
|
Chris@0
|
1644 $allowed_html_mapping = $default_mapping;
|
Chris@0
|
1645 $config = $config_factory->getEditable($name);
|
Chris@0
|
1646 // The image alignment filter needs the data-align attribute.
|
Chris@0
|
1647 $align_enabled = $config->get('filters.filter_align.status');
|
Chris@0
|
1648 if ($align_enabled) {
|
Chris@0
|
1649 $allowed_html_mapping['<img>'] = str_replace('>', ' data-align>', $allowed_html_mapping['<img>']);
|
Chris@0
|
1650 }
|
Chris@0
|
1651 // The image caption filter needs the data-caption attribute.
|
Chris@0
|
1652 $caption_enabled = $config->get('filters.filter_caption.status');
|
Chris@0
|
1653 if ($caption_enabled) {
|
Chris@0
|
1654 $allowed_html_mapping['<img>'] = str_replace('>', ' data-caption>', $allowed_html_mapping['<img>']);
|
Chris@0
|
1655 }
|
Chris@0
|
1656 $allowed_html = $config->get('filters.filter_html.settings.allowed_html');
|
Chris@0
|
1657 if (!empty($allowed_html)) {
|
Chris@0
|
1658 $allowed_html = strtr($allowed_html, $allowed_html_mapping);
|
Chris@0
|
1659 $config->set('filters.filter_html.settings.allowed_html', $allowed_html);
|
Chris@0
|
1660 $config->save();
|
Chris@0
|
1661 }
|
Chris@0
|
1662 }
|
Chris@0
|
1663 }
|
Chris@0
|
1664
|
Chris@0
|
1665 /**
|
Chris@0
|
1666 * Place page title blocks in every theme.
|
Chris@0
|
1667 */
|
Chris@0
|
1668 function system_update_8010() {
|
Chris@0
|
1669 // When block module is not installed, there is nothing that could be done
|
Chris@0
|
1670 // except showing a warning.
|
Chris@0
|
1671 if (!\Drupal::moduleHandler()->moduleExists('block')) {
|
Chris@0
|
1672 return t('Block module is not enabled. The page title has been converted to a block, but default page title markup will still display at the top of the main content area.');
|
Chris@0
|
1673 }
|
Chris@0
|
1674
|
Chris@0
|
1675 /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */
|
Chris@0
|
1676 $theme_handler = \Drupal::service('theme_handler');
|
Chris@0
|
1677 $custom_themes_installed = FALSE;
|
Chris@0
|
1678 $message = NULL;
|
Chris@0
|
1679 $langcode = \Drupal::service('language_manager')->getCurrentLanguage()->getId();
|
Chris@0
|
1680
|
Chris@0
|
1681 $page_title_default_settings = [
|
Chris@0
|
1682 'plugin' => 'page_title_block',
|
Chris@0
|
1683 'region' => 'content',
|
Chris@0
|
1684 'settings.label' => 'Page title',
|
Chris@0
|
1685 'settings.label_display' => 0,
|
Chris@0
|
1686 'visibility' => [],
|
Chris@0
|
1687 'weight' => -50,
|
Chris@0
|
1688 'langcode' => $langcode,
|
Chris@0
|
1689 ];
|
Chris@0
|
1690 foreach ($theme_handler->listInfo() as $theme) {
|
Chris@0
|
1691 $theme_name = $theme->getName();
|
Chris@0
|
1692 switch ($theme_name) {
|
Chris@0
|
1693 case 'bartik':
|
Chris@0
|
1694 $name = 'block.block.bartik_page_title';
|
Chris@0
|
1695 $values = [
|
Chris@0
|
1696 'id' => 'bartik_page_title',
|
Chris@0
|
1697 ] + $page_title_default_settings;
|
Chris@0
|
1698 _system_update_create_block($name, $theme_name, $values);
|
Chris@0
|
1699 break;
|
Chris@0
|
1700
|
Chris@0
|
1701 case 'stark':
|
Chris@0
|
1702 $name = 'block.block.stark_page_title';
|
Chris@0
|
1703 $values = [
|
Chris@0
|
1704 'id' => 'stark_page_title',
|
Chris@0
|
1705 'region' => 'content',
|
Chris@0
|
1706 ] + $page_title_default_settings;
|
Chris@0
|
1707 _system_update_create_block($name, $theme_name, $values);
|
Chris@0
|
1708 break;
|
Chris@0
|
1709
|
Chris@0
|
1710 case 'seven':
|
Chris@0
|
1711 $name = 'block.block.seven_page_title';
|
Chris@0
|
1712 $values = [
|
Chris@0
|
1713 'id' => 'seven_page_title',
|
Chris@0
|
1714 'region' => 'header',
|
Chris@0
|
1715 ] + $page_title_default_settings;
|
Chris@0
|
1716 _system_update_create_block($name, $theme_name, $values);
|
Chris@0
|
1717 break;
|
Chris@0
|
1718
|
Chris@0
|
1719 case 'classy':
|
Chris@0
|
1720 $name = 'block.block.classy_page_title';
|
Chris@0
|
1721 $values = [
|
Chris@0
|
1722 'id' => 'classy_page_title',
|
Chris@0
|
1723 'region' => 'content',
|
Chris@0
|
1724 ] + $page_title_default_settings;
|
Chris@0
|
1725 _system_update_create_block($name, $theme_name, $values);
|
Chris@0
|
1726 break;
|
Chris@0
|
1727
|
Chris@0
|
1728 default:
|
Chris@0
|
1729 $custom_themes_installed = TRUE;
|
Chris@0
|
1730 $name = sprintf('block.block.%s_page_title', $theme_name);
|
Chris@0
|
1731 $values = [
|
Chris@0
|
1732 'id' => sprintf('%s_page_title', $theme_name),
|
Chris@0
|
1733 'region' => 'content',
|
Chris@0
|
1734 'weight' => '-50',
|
Chris@0
|
1735 ] + $page_title_default_settings;
|
Chris@0
|
1736 _system_update_create_block($name, $theme_name, $values);
|
Chris@0
|
1737 break;
|
Chris@0
|
1738 }
|
Chris@0
|
1739 }
|
Chris@0
|
1740
|
Chris@0
|
1741 if ($custom_themes_installed) {
|
Chris@0
|
1742 $message = t('Because your site has custom theme(s) installed, we have placed the page title block in the content region. Please manually review the block configuration and remove the page title variables from your page templates.');
|
Chris@0
|
1743 }
|
Chris@0
|
1744
|
Chris@0
|
1745 return $message;
|
Chris@0
|
1746 }
|
Chris@0
|
1747
|
Chris@0
|
1748 /**
|
Chris@0
|
1749 * Add secondary local tasks block to Seven (fixes system_update_8005).
|
Chris@0
|
1750 */
|
Chris@0
|
1751 function system_update_8011() {
|
Chris@0
|
1752 $langcode = \Drupal::service('language_manager')->getCurrentLanguage()->getId();
|
Chris@0
|
1753 $theme_name = 'seven';
|
Chris@0
|
1754 $name = 'block.block.seven_secondary_local_tasks';
|
Chris@0
|
1755 $values = [
|
Chris@0
|
1756 'plugin' => 'local_tasks_block',
|
Chris@0
|
1757 'region' => 'pre_content',
|
Chris@0
|
1758 'id' => 'seven_secondary_local_tasks',
|
Chris@0
|
1759 'settings.label' => 'Secondary tabs',
|
Chris@0
|
1760 'settings.label_display' => 0,
|
Chris@0
|
1761 'settings.primary' => FALSE,
|
Chris@0
|
1762 'settings.secondary' => TRUE,
|
Chris@0
|
1763 'visibility' => [],
|
Chris@0
|
1764 'weight' => 0,
|
Chris@0
|
1765 'langcode' => $langcode,
|
Chris@0
|
1766 ];
|
Chris@0
|
1767 _system_update_create_block($name, $theme_name, $values);
|
Chris@0
|
1768 }
|
Chris@0
|
1769
|
Chris@0
|
1770 /**
|
Chris@0
|
1771 * Enable automated cron module and move the config into it.
|
Chris@0
|
1772 */
|
Chris@0
|
1773 function system_update_8013() {
|
Chris@0
|
1774 $config_factory = \Drupal::configFactory();
|
Chris@0
|
1775 $system_cron_config = $config_factory->getEditable('system.cron');
|
Chris@0
|
1776 if ($autorun = $system_cron_config->get('threshold.autorun')) {
|
Chris@0
|
1777 // Install 'automated_cron' module.
|
Chris@0
|
1778 \Drupal::service('module_installer')->install(['automated_cron'], FALSE);
|
Chris@0
|
1779
|
Chris@0
|
1780 // Copy 'autorun' value into the new module's 'interval' setting.
|
Chris@0
|
1781 $config_factory->getEditable('automated_cron.settings')
|
Chris@0
|
1782 ->set('interval', $autorun)
|
Chris@0
|
1783 ->save(TRUE);
|
Chris@0
|
1784 }
|
Chris@0
|
1785
|
Chris@0
|
1786 // Remove the 'autorun' key in system module config.
|
Chris@0
|
1787 $system_cron_config
|
Chris@0
|
1788 ->clear('threshold.autorun')
|
Chris@0
|
1789 ->save(TRUE);
|
Chris@0
|
1790 }
|
Chris@0
|
1791
|
Chris@0
|
1792 /**
|
Chris@0
|
1793 * Install the Stable base theme if needed.
|
Chris@0
|
1794 */
|
Chris@0
|
1795 function system_update_8014() {
|
Chris@0
|
1796 $theme_handler = \Drupal::service('theme_handler');
|
Chris@0
|
1797 if ($theme_handler->themeExists('stable')) {
|
Chris@0
|
1798 return;
|
Chris@0
|
1799 }
|
Chris@0
|
1800 $theme_handler->refreshInfo();
|
Chris@0
|
1801 foreach ($theme_handler->listInfo() as $theme) {
|
Chris@0
|
1802 // We first check that a base theme is set because if it's set to false then
|
Chris@0
|
1803 // it's unset in \Drupal\Core\Extension\ThemeHandler::rebuildThemeData().
|
Chris@0
|
1804 if (isset($theme->info['base theme']) && $theme->info['base theme'] == 'stable') {
|
Chris@0
|
1805 $theme_handler->install(['stable']);
|
Chris@0
|
1806 return;
|
Chris@0
|
1807 }
|
Chris@0
|
1808 }
|
Chris@0
|
1809 }
|
Chris@0
|
1810
|
Chris@0
|
1811 /**
|
Chris@0
|
1812 * Fix configuration overrides to not override non existing keys.
|
Chris@0
|
1813 */
|
Chris@0
|
1814 function system_update_8200(&$sandbox) {
|
Chris@0
|
1815 $config_factory = \Drupal::configFactory();
|
Chris@0
|
1816 if (!array_key_exists('config_names', $sandbox)) {
|
Chris@0
|
1817 $sandbox['config_names'] = $config_factory->listAll();
|
Chris@0
|
1818 $sandbox['max'] = count($sandbox['config_names']);
|
Chris@0
|
1819 }
|
Chris@0
|
1820
|
Chris@0
|
1821 // Get a list of 50 to work on at a time.
|
Chris@0
|
1822 $config_names_to_process = array_slice($sandbox['config_names'], 0, 50);
|
Chris@0
|
1823 // Preload in a single query.
|
Chris@0
|
1824 $config_factory->loadMultiple($config_names_to_process);
|
Chris@0
|
1825 foreach ($config_names_to_process as $config_name) {
|
Chris@0
|
1826 $config_factory->getEditable($config_name)->save();
|
Chris@0
|
1827 }
|
Chris@0
|
1828
|
Chris@0
|
1829 // Update the list of names to process.
|
Chris@0
|
1830 $sandbox['config_names'] = array_diff($sandbox['config_names'], $config_names_to_process);
|
Chris@0
|
1831 $sandbox['#finished'] = empty($sandbox['config_names']) ? 1 : ($sandbox['max'] - count($sandbox['config_names'])) / $sandbox['max'];
|
Chris@0
|
1832 }
|
Chris@0
|
1833
|
Chris@0
|
1834 /**
|
Chris@0
|
1835 * Clear caches due to behavior change in DefaultPluginManager.
|
Chris@0
|
1836 */
|
Chris@0
|
1837 function system_update_8201() {
|
Chris@0
|
1838 // Empty update to cause a cache rebuild.
|
Chris@0
|
1839 }
|
Chris@0
|
1840
|
Chris@0
|
1841 /**
|
Chris@0
|
1842 * Clear caches due to behavior change in MachineName element.
|
Chris@0
|
1843 */
|
Chris@0
|
1844 function system_update_8202() {
|
Chris@0
|
1845 // Empty update to cause a cache rebuild.
|
Chris@0
|
1846 }
|
Chris@0
|
1847
|
Chris@0
|
1848 /**
|
Chris@0
|
1849 * Add detailed cron logging configuration.
|
Chris@0
|
1850 */
|
Chris@0
|
1851 function system_update_8300() {
|
Chris@0
|
1852 \Drupal::configFactory()->getEditable('system.cron')
|
Chris@0
|
1853 ->set('logging', 1)
|
Chris@0
|
1854 ->save(TRUE);
|
Chris@0
|
1855 }
|
Chris@0
|
1856
|
Chris@0
|
1857 /**
|
Chris@0
|
1858 * Add install profile to core.extension configuration.
|
Chris@0
|
1859 */
|
Chris@0
|
1860 function system_update_8301() {
|
Chris@0
|
1861 \Drupal::configFactory()->getEditable('core.extension')
|
Chris@0
|
1862 ->set('profile', \Drupal::installProfile())
|
Chris@0
|
1863 ->save();
|
Chris@0
|
1864 }
|
Chris@0
|
1865
|
Chris@0
|
1866 /**
|
Chris@0
|
1867 * Move revision metadata fields to the revision table.
|
Chris@0
|
1868 */
|
Chris@0
|
1869 function system_update_8400(&$sandbox) {
|
Chris@0
|
1870 // Due to the fields from RevisionLogEntityTrait not being explicitly
|
Chris@0
|
1871 // mentioned in the storage they might have been installed wrongly in the base
|
Chris@0
|
1872 // table for revisionable untranslatable entities and in the data and revision
|
Chris@0
|
1873 // data tables for revisionable and translatable entities.
|
Chris@0
|
1874 $entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
|
Chris@0
|
1875 $database = \Drupal::database();
|
Chris@0
|
1876 $database_schema = $database->schema();
|
Chris@0
|
1877
|
Chris@0
|
1878 if (!isset($sandbox['current'])) {
|
Chris@0
|
1879 // This must be the first run. Initialize the sandbox.
|
Chris@0
|
1880 $sandbox['current'] = 0;
|
Chris@0
|
1881
|
Chris@0
|
1882 $definitions = array_filter(\Drupal::entityTypeManager()->getDefinitions(), function (EntityTypeInterface $entity_type) use ($entity_definition_update_manager) {
|
Chris@0
|
1883 if ($entity_type = $entity_definition_update_manager->getEntityType($entity_type->id())) {
|
Chris@0
|
1884 return is_subclass_of($entity_type->getClass(), FieldableEntityInterface::class) && ($entity_type instanceof ContentEntityTypeInterface) && $entity_type->isRevisionable();
|
Chris@0
|
1885 }
|
Chris@0
|
1886 return FALSE;
|
Chris@0
|
1887 });
|
Chris@0
|
1888 $sandbox['entity_type_ids'] = array_keys($definitions);
|
Chris@0
|
1889 $sandbox['max'] = count($sandbox['entity_type_ids']);
|
Chris@0
|
1890 }
|
Chris@0
|
1891
|
Chris@0
|
1892 $current_entity_type_key = $sandbox['current'];
|
Chris@0
|
1893 for ($i = $current_entity_type_key; ($i < $current_entity_type_key + 1) && ($i < $sandbox['max']); $i++) {
|
Chris@0
|
1894 $entity_type_id = $sandbox['entity_type_ids'][$i];
|
Chris@0
|
1895 /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
|
Chris@0
|
1896 $entity_type = $entity_definition_update_manager->getEntityType($entity_type_id);
|
Chris@0
|
1897
|
Chris@0
|
1898 $base_fields = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions($entity_type_id);
|
Chris@0
|
1899 $revision_metadata_fields = $entity_type->getRevisionMetadataKeys();
|
Chris@0
|
1900 $fields_to_update = array_intersect_key($base_fields, array_flip($revision_metadata_fields));
|
Chris@0
|
1901
|
Chris@0
|
1902 if (!empty($fields_to_update)) {
|
Chris@0
|
1903 // Initialize the entity table names.
|
Chris@0
|
1904 // @see \Drupal\Core\Entity\Sql\SqlContentEntityStorage::initTableLayout()
|
Chris@0
|
1905 $base_table = $entity_type->getBaseTable() ?: $entity_type_id;
|
Chris@0
|
1906 $data_table = $entity_type->getDataTable() ?: $entity_type_id . '_field_data';
|
Chris@0
|
1907 $revision_table = $entity_type->getRevisionTable() ?: $entity_type_id . '_revision';
|
Chris@0
|
1908 $revision_data_table = $entity_type->getRevisionDataTable() ?: $entity_type_id . '_field_revision';
|
Chris@0
|
1909 $revision_field = $entity_type->getKey('revision');
|
Chris@0
|
1910
|
Chris@0
|
1911 // No data needs to be migrated if the entity type is not translatable.
|
Chris@0
|
1912 if ($entity_type->isTranslatable()) {
|
Chris@0
|
1913 if (!isset($sandbox[$entity_type_id])) {
|
Chris@0
|
1914 // This must be the first run for this entity type. Initialize the
|
Chris@0
|
1915 // sub-sandbox for it.
|
Chris@0
|
1916
|
Chris@0
|
1917 // Calculate the number of revisions to process.
|
Chris@0
|
1918 $count = \Drupal::entityQuery($entity_type_id)
|
Chris@0
|
1919 ->allRevisions()
|
Chris@0
|
1920 ->count()
|
Chris@0
|
1921 ->accessCheck(FALSE)
|
Chris@0
|
1922 ->execute();
|
Chris@0
|
1923
|
Chris@0
|
1924 $sandbox[$entity_type_id]['current'] = 0;
|
Chris@0
|
1925 $sandbox[$entity_type_id]['max'] = $count;
|
Chris@0
|
1926 }
|
Chris@0
|
1927 // Define the step size.
|
Chris@0
|
1928 $steps = Settings::get('entity_update_batch_size', 50);
|
Chris@0
|
1929
|
Chris@0
|
1930 // Collect the revision IDs to process.
|
Chris@0
|
1931 $revisions = \Drupal::entityQuery($entity_type_id)
|
Chris@0
|
1932 ->allRevisions()
|
Chris@0
|
1933 ->range($sandbox[$entity_type_id]['current'], $sandbox[$entity_type_id]['current'] + $steps)
|
Chris@0
|
1934 ->sort($revision_field, 'ASC')
|
Chris@0
|
1935 ->accessCheck(FALSE)
|
Chris@0
|
1936 ->execute();
|
Chris@0
|
1937 $revisions = array_keys($revisions);
|
Chris@0
|
1938
|
Chris@0
|
1939 foreach ($fields_to_update as $revision_metadata_field_name => $definition) {
|
Chris@0
|
1940 // If the revision metadata field is present in the data and the
|
Chris@0
|
1941 // revision data table, install its definition again with the updated
|
Chris@0
|
1942 // storage code in order for the field to be installed in the
|
Chris@0
|
1943 // revision table. Afterwards, copy over the field values and remove
|
Chris@0
|
1944 // the field from the data and the revision data tables.
|
Chris@0
|
1945 if ($database_schema->fieldExists($data_table, $revision_metadata_field_name) && $database_schema->fieldExists($revision_data_table, $revision_metadata_field_name)) {
|
Chris@0
|
1946 // Install the field in the revision table.
|
Chris@0
|
1947 if (!isset($sandbox[$entity_type_id]['storage_definition_installed'][$revision_metadata_field_name])) {
|
Chris@0
|
1948 $entity_definition_update_manager->installFieldStorageDefinition($revision_metadata_field_name, $entity_type_id, $entity_type->getProvider(), $definition);
|
Chris@0
|
1949 $sandbox[$entity_type_id]['storage_definition_installed'][$revision_metadata_field_name] = TRUE;
|
Chris@0
|
1950 }
|
Chris@0
|
1951
|
Chris@0
|
1952 // Apply the field value from the revision data table to the
|
Chris@0
|
1953 // revision table.
|
Chris@0
|
1954 foreach ($revisions as $rev_id) {
|
Chris@0
|
1955 $field_value = $database->select($revision_data_table, 't')
|
Chris@0
|
1956 ->fields('t', [$revision_metadata_field_name])
|
Chris@0
|
1957 ->condition($revision_field, $rev_id)
|
Chris@0
|
1958 ->execute()
|
Chris@0
|
1959 ->fetchField();
|
Chris@0
|
1960 $database->update($revision_table)
|
Chris@0
|
1961 ->condition($revision_field, $rev_id)
|
Chris@0
|
1962 ->fields([$revision_metadata_field_name => $field_value])
|
Chris@0
|
1963 ->execute();
|
Chris@0
|
1964 }
|
Chris@0
|
1965 }
|
Chris@0
|
1966 }
|
Chris@0
|
1967
|
Chris@0
|
1968 $sandbox[$entity_type_id]['current'] += count($revisions);
|
Chris@0
|
1969 $sandbox[$entity_type_id]['finished'] = ($sandbox[$entity_type_id]['current'] == $sandbox[$entity_type_id]['max']) || empty($revisions);
|
Chris@0
|
1970
|
Chris@0
|
1971 if ($sandbox[$entity_type_id]['finished']) {
|
Chris@0
|
1972 foreach ($fields_to_update as $revision_metadata_field_name => $definition) {
|
Chris@0
|
1973 // Drop the field from the data and revision data tables.
|
Chris@0
|
1974 $database_schema->dropField($data_table, $revision_metadata_field_name);
|
Chris@0
|
1975 $database_schema->dropField($revision_data_table, $revision_metadata_field_name);
|
Chris@0
|
1976 }
|
Chris@0
|
1977 $sandbox['current']++;
|
Chris@0
|
1978 }
|
Chris@0
|
1979 }
|
Chris@0
|
1980 else {
|
Chris@0
|
1981 foreach ($fields_to_update as $revision_metadata_field_name => $definition) {
|
Chris@0
|
1982 if ($database_schema->fieldExists($base_table, $revision_metadata_field_name)) {
|
Chris@0
|
1983 // Install the field in the revision table.
|
Chris@0
|
1984 $entity_definition_update_manager->installFieldStorageDefinition($revision_metadata_field_name, $entity_type_id, $entity_type->getProvider(), $definition);
|
Chris@0
|
1985 // Drop the field from the base table.
|
Chris@0
|
1986 $database_schema->dropField($base_table, $revision_metadata_field_name);
|
Chris@0
|
1987 }
|
Chris@0
|
1988 }
|
Chris@0
|
1989 $sandbox['current']++;
|
Chris@0
|
1990 }
|
Chris@0
|
1991 }
|
Chris@0
|
1992 else {
|
Chris@0
|
1993 $sandbox['current']++;
|
Chris@0
|
1994 }
|
Chris@0
|
1995
|
Chris@0
|
1996 }
|
Chris@0
|
1997
|
Chris@0
|
1998 $sandbox['#finished'] = $sandbox['current'] == $sandbox['max'];
|
Chris@0
|
1999 }
|
Chris@0
|
2000
|
Chris@0
|
2001 /**
|
Chris@0
|
2002 * Remove response.gzip (and response) from system module configuration.
|
Chris@0
|
2003 */
|
Chris@0
|
2004 function system_update_8401() {
|
Chris@0
|
2005 \Drupal::configFactory()->getEditable('system.performance')
|
Chris@0
|
2006 ->clear('response.gzip')
|
Chris@0
|
2007 ->clear('response')
|
Chris@0
|
2008 ->save();
|
Chris@0
|
2009 }
|
Chris@0
|
2010
|
Chris@0
|
2011 /**
|
Chris@0
|
2012 * Add the 'revision_translation_affected' field to all entity types.
|
Chris@0
|
2013 */
|
Chris@0
|
2014 function system_update_8402() {
|
Chris@0
|
2015 $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
|
Chris@0
|
2016
|
Chris@0
|
2017 // Clear the cached entity type definitions so we get the new
|
Chris@0
|
2018 // 'revision_translation_affected' entity key.
|
Chris@0
|
2019 \Drupal::entityTypeManager()->clearCachedDefinitions();
|
Chris@0
|
2020
|
Chris@0
|
2021 // Get a list of revisionable and translatable entity types.
|
Chris@0
|
2022 /** @var \Drupal\Core\Entity\ContentEntityTypeInterface[] $definitions */
|
Chris@0
|
2023 $definitions = array_filter(\Drupal::entityTypeManager()->getDefinitions(), function (EntityTypeInterface $entity_type) use ($definition_update_manager) {
|
Chris@0
|
2024 if ($entity_type = $definition_update_manager->getEntityType($entity_type->id())) {
|
Chris@0
|
2025 return $entity_type->isRevisionable() && $entity_type->isTranslatable();
|
Chris@0
|
2026 }
|
Chris@0
|
2027 return FALSE;
|
Chris@0
|
2028 });
|
Chris@0
|
2029
|
Chris@0
|
2030 foreach ($definitions as $entity_type_id => $entity_type) {
|
Chris@0
|
2031 $field_name = $entity_type->getKey('revision_translation_affected');
|
Chris@0
|
2032 // Install the 'revision_translation_affected' field if needed.
|
Chris@0
|
2033 if (!$definition_update_manager->getFieldStorageDefinition($field_name, $entity_type_id)) {
|
Chris@0
|
2034 $storage_definition = BaseFieldDefinition::create('boolean')
|
Chris@0
|
2035 ->setLabel(t('Revision translation affected'))
|
Chris@0
|
2036 ->setDescription(t('Indicates if the last edit of a translation belongs to current revision.'))
|
Chris@0
|
2037 ->setReadOnly(TRUE)
|
Chris@0
|
2038 ->setRevisionable(TRUE)
|
Chris@0
|
2039 ->setTranslatable(TRUE)
|
Chris@0
|
2040 // Mark all pre-existing revisions as affected in order to be consistent
|
Chris@0
|
2041 // with the previous API return value: if the field was not defined the
|
Chris@0
|
2042 // value returned was always TRUE.
|
Chris@0
|
2043 ->setInitialValue(TRUE);
|
Chris@0
|
2044
|
Chris@0
|
2045 $definition_update_manager
|
Chris@0
|
2046 ->installFieldStorageDefinition($field_name, $entity_type_id, $entity_type_id, $storage_definition);
|
Chris@0
|
2047 }
|
Chris@0
|
2048 }
|
Chris@0
|
2049 }
|
Chris@0
|
2050
|
Chris@0
|
2051 /**
|
Chris@0
|
2052 * Delete all cache_* tables. They are recreated on demand with the new schema.
|
Chris@0
|
2053 */
|
Chris@0
|
2054 function system_update_8403() {
|
Chris@0
|
2055 foreach (Cache::getBins() as $bin => $cache_backend) {
|
Chris@0
|
2056 // Try to delete the table regardless of which cache backend is handling it.
|
Chris@0
|
2057 // This is to ensure the new schema is used if the configuration for the
|
Chris@0
|
2058 // backend class is changed after the update hook runs.
|
Chris@0
|
2059 $table_name = "cache_$bin";
|
Chris@0
|
2060 $schema = Database::getConnection()->schema();
|
Chris@0
|
2061 if ($schema->tableExists($table_name)) {
|
Chris@0
|
2062 $schema->dropTable($table_name);
|
Chris@0
|
2063 }
|
Chris@0
|
2064 }
|
Chris@0
|
2065 }
|
Chris@14
|
2066
|
Chris@14
|
2067 /**
|
Chris@14
|
2068 * Add the 'revision_default' field to all relevant entity types.
|
Chris@14
|
2069 */
|
Chris@14
|
2070 function system_update_8501() {
|
Chris@14
|
2071 $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
|
Chris@14
|
2072
|
Chris@14
|
2073 // Clear the cached entity type definitions so we get the new
|
Chris@14
|
2074 // 'revision_default' revision metadata key.
|
Chris@14
|
2075 \Drupal::entityTypeManager()->clearCachedDefinitions();
|
Chris@14
|
2076
|
Chris@14
|
2077 // Get a list of revisionable entity types.
|
Chris@14
|
2078 /** @var \Drupal\Core\Entity\ContentEntityTypeInterface[] $definitions */
|
Chris@14
|
2079 $definitions = array_filter(\Drupal::entityTypeManager()->getDefinitions(), function (EntityTypeInterface $entity_type) use ($definition_update_manager) {
|
Chris@14
|
2080 if ($entity_type = $definition_update_manager->getEntityType($entity_type->id())) {
|
Chris@14
|
2081 return $entity_type->isRevisionable();
|
Chris@14
|
2082 }
|
Chris@14
|
2083 return FALSE;
|
Chris@14
|
2084 });
|
Chris@14
|
2085
|
Chris@14
|
2086 // Install the 'revision_default' field.
|
Chris@14
|
2087 foreach ($definitions as $entity_type_id => $entity_type) {
|
Chris@14
|
2088 $field_name = $entity_type->getRevisionMetadataKey('revision_default');
|
Chris@14
|
2089 // Install the 'revision_default' field if needed.
|
Chris@14
|
2090 if (!$definition_update_manager->getFieldStorageDefinition($field_name, $entity_type_id)) {
|
Chris@14
|
2091 // Make sure the new "revision_default" revision metadata key is available
|
Chris@14
|
2092 // also to code using the latest installed definition.
|
Chris@14
|
2093 $installed_entity_type = $definition_update_manager->getEntityType($entity_type_id);
|
Chris@14
|
2094 $revision_metadata_keys = $installed_entity_type->get('revision_metadata_keys');
|
Chris@14
|
2095
|
Chris@14
|
2096 if (!isset($revision_metadata_keys['revision_default'])) {
|
Chris@14
|
2097 // Update the property holding the required revision metadata keys,
|
Chris@14
|
2098 // which is used by the BC layer for retrieving the revision metadata
|
Chris@14
|
2099 // keys.
|
Chris@14
|
2100 // @see \Drupal\Core\Entity\ContentEntityType::getRevisionMetadataKeys().
|
Chris@14
|
2101 $required_revision_metadata_keys = $installed_entity_type->get('requiredRevisionMetadataKeys');
|
Chris@14
|
2102 $required_revision_metadata_keys['revision_default'] = $field_name;
|
Chris@14
|
2103 $installed_entity_type->set('requiredRevisionMetadataKeys', $required_revision_metadata_keys);
|
Chris@14
|
2104
|
Chris@14
|
2105 // Update the revision metadata keys to add the new required revision
|
Chris@14
|
2106 // metadata key "revision_default".
|
Chris@14
|
2107 $revision_metadata_keys['revision_default'] = $required_revision_metadata_keys['revision_default'];
|
Chris@14
|
2108 $installed_entity_type->set('revision_metadata_keys', $revision_metadata_keys);
|
Chris@14
|
2109
|
Chris@14
|
2110 $definition_update_manager->updateEntityType($installed_entity_type);
|
Chris@14
|
2111 }
|
Chris@14
|
2112
|
Chris@14
|
2113 $storage_definition = BaseFieldDefinition::create('boolean')
|
Chris@14
|
2114 ->setLabel(t('Default revision'))
|
Chris@14
|
2115 ->setDescription(t('A flag indicating whether this was a default revision when it was saved.'))
|
Chris@14
|
2116 ->setStorageRequired(TRUE)
|
Chris@14
|
2117 ->setTranslatable(FALSE)
|
Chris@14
|
2118 ->setRevisionable(TRUE)
|
Chris@14
|
2119 // We cannot tell whether existing revisions were default or not when
|
Chris@14
|
2120 // they were created, but since we did not support creating non-default
|
Chris@14
|
2121 // revisions in any core stable UI so far, we default to TRUE.
|
Chris@14
|
2122 ->setInitialValue(TRUE);
|
Chris@14
|
2123
|
Chris@14
|
2124 $definition_update_manager
|
Chris@14
|
2125 ->installFieldStorageDefinition($field_name, $entity_type_id, $entity_type_id, $storage_definition);
|
Chris@14
|
2126 }
|
Chris@14
|
2127 else {
|
Chris@14
|
2128 $variables = ['@entity_type_label' => $entity_type->getLabel()];
|
Chris@14
|
2129 if ($field_name === 'revision_default') {
|
Chris@14
|
2130 \Drupal::logger('system')->error('An existing "Default revision" field was found for the @entity_type_label entity type, but no "revision_default" revision metadata key was found in its definition.', $variables);
|
Chris@14
|
2131 }
|
Chris@14
|
2132 else {
|
Chris@14
|
2133 \Drupal::logger('system')->error('An existing "Default revision" field was found for the @entity_type_label entity type.', $variables);
|
Chris@14
|
2134 }
|
Chris@14
|
2135 }
|
Chris@14
|
2136 }
|
Chris@14
|
2137 }
|