diff --git a/core/includes/schema.inc b/core/includes/schema.inc index b367bb571e..753cc935dc 100644 --- a/core/includes/schema.inc +++ b/core/includes/schema.inc @@ -78,26 +78,16 @@ function drupal_get_schema_versions($module) { * The currently installed schema version, or * \Drupal\Core\Extension\SchemaInstallerInterface::UNINSTALLED if the module * is not installed. + * + * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use + * \Drupal\Core\Extension\SchemaInstallerInterface::getInstalledVersion() + * instead. + * + * @see https://www.drupal.org/node/2444417 */ function drupal_get_installed_schema_version($module, $reset = FALSE, $array = FALSE) { - $versions = &drupal_static(__FUNCTION__, []); - - if ($reset) { - $versions = []; - } - - if (!$versions) { - if (!$versions = \Drupal::keyValue('system.schema')->getAll()) { - $versions = []; - } - } - - if ($array) { - return $versions; - } - else { - return isset($versions[$module]) ? $versions[$module] : SchemaInstallerInterface::UNINSTALLED; - } + @trigger_error('drupal_get_installed_schema_version() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Extension\SchemaInstallerInterface::getInstalledVersion() instead. See https://www.drupal.org/node/2444417', E_USER_DEPRECATED); + return \Drupal::service('schema_installer')->getInstalledVersion($module, $reset, $array); } /** @@ -107,11 +97,16 @@ function drupal_get_installed_schema_version($module, $reset = FALSE, $array = F * A module name. * @param string $version * The new schema version. + * + * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use + * \Drupal\Core\Extension\SchemaInstallerInterface::setInstalledVersion() + * instead. + * + * @see https://www.drupal.org/node/2444417 */ function drupal_set_installed_schema_version($module, $version) { - \Drupal::keyValue('system.schema')->set($module, $version); - // Reset the static cache of module schema versions. - drupal_get_installed_schema_version(NULL, TRUE); + @trigger_error('drupal_set_installed_schema_version() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Extension\SchemaInstallerInterface::setInstalledVersion() instead. See https://www.drupal.org/node/2444417', E_USER_DEPRECATED); + \Drupal::service('schema_installer')->setInstalledVersion($module, $version); } /** @@ -119,14 +114,15 @@ function drupal_set_installed_schema_version($module, $version) { * * @param string $module * The module for which the tables will be created. + * + * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use + * \Drupal\Core\Extension\SchemaInstallerInterface::install() instead. + * + * @see https://www.drupal.org/node/2444417 */ function drupal_install_schema($module) { - $schema = drupal_get_module_schema($module); - _drupal_schema_initialize($schema, $module, FALSE); - - foreach ($schema as $name => $table) { - \Drupal::database()->schema()->createTable($name, $table); - } + @trigger_error('drupal_install_schema() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Extension\SchemaInstallerInterface::install() instead. See https://www.drupal.org/node/2444417', E_USER_DEPRECATED); + \Drupal::service('schema_installer')->install($module); } /** @@ -134,16 +130,15 @@ function drupal_install_schema($module) { * * @param string $module * The module for which the tables will be removed. + * + * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use + * \Drupal\Core\Extension\SchemaInstallerInterface::uninstall() instead. + * + * @see https://www.drupal.org/node/2444417 */ function drupal_uninstall_schema($module) { - $tables = drupal_get_module_schema($module); - _drupal_schema_initialize($tables, $module, FALSE); - $schema = \Drupal::database()->schema(); - foreach ($tables as $table) { - if ($schema->tableExists($table['name'])) { - $schema->dropTable($table['name']); - } - } + @trigger_error('drupal_uninstall_schema() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Extension\SchemaInstallerInterface::uninstall() instead. See https://www.drupal.org/node/2444417', E_USER_DEPRECATED); + \Drupal::service('schema_installer')->uninstall($module); } /** @@ -188,8 +183,14 @@ function drupal_get_module_schema($module, $table = NULL) { * (optional) Whether to additionally remove 'description' keys of all tables * and fields to improve performance of serialize() and unserialize(). * Defaults to TRUE. + * + * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. No + * direct replacement provided. + * + * @see https://www.drupal.org/node/2444417 */ function _drupal_schema_initialize(&$schema, $module, $remove_descriptions = TRUE) { + @trigger_error('_drupal_schema_initialize() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. No direct replacement provided. See https://www.drupal.org/node/2444417', E_USER_DEPRECATED); // Set the name and module key for all tables. foreach ($schema as $name => &$table) { if (empty($table['module'])) { diff --git a/core/includes/update.inc b/core/includes/update.inc index 12bbd0b670..e021e64b04 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -117,12 +117,11 @@ function update_check_requirements() { * The schema version the module should be set to. */ function update_set_schema($module, $schema_version) { - \Drupal::keyValue('system.schema')->set($module, $schema_version); + \Drupal::service('schema_installer')->setInstalledVersion($module, $schema_version); \Drupal::service('extension.list.profile')->reset(); \Drupal::service('extension.list.module')->reset(); \Drupal::service('extension.list.theme_engine')->reset(); \Drupal::service('extension.list.theme')->reset(); - drupal_static_reset('drupal_get_installed_schema_version'); } /** diff --git a/core/lib/Drupal/Core/Database/database.api.php b/core/lib/Drupal/Core/Database/database.api.php index c39cf78cf4..afe64a8f89 100644 --- a/core/lib/Drupal/Core/Database/database.api.php +++ b/core/lib/Drupal/Core/Database/database.api.php @@ -385,7 +385,7 @@ * ]; * @endcode * - * @see drupal_install_schema() + * @see \Drupal\Core\Extension\SchemaInstallerInterface::install() * * @} */ diff --git a/core/lib/Drupal/Core/Extension/SchemaInstaller.php b/core/lib/Drupal/Core/Extension/SchemaInstaller.php index 4fdaf92b23..1b23e101fb 100644 --- a/core/lib/Drupal/Core/Extension/SchemaInstaller.php +++ b/core/lib/Drupal/Core/Extension/SchemaInstaller.php @@ -112,9 +112,7 @@ public function getInstalledVersion($module, $reset = FALSE, $array = FALSE) { if ($array) { return $this->currentVersions; } - else { - return isset($this->currentVersions[$module]) ? $this->currentVersions[$module] : static::UNINSTALLED; - } + return isset($this->currentVersions[$module]) ? $this->currentVersions[$module] : static::UNINSTALLED; } /** diff --git a/core/modules/system/src/Tests/Update/UpdatePathTestBase.php b/core/modules/system/src/Tests/Update/UpdatePathTestBase.php index 49d96ac4b9..5acdab0754 100644 --- a/core/modules/system/src/Tests/Update/UpdatePathTestBase.php +++ b/core/modules/system/src/Tests/Update/UpdatePathTestBase.php @@ -281,9 +281,9 @@ protected function runUpdates() { } } } - // Reset the static cache of drupal_get_installed_schema_version() so that + // Reset the static cache of installed schema versions so that // more complex update path testing works. - drupal_static_reset('drupal_get_installed_schema_version'); + \Drupal::service('schema_installer')->getInstalledVersion(NULL, TRUE); // The config schema can be incorrect while the update functions are being // executed. But once the update has been completed, it needs to be valid diff --git a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php index 4627218845..39b361e9ba 100644 --- a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php +++ b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php @@ -220,7 +220,7 @@ public function testUninstallProfileDependency() { $result = $this->moduleInstaller()->uninstall([$non_dependency]); $this->assertTrue($result, 'ModuleInstaller::uninstall() returns TRUE.'); $this->assertFalse($this->moduleHandler()->moduleExists($non_dependency)); - $this->assertEquals(drupal_get_installed_schema_version($non_dependency), SchemaInstallerInterface::UNINSTALLED, "$non_dependency module was uninstalled."); + $this->assertEquals(\Drupal::service('schema_installer')->getInstalledVersion($non_dependency), SchemaInstallerInterface::UNINSTALLED, "$non_dependency module was uninstalled."); // Verify that the installation profile itself was not uninstalled. $uninstalled_modules = \Drupal::state()->get('module_test.uninstall_order') ?: [];