Commit 305d1207 authored by catch's avatar catch
Browse files

Issue #3259188 by alexpott, dww, chr.fritsch: Extend post update system to...

Issue #3259188 by alexpott, dww, chr.fritsch: Extend post update system to provide themes a way to install newly-required dependencies

(cherry picked from commit 5f5c8114)
parent 310943d1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1757,6 +1757,8 @@ services:
  update.post_update_registry:
    class: Drupal\Core\Update\UpdateRegistry
    factory: ['@update.post_update_registry_factory', create]
    tags:
      - { name: event_subscriber }
  update.post_update_registry_factory:
    class: Drupal\Core\Update\UpdateRegistryFactory
    parent: container.trait
+8 −6
Original line number Diff line number Diff line
@@ -286,8 +286,10 @@ function update_invoke_post_update($function, &$context) {
    return;
  }

  [$module, $name] = explode('_post_update_', $function, 2);
  \Drupal::moduleHandler()->loadInclude($module, 'php', $module . '.post_update');
  // Ensure extension post update code is loaded.
  [$extension, $name] = explode('_post_update_', $function, 2);
  \Drupal::service('update.post_update_registry')->getUpdateFunctions($extension);

  if (function_exists($function)) {
    try {
      $ret['results']['query'] = $function($context['sandbox']);
@@ -317,17 +319,17 @@ function update_invoke_post_update($function, &$context) {
    $context['finished'] = $context['sandbox']['#finished'];
    unset($context['sandbox']['#finished']);
  }
  if (!isset($context['results'][$module][$name])) {
    $context['results'][$module][$name] = [];
  if (!isset($context['results'][$extension][$name])) {
    $context['results'][$extension][$name] = [];
  }
  $context['results'][$module][$name] = array_merge($context['results'][$module][$name], $ret);
  $context['results'][$extension][$name] = array_merge($context['results'][$extension][$name], $ret);

  if (!empty($ret['#abort'])) {
    // Record this function in the list of updates that were aborted.
    $context['results']['#abort'][] = $function;
  }

  $context['message'] = t('Post updating @module', ['@module' => $module]);
  $context['message'] = t('Post updating @extension', ['@extension' => $extension]);
}

/**
+0 −12
Original line number Diff line number Diff line
@@ -334,14 +334,6 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
        }
        $this->updateRegistry->setInstalledVersion($module, $version);

        // Ensure that all post_update functions are registered already. This
        // should include existing post-updates, as well as any specified as
        // having been previously removed, to ensure that newly installed and
        // updated sites have the same entries in the registry.
        /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */
        $post_update_registry = \Drupal::service('update.post_update_registry');
        $post_update_registry->registerInvokedUpdates(array_merge($post_update_registry->getModuleUpdateFunctions($module), array_keys($post_update_registry->getRemovedPostUpdates($module))));

        // Record the fact that it was installed.
        $modules_installed[] = $module;

@@ -546,10 +538,6 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
      /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */
      $update_registry = \Drupal::service('update.update_hook_registry');
      $update_registry->deleteInstalledVersion($module);

      /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */
      $post_update_registry = \Drupal::service('update.post_update_registry');
      $post_update_registry->filterOutInvokedUpdatesByModule($module);
    }
    // Rebuild routes after installing module. This is done here on top of
    // \Drupal\Core\Routing\RouteBuilder::destruct to not run into errors on
+0 −2
Original line number Diff line number Diff line
@@ -236,7 +236,6 @@ public function install(array $theme_list, $install_dependencies = TRUE) {
      }

      $themes_installed[] = $key;

      // Record the fact that it was installed.
      $this->logger->info('%theme theme installed.', ['%theme' => $key]);
    }
@@ -289,7 +288,6 @@ public function uninstall(array $theme_list) {

      // Remove all configuration belonging to the theme.
      $this->configManager->uninstall('theme', $key);

    }
    // Don't check schema when uninstalling a theme since we are only clearing
    // keys.
+2 −1
Original line number Diff line number Diff line
@@ -698,7 +698,8 @@ function hook_update_N(&$sandbox) {
/**
 * Executes an update which is intended to update data, like entities.
 *
 * These implementations have to be placed in a MODULE.post_update.php file.
 * These implementations have to be placed in a MODULE.post_update.php file or
 * a THEME.post_update.php file.
 *
 * These updates are executed after all hook_update_N() implementations. At this
 * stage Drupal is already fully repaired so you can use any API as you wish.
Loading