diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index a8124d5..c97de42 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -13,6 +13,7 @@ use Drupal\Core\DrupalKernelInterface; use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Entity\FieldableEntityInterface; +use Drupal\Core\Update\UpdateRegistry; /** * Default implementation of the module installer. @@ -260,6 +261,12 @@ public function install(array $module_list, $enable_dependencies = TRUE) { } drupal_set_installed_schema_version($module, $version); + // Ensure that all post_update functions are registered already. + $post_update_key_value = \Drupal::keyValue('post_update'); + $post_update_registry = new UpdateRegistry($this->root, \Drupal::service('site.path'), array_keys($this->moduleHandler->getModuleList()), $post_update_key_value); + $module_post_update_functions = $post_update_registry->getModuleUpdateFunctions($module); + $post_update_key_value->set('existing_updates', array_merge($post_update_key_value->get('existing_updates', []), $module_post_update_functions)); + // Record the fact that it was installed. $modules_installed[] = $module; @@ -445,6 +452,11 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { $schema_store = \Drupal::keyValue('system.schema'); $schema_store->delete($module); + + $post_update_key_value = \Drupal::keyValue('post_update'); + $post_update_registry = new UpdateRegistry($this->root, \Drupal::service('site.path'), array_keys($this->moduleHandler->getModuleList()), $post_update_key_value); + $module_post_update_functions = $post_update_registry->getModuleUpdateFunctions($module); + $post_update_key_value->set('existing_updates', array_diff($post_update_key_value->get('existing_updates', []), $module_post_update_functions)); } \Drupal::service('router.builder')->setRebuildNeeded(); drupal_get_installed_schema_version(NULL, TRUE); diff --git a/core/lib/Drupal/Core/Update/UpdateRegistry.php b/core/lib/Drupal/Core/Update/UpdateRegistry.php index 8d7be81..df662f2 100644 --- a/core/lib/Drupal/Core/Update/UpdateRegistry.php +++ b/core/lib/Drupal/Core/Update/UpdateRegistry.php @@ -93,14 +93,7 @@ public function getPendingUpdateFunctions() { // bootstrap factory) and b) the path to the modules, we use the extension // discovery for that. - // Scan the module list. - $extension_discovery = new ExtensionDiscovery($this->root, FALSE, [], $this->sitePath); - $module_extensions = $extension_discovery->scan('module'); - - $profile_extensions = $extension_discovery->scan('profile'); - $extensions = array_merge($module_extensions, $profile_extensions); - - $this->loadUpdateFiles($extensions); + $this->scanExtensionsAndLoadUpdateFiles(); // First figure out which hook_{$this->updateName}_NAME got executed already. $existing_update_functions = $this->keyValue->get('existing_updates', []); @@ -172,4 +165,36 @@ public function getPendingUpdateInformation() { return $ret; } + /** + * Returns all available updates for a given module. + * + * @param string $module_name + * The module name. + * + * @return callable[] + */ + public function getModuleUpdateFunctions($module_name) { + $this->scanExtensionsAndLoadUpdateFiles(); + $all_functions = $this->getAvailableUpdateFunctions(); + + return array_filter($all_functions, function($function_name) use ($module_name) { + list($function_module_name, ) = explode("_{$this->updateName}_", $function_name); + return $function_module_name === $module_name; + }); + } + + /** + * Scans all module + profile extensions and load the update files. + */ + protected function scanExtensionsAndLoadUpdateFiles() { + // Scan the module list. + $extension_discovery = new ExtensionDiscovery($this->root, FALSE, [], $this->sitePath); + $module_extensions = $extension_discovery->scan('module'); + + $profile_extensions = $extension_discovery->scan('profile'); + $extensions = array_merge($module_extensions, $profile_extensions); + + $this->loadUpdateFiles($extensions); + } + } diff --git a/core/modules/block/block.post_update.php b/core/modules/block/block.post_update.php index e4079eb..4a16ca1 100644 --- a/core/modules/block/block.post_update.php +++ b/core/modules/block/block.post_update.php @@ -19,8 +19,8 @@ function block_post_update_disable_blocks_with_missing_contexts() { $block_ids = array_keys($block_update_8001); $block_storage = \Drupal::entityManager()->getStorage('block'); $blocks = $block_storage->loadMultiple($block_ids); + /** @var $blocks \Drupal\block\BlockInterface[] */ foreach ($blocks as $block) { - /** @var $block \Drupal\block\BlockInterface */ // This block will have an invalid context mapping service and must be // disabled in order to prevent information disclosure. @@ -46,11 +46,12 @@ function block_post_update_disable_blocks_with_missing_contexts() { $message .= '