diff --git a/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php index 5ce0f7b..ab11469 100644 --- a/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php +++ b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php @@ -188,7 +188,7 @@ public function scan($type, $include_tests = NULL) { // Test extensions can also be included for debugging purposes by setting a // variable in settings.php. if (!isset($include_tests)) { - $include_tests = drupal_valid_test_ua() || Settings::get('extension_discovery_scan_tests'); + $include_tests = Settings::get('extension_discovery_scan_tests') || drupal_valid_test_ua(); } $files = array(); diff --git a/core/lib/Drupal/Core/Extension/module.api.php b/core/lib/Drupal/Core/Extension/module.api.php index d7d5332..6bc62d1 100644 --- a/core/lib/Drupal/Core/Extension/module.api.php +++ b/core/lib/Drupal/Core/Extension/module.api.php @@ -660,6 +660,41 @@ function hook_update_N(&$sandbox) { } /** + * Executes an update which is intended to update data, like entities. + * + * 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 + * also use machine names. + * + * @param array $sandbox + * Stores information for batch updates. See above for more information. + * + * @throws \Drupal\Core\Utility\UpdateException|PDOException + * In case of error, update hooks should throw an instance of + * Drupal\Core\Utility\UpdateException with a meaningful message for the user. + * If a database query fails for whatever reason, it will throw a + * PDOException.ame for the name of those updates. + * + * @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 + * returned, no message will be presented to the user. + * + * @ingroup update_api + * + * @see hook_update_N + */ +function hook_update_after_X(&$sandbox) { + $node = \Drupal\node\Entity\Node::load(123); + $node->setTitle('foo'); + $node->save(); + + return t('Node 123 saved'); +} + +/** * Return an array of information about module update dependencies. * * This can be used to indicate update functions from other modules that your diff --git a/core/modules/system/src/Controller/DbUpdateController.php b/core/modules/system/src/Controller/DbUpdateController.php index 5b44880..d935d50 100644 --- a/core/modules/system/src/Controller/DbUpdateController.php +++ b/core/modules/system/src/Controller/DbUpdateController.php @@ -283,7 +283,6 @@ protected function selection(Request $request) { continue; } if (!empty($update['pending'])) { - $starting_updates[$module] = $update['start']; $build['start'][$module] = array( '#type' => 'hidden', '#value' => $update['start'], @@ -293,6 +292,10 @@ protected function selection(Request $request) { '#items' => $update['pending'], '#title' => $module . ' module', ); + + if ($update_type === 'update') { + $starting_updates[$module] = $update['start']; + } } if (isset($update['pending'])) { $count = $count + count($update['pending']); diff --git a/core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php b/core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php index 2206fc2..92874ef 100644 --- a/core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php +++ b/core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\Site\Settings; use Drupal\Core\Update\UpdateRegistry; use Drupal\Tests\UnitTestCase; use org\bovigo\vfs\vfsStream; @@ -21,7 +22,21 @@ */ class UpdateRegistryTest extends UnitTestCase { - protected function setupBasicModules($directories) { + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); // TODO: Change the autogenerated stub + + $settings = Settings::all(); + $settings['extension_discovery_scan_tests'] = TRUE; + new Settings($settings); + } + + /** + * Sets up some modules with some update functions. + */ + protected function setupBasicModules() { $info_a = <<<'EOS' type: module name: Module A @@ -61,7 +76,7 @@ function module_b_update_after_a() { EOS; vfsStream::setup('drupal'); - vfsStream::create(NestedArray::mergeDeep($directories, [ + vfsStream::create([ 'sites' => [ 'default' => [ 'modules' => [ @@ -76,14 +91,14 @@ function module_b_update_after_a() { ] ] ], - ])); + ]); } /** * @covers ::getMissingUpdateFunctions */ public function testGetMissingUpdateFunctionsWithNoExistingUpdates() { - $this->setupBasicModules([]); + $this->setupBasicModules(); $key_value = $this->prophesize(KeyValueStoreInterface::class); $key_value->get('core.update__update_after', [])->wilLReturn([]); @@ -105,7 +120,7 @@ public function testGetMissingUpdateFunctionsWithNoExistingUpdates() { * @covers ::getMissingUpdateFunctions */ public function testGetMissingUpdateFunctionsWithExistingUpdates() { - $this->setupBasicModules([]); + $this->setupBasicModules(); $key_value = $this->prophesize(KeyValueStoreInterface::class); $key_value->get('core.update__update_after', [])->wilLReturn(['module_a_update_after_a']); @@ -127,7 +142,7 @@ public function testGetMissingUpdateFunctionsWithExistingUpdates() { * @covers ::getMissingUpdateList */ public function testGetMissingUpdateList() { - $this->setupBasicModules([]); + $this->setupBasicModules(); $key_value = $this->prophesize(KeyValueStoreInterface::class); $key_value->get('core.update__update_after', [])->wilLReturn([]); @@ -152,7 +167,7 @@ public function testGetMissingUpdateList() { * @covers ::getMissingUpdateList */ public function testGetMissingUpdateListWithExistingUpdates() { - $this->setupBasicModules([]); + $this->setupBasicModules(); $key_value = $this->prophesize(KeyValueStoreInterface::class); $key_value->get('core.update__update_after', [])->wilLReturn(['module_a_update_after_a']);