diff --git a/core/includes/update.inc b/core/includes/update.inc index 85246c3..f7baaf5 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -243,9 +243,9 @@ function update_invoke_post_update($function, &$context) { \Drupal::service('update.post_update_registry')->registerInvokedUpdates([$function]); } - // @TODO We may want to do different error handling for different - // exception types, but for now we'll just log the exception and - // return the message for printing. + // @TODO We may want to do different error handling for different exception + // types, but for now we'll just log the exception and return the message + // for printing. catch (Exception $e) { watchdog_exception('update', $e); diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index 683450c..f939c03 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -452,11 +452,6 @@ 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)); - /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */ $post_update_registry = \Drupal::service('update.post_update_registry'); $post_update_registry->filterOutInvokedUpdatesByModule($module); diff --git a/core/lib/Drupal/Core/Extension/module.api.php b/core/lib/Drupal/Core/Extension/module.api.php index 41393de..ce72ded 100644 --- a/core/lib/Drupal/Core/Extension/module.api.php +++ b/core/lib/Drupal/Core/Extension/module.api.php @@ -684,9 +684,9 @@ function hook_update_N(&$sandbox) { * PDOException. * * @return string|null - * Optionally, hook_post_update_NAME() hooks may return a translated string that will - * be displayed to the user after the update has completed. If no message is - * returned, no message will be presented to the user. + * Optionally, hook_post_update_NAME() hooks may return a translated string + * that will be displayed to the user after the update has completed. If no + * message is returned, no message will be presented to the user. * * @ingroup update_api * diff --git a/core/lib/Drupal/Core/Update/UpdateRegistry.php b/core/lib/Drupal/Core/Update/UpdateRegistry.php index 93cc694..0190e04 100644 --- a/core/lib/Drupal/Core/Update/UpdateRegistry.php +++ b/core/lib/Drupal/Core/Update/UpdateRegistry.php @@ -106,7 +106,9 @@ protected function getAvailableUpdateFunctions() { // If this function is a module update function, add it to the list of // module updates. if (preg_match($regexp, $function, $matches)) { - $updates[] = $matches['module'] . '_' . $this->updateType . '_' . $matches['name']; + if (in_array($matches['module'], $this->enabledModules)) { + $updates[] = $matches['module'] . '_' . $this->updateType . '_' . $matches['name']; + } } } diff --git a/core/modules/system/src/Controller/DbUpdateController.php b/core/modules/system/src/Controller/DbUpdateController.php index 8baa784..61e89a2 100644 --- a/core/modules/system/src/Controller/DbUpdateController.php +++ b/core/modules/system/src/Controller/DbUpdateController.php @@ -472,7 +472,7 @@ protected function results(Request $request) { $title = $this->t('Update #@count', ['@count' => $name]); } else { - $title = $this->t('Update @name', ['@name' => $name]); + $title = $this->t('Update @name', ['@name' => trim($name, '_')]); } $info_messages[] = array( '#theme' => 'item_list', diff --git a/core/modules/system/src/Tests/Module/InstallUninstallTest.php b/core/modules/system/src/Tests/Module/InstallUninstallTest.php index 3573247..24549b5 100644 --- a/core/modules/system/src/Tests/Module/InstallUninstallTest.php +++ b/core/modules/system/src/Tests/Module/InstallUninstallTest.php @@ -108,7 +108,7 @@ public function testInstallUninstall() { $this->assertModuleTablesExist($module_to_install); $this->assertModuleConfig($module_to_install); $this->assertLogMessage('system', "%module module installed.", array('%module' => $module_to_install), RfcLogLevel::INFO); - $this->assertModuleUpdates($module_to_install); + $this->assertInstallModuleUpdates($module_to_install); } // Uninstall the original module, and check appropriate @@ -196,16 +196,24 @@ protected function assertSuccessfulUninstall($module, $package = 'Core') { } /** - * Ensures the module post update functions after install. + * Asserts the module post update functions after install. * * @param string $module * The module that got installed. */ - protected function assertModuleUpdates($module) { + protected function assertInstallModuleUpdates($module) { /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */ $post_update_registry = \Drupal::service('update.post_update_registry'); $all_update_functions = $post_update_registry->getPendingUpdateFunctions(); - $this->assertTrue(empty($all_update_functions[$module]), 'Ensures that no pending post update functions are available.'); + $empty_result = TRUE; + foreach ($all_update_functions as $function) { + list($function_module, ) = explode('_post_update_', $function); + if ($module === $function_module) { + $empty_result = FALSE; + break; + } + } + $this->assertTrue($empty_result, 'Ensures that no pending post update functions are available.'); $existing_updates = \Drupal::keyValue('post_update')->get('existing_updates', []); switch ($module) { @@ -219,7 +227,7 @@ protected function assertModuleUpdates($module) { } /** - * Ensures the module post update functions after uninstall. + * Asserts the module post update functions after uninstall. * * @param string $module * The module that got installed. @@ -231,10 +239,10 @@ protected function assertUninstallModuleUpdates($module) { switch ($module) { case 'block': - $this->assertFalse(array_intersect(['block_post_update_disable_blocks_with_missing_contexts'], $all_update_functions), 'Ensures that no pending post update functions are available.'); + $this->assertFalse(array_intersect(['block_post_update_disable_blocks_with_missing_contexts'], $all_update_functions), 'Asserts that no pending post update functions are available.'); $existing_updates = \Drupal::keyValue('post_update')->get('existing_updates', []); - $this->assertFalse(array_intersect(['block_post_update_disable_blocks_with_missing_contexts'], $existing_updates), 'Ensures that no pending post update functions are available.'); + $this->assertFalse(array_intersect(['block_post_update_disable_blocks_with_missing_contexts'], $existing_updates), 'Asserts that no post update functions are stored in keyvalue store.'); break; } } diff --git a/core/modules/system/src/Tests/System/StatusTest.php b/core/modules/system/src/Tests/System/StatusTest.php index 3f4f83f..5bb9578 100644 --- a/core/modules/system/src/Tests/System/StatusTest.php +++ b/core/modules/system/src/Tests/System/StatusTest.php @@ -66,7 +66,7 @@ public function testStatusPage() { $this->assertNoText(t('Out of date')); // Set the schema version of update_test_postupdate to a lower version, so - // update_test_postupdate_update_8001() needs to be exeucted. + // update_test_postupdate_update_8001() needs to be executed. drupal_set_installed_schema_version('update_test_postupdate', 8000); $this->drupalGet('admin/reports/status'); $this->assertText(t('Out of date')); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 9182301..d4eb139 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -610,14 +610,15 @@ function system_requirements($phase) { } } } - - /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */ - $post_update_registry = \Drupal::service('update.post_update_registry'); - $missing_post_update_functions = $post_update_registry->getPendingUpdateFunctions(); - if (!empty($missing_post_update_functions)) { - $requirements['update']['severity'] = REQUIREMENT_ERROR; - $requirements['update']['value'] = t('Out of date'); - $requirements['update']['description'] = t('Some modules have database schema updates to install. You should run the database update script immediately.', array('@update' => \Drupal::url('system.db_update'))); + if (empty($requirements['update']['severity'])) { + /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */ + $post_update_registry = \Drupal::service('update.post_update_registry'); + $missing_post_update_functions = $post_update_registry->getPendingUpdateFunctions(); + if (!empty($missing_post_update_functions)) { + $requirements['update']['severity'] = REQUIREMENT_ERROR; + $requirements['update']['value'] = t('Out of date'); + $requirements['update']['description'] = t('Some modules have database schema updates to install. You should run the database update script immediately.', array('@update' => \Drupal::url('system.db_update'))); + } } // Verify that no entity updates are pending after running every DB update. diff --git a/core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php b/core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php index c8b3f91..5de6780 100644 --- a/core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php +++ b/core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php @@ -17,7 +17,7 @@ * @coversDefaultClass \Drupal\Core\Update\UpdateRegistry * @group Update * - * Note we load code, so we shoudl better run in isolation. + * Note we load code, so we should better run in isolation. * * @runTestsInSeparateProcesses */ @@ -120,6 +120,31 @@ public function testGetPendingUpdateFunctionsNoExistingUpdates() { /** * @covers ::getPendingUpdateFunctions */ + public function testGetPendingUpdateFunctionsWithLoadedModulesButNotEnabled() { + $this->setupBasicModules(); + + $key_value = $this->prophesize(KeyValueStoreInterface::class); + $key_value->get('existing_updates', [])->willReturn([]); + $key_value = $key_value->reveal(); + + // Preload modules to ensure that ::getAvailableUpdateFunctions filters out + // not enabled modules. + include_once 'vfs://drupal/sites/default/modules/module_a/module_a.post_update.php'; + include_once 'vfs://drupal/sites/default/modules/module_b/module_b.post_update.php'; + + $update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [ + 'module_a', + ], $key_value, FALSE); + + $this->assertEquals([ + 'module_a_post_update_a', + 'module_a_post_update_b', + ], $update_registry->getPendingUpdateFunctions()); + } + + /** + * @covers ::getPendingUpdateFunctions + */ public function testGetPendingUpdateFunctionsExistingUpdates() { $this->setupBasicModules();