diff --git a/core/includes/update.inc b/core/includes/update.inc index f0020ee..67af504 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -219,26 +219,26 @@ function update_do_one($module, $number, $dependency_map, &$context) { } /** - * Executes a single hook_update_after_$name(). + * Executes a single hook_post_update_$name(). * * @param string $function * The function name, that should be executed. * @param array $context * The batch context array. */ -function update_after_do_one($function, &$context) { +function update_post_update_do_one($function, &$context) { $ret = []; - list($module, ) = explode('_update_after_', $function); - module_load_include('inc', $module, $module . '.update_after'); + list($module, ) = explode('_post_update_', $function); + module_load_include('php', $module, $module . '.post_update'); if (function_exists($function)) { try { $ret['results']['query'] = $function($context['sandbox']); $ret['results']['success'] = TRUE; - $key_value_store = \Drupal::keyValue('update_after'); - $executed_updates = $key_value_store->get('core.update__update_after', []); + $key_value_store = \Drupal::keyValue('update_test_post_update'); + $executed_updates = $key_value_store->get('core.update__post_update', []); $executed_updates[] = $function; - $key_value_store->set('core.update__update_after', $executed_updates); + $key_value_store->set('core.update__post_update', $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 6bc62d1..264dc4c 100644 --- a/core/lib/Drupal/Core/Extension/module.api.php +++ b/core/lib/Drupal/Core/Extension/module.api.php @@ -686,7 +686,7 @@ function hook_update_N(&$sandbox) { * * @see hook_update_N */ -function hook_update_after_X(&$sandbox) { +function hook_post_update_X(&$sandbox) { $node = \Drupal\node\Entity\Node::load(123); $node->setTitle('foo'); $node->save(); diff --git a/core/lib/Drupal/Core/Update/UpdateRegistry.php b/core/lib/Drupal/Core/Update/UpdateRegistry.php index 58ec918..b7d3b67 100644 --- a/core/lib/Drupal/Core/Update/UpdateRegistry.php +++ b/core/lib/Drupal/Core/Update/UpdateRegistry.php @@ -12,14 +12,14 @@ use Drupal\Core\KeyValueStore\KeyValueStoreInterface; /** - * Provides all and missing hook_update_$updateName_X implementations. + * Provides all and missing hook_$updateName_X implementations. * * It therefore scans for functions in $module.$updateName.inc named like - * $module_update_$updateName_X with X being a machine name. + * $module_$updateName_X with X being a machine name. */ class UpdateRegistry { - protected $updateName = 'update_after'; + protected $updateName = 'post_update'; /** * The app root. @@ -126,7 +126,7 @@ protected function loadUpdateFiles(array $module_extensions) { * @param \Drupal\Core\Extension\Extension $module */ protected function loadUpdateFile(Extension $module) { - $filename = $this->root . '/' . $module->getPath() . '/' . $module->getName() . ".{$this->updateName}.inc"; + $filename = $this->root . '/' . $module->getPath() . '/' . $module->getName() . ".{$this->updateName}.php"; if (file_exists($filename)) { include_once $filename; } @@ -158,7 +158,7 @@ public function getMissingUpdateList() { // The description for an update comes from its Doxygen. $func = new \ReflectionFunction($function); $description = trim(str_replace(array("\n", '*', '/'), '', $func->getDocComment()), ' '); - $ret[$module]['pending'][$update] = "$update - $description"; + $ret[$module]['pending'][$update] = "$description"; if (!isset($ret[$module]['start'])) { $ret[$module]['start'] = $update; } diff --git a/core/modules/system/src/Controller/DbUpdateController.php b/core/modules/system/src/Controller/DbUpdateController.php index d935d50..ab06793 100644 --- a/core/modules/system/src/Controller/DbUpdateController.php +++ b/core/modules/system/src/Controller/DbUpdateController.php @@ -259,12 +259,12 @@ protected function selection(Request $request) { $build['start']['system'] = array(); $starting_updates = array(); - foreach (['update', 'update_after'] as $update_type) { + foreach (['update', 'post_update'] as $update_type) { switch ($update_type) { case 'update': $updates = update_get_update_list(); break; - case 'update_after': + case 'post_update': $after_update_registry = $this->getUpdateAfterRegistry(); $updates = $after_update_registry->getMissingUpdateList(); break; @@ -590,14 +590,14 @@ protected function triggerBatch(Request $request) { } $after_update_registry = $this->getUpdateAfterRegistry(); - $after_updates = $after_update_registry->getMissingUpdateFunctions(); + $post_updates = $after_update_registry->getMissingUpdateFunctions(); - if ($after_updates) { - // Now we rebuild all caches and after that execute the hook_update_after() + if ($post_updates) { + // Now we rebuild all caches and after that execute the hook_post_update() // functions. $operations[] = ['drupal_flush_all_caches', []]; - foreach ($after_updates as $function) { - $operations[] = ['update_after_do_one', [$function]]; + foreach ($post_updates as $function) { + $operations[] = ['update_post_update_do_one', [$function]]; } } @@ -616,12 +616,12 @@ protected function triggerBatch(Request $request) { } /** - * Gets the update registry instance for the hook_update_after updates. + * Gets the update registry instance for the hook_post_update updates. * * @return \Drupal\Core\Update\UpdateRegistry */ - protected function getUpdateAfterRegistry() { - return new UpdateRegistry($this->root, \Drupal::service('site.path'), array_keys($this->moduleHandler()->getModuleList()), \Drupal::keyValue('update_after')); + protected function getPostUpdateRegistry() { + return new UpdateRegistry($this->root, \Drupal::service('site.path'), array_keys($this->moduleHandler()->getModuleList()), \Drupal::keyValue('post_update')); } /** diff --git a/core/modules/system/src/Tests/Update/UpdateAfterTest.php b/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php similarity index 50% rename from core/modules/system/src/Tests/Update/UpdateAfterTest.php rename to core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php index 0b85fcb..e82b0c5 100644 --- a/core/modules/system/src/Tests/Update/UpdateAfterTest.php +++ b/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php @@ -2,17 +2,17 @@ /** * @file - * Contains \Drupal\system\Tests\Update\UpdateAfterTest. + * Contains \Drupal\system\Tests\Update\UpdatePostUpdateTest. */ namespace Drupal\system\Tests\Update; /** - * Tests hook_update_after(). + * Tests hook_post_update(). * * @group Update */ -class UpdateAfterTest extends UpdatePathTestBase { +class UpdatePostUpdateTest extends UpdatePathTestBase { /** * {@inheritdoc} @@ -20,7 +20,7 @@ class UpdateAfterTest 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-after-enabled.php', + __DIR__ . '/../../../tests/fixtures/update/drupal-8.update-post-update-after-enabled.php', ]; } @@ -28,11 +28,11 @@ public function testUpdateAfter() { $this->runUpdates(); $this->assertIdentical([ - 'update_test_after_update_after_first', - 'update_test_after_update_after_second', - 'update_test_after_update_after_test1', - 'update_test_after_update_after_test0', - ], \Drupal::state()->get('update_test_after_execution', [])); + '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', + ], \Drupal::state()->get('post_update_test_execution', [])); } } diff --git a/core/modules/system/tests/fixtures/update/drupal-8.update-test-after-enabled.php b/core/modules/system/tests/fixtures/update/drupal-8.update-test-post-update-enabled.php similarity index 82% rename from core/modules/system/tests/fixtures/update/drupal-8.update-test-after-enabled.php rename to core/modules/system/tests/fixtures/update/drupal-8.update-test-post-update-enabled.php index 681a5fb..3d5af10 100644 --- a/core/modules/system/tests/fixtures/update/drupal-8.update-test-after-enabled.php +++ b/core/modules/system/tests/fixtures/update/drupal-8.update-test-post-update-enabled.php @@ -2,7 +2,7 @@ /** * @file - * Partial database to mimic the installation of the update_test_after module. + * Partial database to mimic the installation of the update_test_post_update module. */ use Drupal\Core\Database\Database; @@ -12,10 +12,10 @@ // Set the schema version. $connection->merge('key_value') ->condition('collection', 'system.schema') - ->condition('name', 'update_test_schema') + ->condition('name', 'update_test_post_update') ->fields([ 'collection' => 'system.schema', - 'name' => 'update_test_after', + 'name' => 'update_test_post_update', 'value' => 'i:8000;', ]) ->execute(); @@ -28,7 +28,7 @@ ->execute() ->fetchField(); $extensions = unserialize($extensions); -$extensions['module']['update_test_after'] = 8000; +$extensions['module']['update_test_post_update'] = 8000; $connection->update('config') ->fields([ 'data' => serialize($extensions), diff --git a/core/modules/system/tests/modules/update_test_after/update_test_after.update_after.inc b/core/modules/system/tests/modules/update_test_after/update_test_after.update_after.inc deleted file mode 100644 index b45197a..0000000 --- a/core/modules/system/tests/modules/update_test_after/update_test_after.update_after.inc +++ /dev/null @@ -1,37 +0,0 @@ -get('update_test_after_execution', []); - $execution[] = __FUNCTION__; - \Drupal::state()->set('update_test_after_execution', $execution); -} - -/** - * Second update. - */ -function update_test_after_update_after_second() { - $execution = \Drupal::state()->get('update_test_after_execution', []); - $execution[] = __FUNCTION__; - \Drupal::state()->set('update_test_after_execution', $execution); -} - -/** - * Test1 update. - */ -function update_test_after_update_after_test1() { - $execution = \Drupal::state()->get('update_test_after_execution', []); - $execution[] = __FUNCTION__; - \Drupal::state()->set('update_test_after_execution', $execution); -} - -/** - * Test2 update. - */ -function update_test_after_update_after_test0() { - $execution = \Drupal::state()->get('update_test_after_execution', []); - $execution[] = __FUNCTION__; - \Drupal::state()->set('update_test_after_execution', $execution); -} 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_post_update/update_test_post_update.post_update.php new file mode 100644 index 0000000..7ff4945 --- /dev/null +++ b/core/modules/system/tests/modules/update_test_post_update/update_test_post_update.post_update.php @@ -0,0 +1,37 @@ +get('post_update_test_execution', []); + $execution[] = __FUNCTION__; + \Drupal::state()->set('post_update_test_execution', $execution); +} + +/** + * Second update. + */ +function update_test_post_update_post_update_second() { + $execution = \Drupal::state()->get('post_update_test_execution', []); + $execution[] = __FUNCTION__; + \Drupal::state()->set('post_update_test_execution', $execution); +} + +/** + * Test1 update. + */ +function update_test_post_update_post_update_test1() { + $execution = \Drupal::state()->get('post_update_test_execution', []); + $execution[] = __FUNCTION__; + \Drupal::state()->set('post_update_test_execution', $execution); +} + +/** + * Test2 update. + */ +function update_test_post_update_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/modules/system/tests/modules/update_test_after/update_test_after.info.yml b/core/modules/system/tests/modules/update_test_post_update/update_test_post_update.yml similarity index 100% rename from core/modules/system/tests/modules/update_test_after/update_test_after.info.yml rename to core/modules/system/tests/modules/update_test_post_update/update_test_post_update.yml diff --git a/core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php b/core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php index 92874ef..fe79330 100644 --- a/core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php +++ b/core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php @@ -28,7 +28,7 @@ class UpdateRegistryTest extends UnitTestCase { protected function setUp() { parent::setUp(); // TODO: Change the autogenerated stub - $settings = Settings::all(); + $settings = []; $settings['extension_discovery_scan_tests'] = TRUE; new Settings($settings); } @@ -55,13 +55,13 @@ protected function setupBasicModules() { /** * Module A update A. */ -function module_a_update_after_a() { +function module_a_post_update_a() { } /** * Module A update B. */ -function module_a_update_after_b() { +function module_a_post_update_b() { } EOS; @@ -71,7 +71,7 @@ function module_a_update_after_b() { /** * Module B update A. */ -function module_b_update_after_a() { +function module_b_post_update_a() { } EOS; @@ -81,11 +81,11 @@ function module_b_update_after_a() { 'default' => [ 'modules' => [ 'module_a' => [ - 'module_a.update_after.inc' => $module_a, + 'module_a.post_update.php' => $module_a, 'module_a.info.yml' => $info_a ], 'module_b' => [ - 'module_b.update_after.inc' => $module_b, + 'module_b.post_update.php' => $module_b, 'module_b.info.yml' => $info_b ], ] @@ -101,7 +101,7 @@ public function testGetMissingUpdateFunctionsWithNoExistingUpdates() { $this->setupBasicModules(); $key_value = $this->prophesize(KeyValueStoreInterface::class); - $key_value->get('core.update__update_after', [])->wilLReturn([]); + $key_value->get('core.update__post_update', [])->wilLReturn([]); $key_value = $key_value->reveal(); $update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [ @@ -110,9 +110,9 @@ public function testGetMissingUpdateFunctionsWithNoExistingUpdates() { ], $key_value, FALSE); $this->assertEquals([ - 'module_a_update_after_a', - 'module_a_update_after_b', - 'module_b_update_after_a' + 'module_a_post_update_a', + 'module_a_post_update_b', + 'module_b_post_update_a' ], $update_registry->getMissingUpdateFunctions()); } @@ -123,7 +123,7 @@ public function testGetMissingUpdateFunctionsWithExistingUpdates() { $this->setupBasicModules(); $key_value = $this->prophesize(KeyValueStoreInterface::class); - $key_value->get('core.update__update_after', [])->wilLReturn(['module_a_update_after_a']); + $key_value->get('core.update__post_update', [])->wilLReturn(['module_a_post_update_a']); $key_value = $key_value->reveal(); $update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [ @@ -132,8 +132,8 @@ public function testGetMissingUpdateFunctionsWithExistingUpdates() { ], $key_value, FALSE); $this->assertEquals(array_values([ - 'module_a_update_after_b', - 'module_b_update_after_a' + 'module_a_post_update_b', + 'module_b_post_update_a' ]), array_values($update_registry->getMissingUpdateFunctions())); } @@ -145,7 +145,7 @@ public function testGetMissingUpdateList() { $this->setupBasicModules(); $key_value = $this->prophesize(KeyValueStoreInterface::class); - $key_value->get('core.update__update_after', [])->wilLReturn([]); + $key_value->get('core.update__post_update', [])->wilLReturn([]); $key_value = $key_value->reveal(); $update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [ @@ -154,10 +154,10 @@ public function testGetMissingUpdateList() { ], $key_value, FALSE); $expected = []; - $expected['module_a']['pending']['a'] = 'a - Module A update A.'; - $expected['module_a']['pending']['b'] = 'b - Module A update B.'; + $expected['module_a']['pending']['a'] = 'Module A update A.'; + $expected['module_a']['pending']['b'] = 'Module A update B.'; $expected['module_a']['start'] = 'a'; - $expected['module_b']['pending']['a'] = 'a - Module B update A.'; + $expected['module_b']['pending']['a'] = 'Module B update A.'; $expected['module_b']['start'] = 'a'; $this->assertEquals($expected, $update_registry->getMissingUpdateList()); @@ -170,7 +170,7 @@ public function testGetMissingUpdateListWithExistingUpdates() { $this->setupBasicModules(); $key_value = $this->prophesize(KeyValueStoreInterface::class); - $key_value->get('core.update__update_after', [])->wilLReturn(['module_a_update_after_a']); + $key_value->get('core.update__post_update', [])->wilLReturn(['module_a_post_update_a']); $key_value = $key_value->reveal(); $update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [ @@ -179,9 +179,9 @@ public function testGetMissingUpdateListWithExistingUpdates() { ], $key_value, FALSE); $expected = []; - $expected['module_a']['pending']['b'] = 'b - Module A update B.'; + $expected['module_a']['pending']['b'] = 'Module A update B.'; $expected['module_a']['start'] = 'b'; - $expected['module_b']['pending']['a'] = 'a - Module B update A.'; + $expected['module_b']['pending']['a'] = 'Module B update A.'; $expected['module_b']['start'] = 'a'; $this->assertEquals($expected, $update_registry->getMissingUpdateList());