annotate core/modules/system/system.install @ 19:fa3358dc1485 tip

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