annotate core/modules/system/system.install @ 2:92f882872392

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