diff core/modules/system/system.install @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children 12f9dff5fda9
line wrap: on
line diff
--- a/core/modules/system/system.install	Thu Feb 28 11:14:44 2019 +0000
+++ b/core/modules/system/system.install	Thu Feb 28 13:11:55 2019 +0000
@@ -18,6 +18,7 @@
 use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Entity\FieldableEntityInterface;
 use Drupal\Core\DrupalKernel;
+use Drupal\Core\Extension\Extension;
 use Drupal\Core\Field\BaseFieldDefinition;
 use Drupal\Core\Site\Settings;
 use Drupal\Core\StreamWrapper\PrivateStream;
@@ -51,10 +52,10 @@
         'value' => t('%profile_name (%profile-%version)', [
           '%profile_name' => $info['name'],
           '%profile' => $profile,
-          '%version' => $info['version']
+          '%version' => $info['version'],
         ]),
         'severity' => REQUIREMENT_INFO,
-        'weight' => -9
+        'weight' => -9,
       ];
     }
 
@@ -77,14 +78,15 @@
   }
 
   // Web server information.
-  $software = \Drupal::request()->server->get('SERVER_SOFTWARE');
+  $request_object = \Drupal::request();
+  $software = $request_object->server->get('SERVER_SOFTWARE');
   $requirements['webserver'] = [
     'title' => t('Web server'),
     'value' => $software,
   ];
 
   // Tests clean URL support.
-  if ($phase == 'install' && $install_state['interactive'] && !isset($_GET['rewrite']) && strpos($software, 'Apache') !== FALSE) {
+  if ($phase == 'install' && $install_state['interactive'] && !$request_object->query->has('rewrite') && strpos($software, 'Apache') !== FALSE) {
     // If the Apache rewrite module is not enabled, Apache version must be >=
     // 2.2.16 because of the FallbackResource directive in the root .htaccess
     // file. Since the Apache version reported by the server is dependent on the
@@ -435,12 +437,13 @@
     // directory. This allows additional files in the site directory to be
     // updated when they are managed in a version control system.
     if (Settings::get('skip_permissions_hardening')) {
-      $conf_errors[] = t('Protection disabled');
+      $error_value = t('Protection disabled');
       // If permissions hardening is disabled, then only show a warning for a
       // writable file, as a reminder, rather than an error.
       $file_protection_severity = REQUIREMENT_WARNING;
     }
     else {
+      $error_value = t('Not protected');
       // In normal operation, writable files or directories are an error.
       $file_protection_severity = REQUIREMENT_ERROR;
       if (!drupal_verify_install_file($site_path, FILE_NOT_WRITABLE, 'dir')) {
@@ -449,7 +452,7 @@
     }
     foreach (['settings.php', 'settings.local.php', 'services.yml'] as $conf_file) {
       $full_path = $site_path . '/' . $conf_file;
-      if (file_exists($full_path) && (Settings::get('skip_permissions_hardening') || !drupal_verify_install_file($full_path, FILE_EXIST | FILE_READABLE | FILE_NOT_WRITABLE))) {
+      if (file_exists($full_path) && !drupal_verify_install_file($full_path, FILE_EXIST | FILE_READABLE | FILE_NOT_WRITABLE, 'file', !Settings::get('skip_permissions_hardening'))) {
         $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]);
       }
     }
@@ -471,7 +474,7 @@
         ];
       }
       $requirements['configuration_files'] = [
-        'value' => t('Not protected'),
+        'value' => $error_value,
         'severity' => $file_protection_severity,
         'description' => $description,
       ];
@@ -1000,6 +1003,34 @@
     ];
   }
 
+  // During installs from configuration don't support install profiles that
+  // implement hook_install.
+  if ($phase == 'install' && !empty($install_state['config_install_path'])) {
+    $install_hook = $install_state['parameters']['profile'] . '_install';
+    if (function_exists($install_hook)) {
+      $requirements['config_install'] = [
+        'title' => t('Configuration install'),
+        'value' => $install_state['parameters']['profile'],
+        'description' => t('The selected profile has a hook_install() implementation and therefore can not be installed from configuration.'),
+        'severity' => REQUIREMENT_ERROR,
+      ];
+    }
+  }
+
+  if ($phase === 'runtime') {
+    $settings = Settings::getAll();
+    if (array_key_exists('install_profile', $settings)) {
+      // The following message is only informational because not all site owners
+      // have access to edit their settings.php as it may be controlled by their
+      // hosting provider.
+      $requirements['install_profile_in_settings'] = [
+        'title' => t('Install profile in settings'),
+        'value' => t("Drupal 8 no longer uses the \$settings['install_profile'] value in settings.php and it can be removed."),
+        'severity' => REQUIREMENT_INFO,
+      ];
+    }
+  }
+
   return $requirements;
 }
 
@@ -1836,6 +1867,10 @@
  */
 function system_update_8201() {
   // Empty update to cause a cache rebuild.
+
+  // Use hook_post_update_NAME() instead to clear the cache.
+  // The use of hook_update_N() to clear the cache has been deprecated
+  // see https://www.drupal.org/node/2960601 for more details.
 }
 
 /**
@@ -1843,6 +1878,10 @@
  */
 function system_update_8202() {
   // Empty update to cause a cache rebuild.
+
+  // Use hook_post_update_NAME() instead to clear the cache.The use
+  // of hook_update_N to clear the cache has been deprecated see
+  // https://www.drupal.org/node/2960601 for more details.
 }
 
 /**
@@ -2135,3 +2174,67 @@
     }
   }
 }
+
+/**
+* Fix missing install profile after updating to Drupal 8.6.9 with Drush 8.
+*/
+function system_update_8601() {
+  $extension_config = \Drupal::configFactory()->getEditable('core.extension');
+  $install_profile = $extension_config->get('profile');
+  if (!$install_profile) {
+    // There's no install profile configured.
+    return;
+  }
+  $modules = $extension_config->get('module');
+  if (isset($modules[$install_profile])) {
+    // The install profile is already in the installed module list.
+    return;
+  }
+
+  // Ensure the install profile is available.
+  if (!\Drupal::service('extension.list.module')->exists($install_profile)) {
+    return t('The %install_profile install profile configured in core.extension is not available.', ['%install_profile' => $install_profile]);
+  }
+
+  // Add the install profile to the list of enabled modules.
+  $modules[$install_profile] = 1000;
+  $modules = module_config_sort($modules);
+  $extension_config
+    ->set('module', $modules)
+    ->save(TRUE);
+
+  // Build a module list from the updated extension configuration.
+  $current_module_filenames = \Drupal::moduleHandler()->getModuleList();
+  $current_modules = array_fill_keys(array_keys($current_module_filenames), 0);
+  $current_modules = module_config_sort(array_merge($current_modules, $extension_config->get('module')));
+  $module_filenames = [];
+  foreach ($current_modules as $name => $weight) {
+    if (isset($current_module_filenames[$name])) {
+      $module_filenames[$name] = $current_module_filenames[$name];
+    }
+    else {
+      $module_path = \Drupal::service('extension.list.module')->getPath($name);
+      $pathname = "$module_path/$name.info.yml";
+      $filename = file_exists($module_path . "/$name.module") ? "$name.module" : NULL;
+      $module_filenames[$name] = new Extension(\Drupal::root(), 'module', $pathname, $filename);
+    }
+  }
+
+  // Update the module handler list to contain the missing install profile.
+  \Drupal::moduleHandler()->setModuleList($module_filenames);
+  \Drupal::moduleHandler()->load($install_profile);
+
+  // Clear the static cache of the "extension.list.module" service to pick
+  // up the new install profile correctly.
+  \Drupal::service('extension.list.profile')->reset();
+
+  // Clear the static cache of the "extension.list.module" service to pick
+  // up the new module, since it merges the installation status of modules
+  // into its statically cached list.
+  \Drupal::service('extension.list.module')->reset();
+
+  // Update the kernel to include the missing profile.
+  \Drupal::service('kernel')->updateModules($module_filenames, $module_filenames);
+
+  return t('The %install_profile install profile has been added to the installed module list.', ['%install_profile' => $install_profile]);
+}