diff --git a/core/includes/schema.inc b/core/includes/schema.inc index e4e2a29..bf2b300 100644 --- a/core/includes/schema.inc +++ b/core/includes/schema.inc @@ -106,7 +106,10 @@ function drupal_set_installed_schema_version($module, $version) { \Drupal::keyValue('system.schema')->set($module, $version); // Store the information in config so that we can ensure that database updates // are the same between the source and the target site instances. - \Drupal::configFactory()->getEditable('core.extension')->set("versions.$module.schema", (string) $version); + \Drupal::configFactory() + ->getEditable('core.extension') + ->set("versions.$module.schema", (string) $version) + ->save(); // Reset the static cache of module schema versions. drupal_get_installed_schema_version(NULL, TRUE); } diff --git a/core/modules/config/src/Tests/ConfigImporterTest.php b/core/modules/config/src/Tests/ConfigImporterTest.php index a07bcce..4dc2367 100644 --- a/core/modules/config/src/Tests/ConfigImporterTest.php +++ b/core/modules/config/src/Tests/ConfigImporterTest.php @@ -697,7 +697,7 @@ public function testVersionMismatch() { $error_log = $this->configImporter->getErrors(); $this->assertEqual([ 'The schema version of config_test module on the source site (8999) does not match this site (-1).', - 'The version of system module on the source site (8.0.0-beta1) does not match this site (8.0.0-dev).' + 'The version of system module on the source site (8.0.0-beta1) does not match this site (' . \Drupal::VERSION . ').' ], $error_log); } } diff --git a/core/modules/system/src/Tests/Update/VersionInfoUpdateTest.php b/core/modules/system/src/Tests/Update/VersionInfoUpdateTest.php new file mode 100644 index 0000000..280cbe8 --- /dev/null +++ b/core/modules/system/src/Tests/Update/VersionInfoUpdateTest.php @@ -0,0 +1,64 @@ +databaseDumpFiles = [ + __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz', + ]; + } + + /** + * Tests that core.extension:versions is updated properly. + */ + public function testSystemUpdate8015() { + // Set a partial value to ensure that regardless everything is updated + // correctly. + $this->config('core.extension')->set('versions.user.install', '8.0.0')->save(); + $this->runUpdates(); + + // Test that a module is added. + $this->assertEqual([ + 'current' => \Drupal::VERSION, + 'install' => \Drupal::VERSION, + 'schema' => drupal_get_installed_schema_version('system'), + ], $this->config('core.extension')->get('versions.system')); + // Test that a profile is added. + $this->assertEqual([ + 'current' => \Drupal::VERSION, + 'install' => \Drupal::VERSION, + 'schema' => drupal_get_installed_schema_version('standard'), + ], $this->config('core.extension')->get('versions.standard')); + // Test that a theme is added. + $this->assertEqual([ + 'current' => \Drupal::VERSION, + 'install' => \Drupal::VERSION, + ], $this->config('core.extension')->get('versions.bartik')); + + // Test that any existing version information is merged correctly. + $this->assertEqual([ + 'current' => \Drupal::VERSION, + 'install' => '8.0.0', + 'schema' => drupal_get_installed_schema_version('user'), + ], $this->config('core.extension')->get('versions.user')); + + } + +} diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 67d049a..076e065 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -10,6 +10,7 @@ use Drupal\Core\Url; use Drupal\Core\Database\Database; use Drupal\Core\DrupalKernel; +use Drupal\Core\Extension\Extension; use Drupal\Core\Site\Settings; use Drupal\Core\StreamWrapper\PrivateStream; use Drupal\Core\StreamWrapper\PublicStream; @@ -1873,27 +1874,49 @@ function system_update_8014() { */ /** + * @addtogroup updates-8.1.0 + * @{ + */ + +/** * Add the version information to core.extension */ function system_update_8015() { // Update core.extensions to have the correct version information. $core = \Drupal::configFactory()->getEditable('core.extension'); - $versions = $core->get('versions'); - foreach (\Drupal::moduleHandler()->getModuleList() as $module => $extension) { - $version = \Drupal::service('info_parser')->parse($extension->getPathname())['version']; - $versions[$module] = [ + $versions = $core->get('versions') ?: []; + $info_parser = \Drupal::service('info_parser'); + + // Create a method to populate the version information for an array of + // \Drupal\Core\Extension\Extension objects. + $map_version_info = function (Extension $extension) use ($info_parser) { + // Read from disk to avoid using APIs. + $version = $info_parser->parse($extension->getPathname())['version']; + $return = [ 'current' => $version, + // We can't know which version was present at install time so all we can + // do is use the current version. 'install' => $version, - 'schema' => (string) drupal_get_installed_schema_version($module), ]; - } - foreach (\Drupal::service('theme_handler')->listInfo() as $theme => $extension) { - $version = \Drupal::service('info_parser')->parse($extension->getPathname())['version']; - $versions[$theme] = [ - 'current' => $version, - 'install' => $version, - ]; - } + // Modules and profiles also stored the schema version. + if ($extension->getType() === 'module' || $extension->getType() === 'profile') { + $return['schema'] = (string) drupal_get_installed_schema_version($extension->getName()); + } + return $return; + }; + + // It is possible that version information already exists. For example, + // another hook_update_N hook could have installed a module. Do not overwrite + // existing data. + $versions = \Drupal\Component\Utility\NestedArray::mergeDeep( + array_map($map_version_info, \Drupal::moduleHandler()->getModuleList()), + array_map($map_version_info, \Drupal::service('theme_handler')->listInfo()), + $versions + ); ksort($versions); $core->set('versions', $versions)->save(); } + +/** + * @} End of "addtogroup updates-8.1.0". + */