@@ -18,6 +18,7 @@ use Drupal\Core\Entity\ContentEntityTypeInterface;
1818use Drupal\Core\Entity\EntityTypeInterface;
1919use Drupal\Core\Entity\FieldableEntityInterface;
2020use Drupal\Core\DrupalKernel;
21+ use Drupal\Core\Extension\Extension;
2122use Drupal\Core\Field\BaseFieldDefinition;
2223use Drupal\Core\Site\Settings;
2324use Drupal\Core\StreamWrapper\PrivateStream;
@@ -2173,3 +2174,67 @@ function system_update_8501() {
21732174 }
21742175 }
21752176}
2177+
2178+ /**
2179+ * Fix missing install profile after updating to Drupal 8.6.9 with Drush 8.
2180+ */
2181+ function system_update_8601() {
2182+ $extension_config = \Drupal::configFactory()->getEditable('core.extension');
2183+ $install_profile = $extension_config->get('profile');
2184+ if (!$install_profile) {
2185+ // There's no install profile configured.
2186+ return;
2187+ }
2188+ $modules = $extension_config->get('module');
2189+ if (isset($modules[$install_profile])) {
2190+ // The install profile is already in the installed module list.
2191+ return;
2192+ }
2193+
2194+ // Ensure the install profile is available.
2195+ if (!\Drupal::service('extension.list.module')->exists($install_profile)) {
2196+ return t('The %install_profile install profile configured in core.extension is not available.', ['%install_profile' => $install_profile]);
2197+ }
2198+
2199+ // Add the install profile to the list of enabled modules.
2200+ $modules[$install_profile] = 1000;
2201+ $modules = module_config_sort($modules);
2202+ $extension_config
2203+ ->set('module', $modules)
2204+ ->save(TRUE);
2205+
2206+ // Build a module list from the updated extension configuration.
2207+ $current_module_filenames = \Drupal::moduleHandler()->getModuleList();
2208+ $current_modules = array_fill_keys(array_keys($current_module_filenames), 0);
2209+ $current_modules = module_config_sort(array_merge($current_modules, $extension_config->get('module')));
2210+ $module_filenames = [];
2211+ foreach ($current_modules as $name => $weight) {
2212+ if (isset($current_module_filenames[$name])) {
2213+ $module_filenames[$name] = $current_module_filenames[$name];
2214+ }
2215+ else {
2216+ $module_path = \Drupal::service('extension.list.module')->getPath($name);
2217+ $pathname = "$module_path/$name.info.yml";
2218+ $filename = file_exists($module_path . "/$name.module") ? "$name.module" : NULL;
2219+ $module_filenames[$name] = new Extension(\Drupal::root(), 'module', $pathname, $filename);
2220+ }
2221+ }
2222+
2223+ // Update the module handler list to contain the missing install profile.
2224+ \Drupal::moduleHandler()->setModuleList($module_filenames);
2225+ \Drupal::moduleHandler()->load($install_profile);
2226+
2227+ // Clear the static cache of the "extension.list.module" service to pick
2228+ // up the new install profile correctly.
2229+ \Drupal::service('extension.list.profile')->reset();
2230+
2231+ // Clear the static cache of the "extension.list.module" service to pick
2232+ // up the new module, since it merges the installation status of modules
2233+ // into its statically cached list.
2234+ \Drupal::service('extension.list.module')->reset();
2235+
2236+ // Update the kernel to include the missing profile.
2237+ \Drupal::service('kernel')->updateModules($module_filenames, $module_filenames);
2238+
2239+ return t('The %install_profile install profile has been added to the installed module list.', ['%install_profile' => $install_profile]);
2240+ }
0 commit comments