diff --git a/core/includes/update.inc b/core/includes/update.inc index 532b0b89bf..18df0febe2 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -129,7 +129,7 @@ function _update_fix_missing_schema() { if ($last_removed = $module_handler->invoke($module, 'update_last_removed')) { $last_update = max($last_update, $last_removed); } - drupal_set_installed_schema_version($module, $last_update); + \Drupal::service('schema_installer')->setInstalledVersion($module, $last_update); $args = ['%module' => $module, '%last_update_hook' => $module . '_update_' . $last_update . '()']; \Drupal::messenger()->addWarning(t('Schema information for module %module was missing from the database. You should manually review the module updates and your database to check if any updates have been skipped up to, and including, %last_update_hook.', $args)); \Drupal::logger('update')->warning('Schema information for module %module was missing from the database. You should manually review the module updates and your database to check if any updates have been skipped up to, and including, %last_update_hook.', $args); @@ -342,7 +342,7 @@ function update_get_update_list() { $extension_list = \Drupal::service('extension.list.module'); foreach ($modules as $module => $schema_version) { // Skip uninstalled and incompatible modules. - if ($schema_version == SchemaInstallerInterface::UNINSTALLED || update_check_incompatibility($module)) { + if ($schema_version == SchemaInstallerInterface::UNINSTALLED || $extension_list->checkIncompatibility($module)) { continue; } // Display a requirements error if the user somehow has a schema version diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 1e68600a42..d8b2f2491f 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1218,17 +1218,19 @@ function system_requirements($phase) { // one that was last removed. if ($phase == 'update') { $module_handler = \Drupal::moduleHandler(); + /** @var \Drupal\Core\Extension\SchemaInstallerInterface $schema_installer */ + $schema_installer = \Drupal::service('schema_installer'); $module_list = []; foreach ($module_handler->getImplementations('update_last_removed') as $module) { $last_removed = $module_handler->invoke($module, 'update_last_removed'); - if ($last_removed && $last_removed > drupal_get_installed_schema_version($module)) { + if ($last_removed && $last_removed > $schema_installer->getInstalledVersion($module)) { /** @var \Drupal\Core\Extension\Extension $module_info */ $module_info = \Drupal::service('extension.list.module')->get($module); $module_list[$module] = [ 'name' => $module_info->info['name'], 'last_removed' => $last_removed, - 'installed_version' => drupal_get_installed_schema_version($module), + 'installed_version' => $schema_installer->getInstalledVersion($module), ]; } } diff --git a/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathLastRemovedTest.php b/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathLastRemovedTest.php index 20d18856c1..4d39ad2e03 100644 --- a/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathLastRemovedTest.php +++ b/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathLastRemovedTest.php @@ -53,8 +53,8 @@ protected function setUp(): void { * Tests that a module with a too old schema version can not be updated. */ public function testLastRemovedVersion() { - drupal_set_installed_schema_version('update_test_last_removed', 8000); - drupal_set_installed_schema_version('system', 8804); + $this->getSchemaInstaller()->setInstalledVersion('update_test_last_removed', 8000); + $this->getSchemaInstaller()->setInstalledVersion('system', 8804); // Access the update page with a schema version that is too old for system // and the test module, only the generic core message should be shown. @@ -70,7 +70,7 @@ public function testLastRemovedVersion() { // Update the installed version of system and then assert that now, // the test module is shown instead. - drupal_set_installed_schema_version('system', 8805); + $this->getSchemaInstaller()->setInstalledVersion('system', 8805); $this->drupalGet($this->updateUrl); $assert_session->pageTextNotContains('The version of Drupal you are trying to update from is too old'); @@ -81,11 +81,21 @@ public function testLastRemovedVersion() { // Set the expected schema version for the node and test module, updates are // successful now. - drupal_set_installed_schema_version('update_test_last_removed', 8002); + $this->getSchemaInstaller()->setInstalledVersion('update_test_last_removed', 8002); $this->runUpdates(); - $this->assertEquals(8003, drupal_get_installed_schema_version('update_test_last_removed')); + $this->assertEquals(8003, $this->getSchemaInstaller()->getInstalledVersion('update_test_last_removed')); } + /** + * Returns the schema installer service. + * + * @return \Drupal\Core\Extension\SchemaInstallerInterface + * The schema installer. + */ + protected function getSchemaInstaller() { + return \Drupal::service('schema_installer'); + } + } diff --git a/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathNewDependencyTest.php b/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathNewDependencyTest.php index 6830c3b7f5..c876c9b0e7 100644 --- a/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathNewDependencyTest.php +++ b/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathNewDependencyTest.php @@ -31,7 +31,7 @@ public function testUpdateNewDependency() { ->set('module.new_dependency_test', 0) ->set('module', module_config_sort($extension_config->get('module'))) ->save(TRUE); - drupal_set_installed_schema_version('new_dependency_test', \Drupal::CORE_MINIMUM_SCHEMA_VERSION); + \Drupal::service('schema_installer')->setInstalledVersion('new_dependency_test', \Drupal::CORE_MINIMUM_SCHEMA_VERSION); // Rebuild the container and test that the service with the optional unmet // dependency is still available while the ones that fail are not. diff --git a/core/tests/Drupal/Tests/UpdatePathTestTrait.php b/core/tests/Drupal/Tests/UpdatePathTestTrait.php index 421f7097f8..e930c00fee 100644 --- a/core/tests/Drupal/Tests/UpdatePathTestTrait.php +++ b/core/tests/Drupal/Tests/UpdatePathTestTrait.php @@ -60,7 +60,7 @@ protected function runUpdates($update_url = NULL) { // Ensure that there are no pending updates. Clear the schema version // static cache first in case it was accessed before running updates. - drupal_get_installed_schema_version(NULL, TRUE); + \Drupal::service('schema_installer')->getInstalledVersion(NULL, TRUE); foreach (['update', 'post_update'] as $update_type) { switch ($update_type) { case 'update':