diff --git a/core/includes/update.inc b/core/includes/update.inc index 5556690..e395fb6 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -239,7 +239,7 @@ function update_invoke_post_update($function, &$context) { $key_value_store = \Drupal::keyValue('update__post_update'); $executed_updates = $key_value_store->get('existing_updates', []); $executed_updates[] = $function; - $key_value_store->set($module, $executed_updates); + $key_value_store->set('existing_updates', $executed_updates); } // @TODO We may want to do different error handling for different // exception types, but for now we'll just log the exception and diff --git a/core/lib/Drupal/Core/Extension/module.api.php b/core/lib/Drupal/Core/Extension/module.api.php index b4b0cf8..8dc2e40 100644 --- a/core/lib/Drupal/Core/Extension/module.api.php +++ b/core/lib/Drupal/Core/Extension/module.api.php @@ -662,10 +662,12 @@ 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 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. * - * Note: In contrast to hook_update_N there is no enforced order, so you can + * Note: In contrast to hook_update_N() there is no enforced order, so you can * also use machine names for the name of those updates. * * @param array $sandbox @@ -678,8 +680,8 @@ function hook_update_N(&$sandbox) { * PDOException. * * @return string|null - * Optionally, update hooks may return a translated string that will be - * displayed to the user after the update has completed. If no message is + * Optionally, 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/modules/system/src/Controller/DbUpdateController.php b/core/modules/system/src/Controller/DbUpdateController.php index 043e61d..5aac272 100644 --- a/core/modules/system/src/Controller/DbUpdateController.php +++ b/core/modules/system/src/Controller/DbUpdateController.php @@ -259,6 +259,7 @@ protected function selection(Request $request) { $build['start']['system'] = array(); $starting_updates = array(); + $incompatible_updates_exist = FALSE; foreach (['update', 'post_update'] as $update_type) { switch ($update_type) { case 'update': @@ -269,7 +270,6 @@ protected function selection(Request $request) { $updates = $after_update_registry->getMissingUpdateList(); break; } - $incompatible_updates_exist = FALSE; foreach ($updates as $module => $update) { if (!isset($update['start'])) { $build['start'][$module] = array( @@ -601,7 +601,6 @@ protected function triggerBatch(Request $request) { } } - $batch['operations'] = $operations; $batch += array( 'title' => $this->t('Updating'), diff --git a/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php b/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php index 8be271f..2dd1fbd 100644 --- a/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php +++ b/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php @@ -20,18 +20,21 @@ class UpdatePostUpdateTest extends UpdatePathTestBase { protected function setDatabaseDumpFiles() { $this->databaseDumpFiles = [ __DIR__ . '/../../../tests/fixtures/update/drupal-8.bare.standard.php.gz', - __DIR__ . '/../../../tests/fixtures/update/drupal-8.update-test-post-update-enabled.php', + __DIR__ . '/../../../tests/fixtures/update/drupal-8.update-test-postupdate-enabled.php', ]; } - public function testUpdateAfter() { + /** + * Tests hook_post_update_NAME(). + */ + public function testPostUpdate() { $this->runUpdates(); $updates = [ - 'update_test_post_update_post_update_first', - 'update_test_post_update_post_update_second', - 'update_test_post_update_post_update_test1', - 'update_test_post_update_post_update_test0', + 'update_test_postupdate_post_update_first', + 'update_test_postupdate_post_update_second', + 'update_test_postupdate_post_update_test1', + 'update_test_postupdate_post_update_test0', ]; $this->assertIdentical($updates, \Drupal::state()->get('post_update_test_execution', [])); diff --git a/core/modules/system/tests/fixtures/update/drupal-8.update-test-post-update-enabled.php b/core/modules/system/tests/fixtures/update/drupal-8.update-test-postupdate-enabled.php similarity index 84% rename from core/modules/system/tests/fixtures/update/drupal-8.update-test-post-update-enabled.php rename to core/modules/system/tests/fixtures/update/drupal-8.update-test-postupdate-enabled.php index 3d5af10..1b2d186 100644 --- a/core/modules/system/tests/fixtures/update/drupal-8.update-test-post-update-enabled.php +++ b/core/modules/system/tests/fixtures/update/drupal-8.update-test-postupdate-enabled.php @@ -12,10 +12,10 @@ // Set the schema version. $connection->merge('key_value') ->condition('collection', 'system.schema') - ->condition('name', 'update_test_post_update') + ->condition('name', 'update_test_postupdate') ->fields([ 'collection' => 'system.schema', - 'name' => 'update_test_post_update', + 'name' => 'update_test_postupdate', 'value' => 'i:8000;', ]) ->execute(); @@ -28,7 +28,7 @@ ->execute() ->fetchField(); $extensions = unserialize($extensions); -$extensions['module']['update_test_post_update'] = 8000; +$extensions['module']['update_test_postupdate'] = 8000; $connection->update('config') ->fields([ 'data' => serialize($extensions), diff --git a/core/modules/system/tests/modules/update_test_post_update/update_test_post_update.info.yml b/core/modules/system/tests/modules/update_test_postupdate/update_test_postupdate.info.yml similarity index 100% rename from core/modules/system/tests/modules/update_test_post_update/update_test_post_update.info.yml rename to core/modules/system/tests/modules/update_test_postupdate/update_test_postupdate.info.yml diff --git a/core/modules/system/tests/modules/update_test_post_update/update_test_post_update.post_update.php b/core/modules/system/tests/modules/update_test_postupdate/update_test_postupdate.post_update.php similarity index 78% rename from core/modules/system/tests/modules/update_test_post_update/update_test_post_update.post_update.php rename to core/modules/system/tests/modules/update_test_postupdate/update_test_postupdate.post_update.php index 7ff4945..d67ea14 100644 --- a/core/modules/system/tests/modules/update_test_post_update/update_test_post_update.post_update.php +++ b/core/modules/system/tests/modules/update_test_postupdate/update_test_postupdate.post_update.php @@ -3,7 +3,7 @@ /** * First update. */ -function update_test_post_update_post_update_first() { +function update_test_postupdate_post_update_first() { $execution = \Drupal::state()->get('post_update_test_execution', []); $execution[] = __FUNCTION__; \Drupal::state()->set('post_update_test_execution', $execution); @@ -12,7 +12,7 @@ function update_test_post_update_post_update_first() { /** * Second update. */ -function update_test_post_update_post_update_second() { +function update_test_postupdate_post_update_second() { $execution = \Drupal::state()->get('post_update_test_execution', []); $execution[] = __FUNCTION__; \Drupal::state()->set('post_update_test_execution', $execution); @@ -21,7 +21,7 @@ function update_test_post_update_post_update_second() { /** * Test1 update. */ -function update_test_post_update_post_update_test1() { +function update_test_postupdate_post_update_test1() { $execution = \Drupal::state()->get('post_update_test_execution', []); $execution[] = __FUNCTION__; \Drupal::state()->set('post_update_test_execution', $execution); @@ -30,7 +30,7 @@ function update_test_post_update_post_update_test1() { /** * Test2 update. */ -function update_test_post_update_post_update_test0() { +function update_test_postupdate_post_update_test0() { $execution = \Drupal::state()->get('post_update_test_execution', []); $execution[] = __FUNCTION__; \Drupal::state()->set('post_update_test_execution', $execution); diff --git a/core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php b/core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php index e90acaa..e1d69c2 100644 --- a/core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php +++ b/core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php @@ -101,7 +101,7 @@ public function testGetMissingUpdateFunctionsWithNoExistingUpdates() { $this->setupBasicModules(); $key_value = $this->prophesize(KeyValueStoreInterface::class); - $key_value->get('core.update__post_update', [])->willReturn([]); + $key_value->get('existing_updates', [])->willReturn([]); $key_value = $key_value->reveal(); $update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [ @@ -123,7 +123,7 @@ public function testGetMissingUpdateFunctionsWithExistingUpdates() { $this->setupBasicModules(); $key_value = $this->prophesize(KeyValueStoreInterface::class); - $key_value->get('core.update__post_update', [])->willReturn(['module_a_post_update_a']); + $key_value->get('existing_updates', [])->willReturn(['module_a_post_update_a']); $key_value = $key_value->reveal(); $update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [ @@ -145,7 +145,7 @@ public function testGetMissingUpdateList() { $this->setupBasicModules(); $key_value = $this->prophesize(KeyValueStoreInterface::class); - $key_value->get('core.update__post_update', [])->willReturn([]); + $key_value->get('existing_updates', [])->willReturn([]); $key_value = $key_value->reveal(); $update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [ @@ -170,7 +170,7 @@ public function testGetMissingUpdateListWithExistingUpdates() { $this->setupBasicModules(); $key_value = $this->prophesize(KeyValueStoreInterface::class); - $key_value->get('core.update__post_update', [])->willReturn(['module_a_post_update_a']); + $key_value->get('existing_updates', [])->willReturn(['module_a_post_update_a']); $key_value = $key_value->reveal(); $update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [