diff --git a/core/core.services.yml b/core/core.services.yml index a842043e12..dbaaa578e7 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -509,7 +509,7 @@ services: class: Drupal\Core\Extension\ModuleInstaller tags: - { name: service_collector, tag: 'module_install.uninstall_validator', call: addUninstallValidator } - arguments: ['@app.root', '@module_handler', '@kernel'] + arguments: ['@app.root', '@module_handler', '@kernel', '@schema_installer'] lazy: true extension.list.module: class: Drupal\Core\Extension\ModuleExtensionList @@ -541,6 +541,10 @@ services: theme_installer: class: Drupal\Core\Extension\ThemeInstaller arguments: ['@theme_handler', '@config.factory', '@config.installer', '@module_handler', '@config.manager', '@asset.css.collection_optimizer', '@router.builder', '@logger.channel.default', '@state'] + schema_installer: + class: Drupal\Core\Extension\SchemaInstaller + arguments: ['@module_handler', '@cache.default', '@keyvalue', '@database', '@cache_tags.invalidator'] + lazy: true # @deprecated in Drupal 8.0.x and will be removed before 9.0.0. Use the other # entity* services instead. entity.manager: diff --git a/core/includes/install.inc b/core/includes/install.inc index 45a8b141c3..571a1380b4 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -80,7 +80,7 @@ * Loads .install files for installed modules to initialize the update system. */ function drupal_load_updates() { - foreach (drupal_get_installed_schema_version(NULL, FALSE, TRUE) as $module => $schema_version) { + foreach (\Drupal::service('schema_installer')->getInstalledVersion(NULL, FALSE, TRUE) as $module => $schema_version) { if ($schema_version > -1) { module_load_install($module); } diff --git a/core/includes/schema.inc b/core/includes/schema.inc index 978ec2307a..b3972c0210 100644 --- a/core/includes/schema.inc +++ b/core/includes/schema.inc @@ -5,6 +5,8 @@ * Schema API handling functions. */ +use Drupal\Core\Extension\SchemaInstallerInterface; + /** * @addtogroup schemaapi * @{ @@ -12,8 +14,11 @@ /** * Indicates that a module has not been installed yet. + * + * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. + * Use \Drupal\Core\Extension\SchemaInstallerInterface::UNINSTALLED. */ -const SCHEMA_UNINSTALLED = -1; +const SCHEMA_UNINSTALLED = SchemaInstallerInterface::UNINSTALLED; /** * Returns an array of available schema versions for a module. @@ -70,28 +75,19 @@ function drupal_get_schema_versions($module) { * system. * * @return string|int - * The currently installed schema version, or SCHEMA_UNINSTALLED if the - * module is not installed. + * 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/2970993 */ 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] : SCHEMA_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/2970993', E_USER_DEPRECATED); + return \Drupal::service('schema_installer')->getInstalledVersion($module, $reset, $array); } /** @@ -101,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/2970993 */ 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/2970993', E_USER_DEPRECATED); + \Drupal::service('schema_installer')->setInstalledVersion($module, $version); } /** @@ -113,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/2970993 */ 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/2970993', E_USER_DEPRECATED); + \Drupal::service('schema_installer')->install($module); } /** @@ -128,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/2970993 */ 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/2970993', E_USER_DEPRECATED); + \Drupal::service('schema_installer')->uninstall($module); } /** @@ -152,22 +153,15 @@ function drupal_uninstall_schema($module) { * @param string $table * The name of the table. If not given, the module's complete schema * is returned. + * + * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use + * \Drupal\Core\Extension\SchemaInstallerInterface::getSchema() instead. + * + * @see https://www.drupal.org/node/2970993 */ function drupal_get_module_schema($module, $table = NULL) { - // Load the .install file to get hook_schema. - module_load_install($module); - $schema = \Drupal::moduleHandler()->invoke($module, 'schema'); - - if (isset($table)) { - if (isset($schema[$table])) { - return $schema[$table]; - } - return []; - } - elseif (!empty($schema)) { - return $schema; - } - return []; + @trigger_error('drupal_get_module_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/2970993', E_USER_DEPRECATED); + return \Drupal::service('schema_installer')->getSchema($module, $table); } /** @@ -182,8 +176,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/2970993 */ 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/2970993', 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 2021a66231..e021e64b04 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -9,6 +9,7 @@ */ use Drupal\Component\Graph\Graph; +use Drupal\Core\Extension\SchemaInstallerInterface; use Drupal\Core\Update\UpdateKernel; use Drupal\Core\Utility\Error; @@ -75,7 +76,7 @@ function update_check_incompatibility($name, $type = 'module') { function update_system_schema_requirements() { $requirements = []; - $system_schema = drupal_get_installed_schema_version('system'); + $system_schema = \Drupal::service('schema_installer')->getInstalledVersion('system'); $requirements['minimum schema']['title'] = 'Minimum schema version'; if ($system_schema >= \Drupal::CORE_MINIMUM_SCHEMA_VERSION) { @@ -116,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'); } /** @@ -217,7 +217,7 @@ function update_do_one($module, $number, $dependency_map, &$context) { // Record the schema update if it was completed successfully. if ($context['finished'] == 1 && empty($ret['#abort'])) { - drupal_set_installed_schema_version($module, $number); + \Drupal::service('schema_installer')->setInstalledVersion($module, $number); } $context['message'] = t('Updating @module', ['@module' => $module]); @@ -306,10 +306,10 @@ function update_get_update_list() { // Make sure that the system module is first in the list of updates. $ret = ['system' => []]; - $modules = drupal_get_installed_schema_version(NULL, FALSE, TRUE); + $modules = \Drupal::service('schema_installer')->getInstalledVersion(NULL, FALSE, TRUE); foreach ($modules as $module => $schema_version) { // Skip uninstalled and incompatible modules. - if ($schema_version == SCHEMA_UNINSTALLED || update_check_incompatibility($module)) { + if ($schema_version == SchemaInstallerInterface::UNINSTALLED || update_check_incompatibility($module)) { continue; } // Display a requirements error if the user somehow has a schema version @@ -586,7 +586,7 @@ function update_is_missing($module, $number, $update_functions) { * performed; FALSE otherwise. */ function update_already_performed($module, $number) { - return $number <= drupal_get_installed_schema_version($module); + return $number <= \Drupal::service('schema_installer')->getInstalledVersion($module); } /** @@ -609,7 +609,7 @@ function update_retrieve_dependencies() { // Get a list of installed modules, arranged so that we invoke their hooks in // the same order that \Drupal::moduleHandler()->invokeAll() does. foreach (\Drupal::keyValue('system.schema')->getAll() as $module => $schema) { - if ($schema == SCHEMA_UNINSTALLED) { + if ($schema == SchemaInstallerInterface::UNINSTALLED) { // Nothing to upgrade. continue; } 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/ModuleExtensionList.php b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php index c8f492bd4f..2364f674f0 100644 --- a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php @@ -173,7 +173,7 @@ protected function doList() { foreach ($extensions as $name => $module) { $module->weight = isset($installed_modules[$name]) ? $installed_modules[$name] : 0; $module->status = (int) isset($installed_modules[$name]); - $module->schema_version = SCHEMA_UNINSTALLED; + $module->schema_version = SchemaInstallerInterface::UNINSTALLED; } $extensions = $this->moduleHandler->buildModuleDependencies($extensions); diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index 86cc9bc44d..8f3e0e6b3c 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -43,6 +43,13 @@ class ModuleInstaller implements ModuleInstallerInterface { */ protected $root; + /** + * The schema service. + * + * @var \Drupal\Core\Extension\SchemaInstallerInterface + */ + protected $schemaInstaller; + /** * The uninstall validators. * @@ -59,14 +66,20 @@ class ModuleInstaller implements ModuleInstallerInterface { * The module handler. * @param \Drupal\Core\DrupalKernelInterface $kernel * The drupal kernel. + * @param \Drupal\Core\Extension\SchemaInstallerInterface|null $schema_installer + * The schema installer service. * * @see \Drupal\Core\DrupalKernel * @see \Drupal\Core\CoreServiceProvider */ - public function __construct($root, ModuleHandlerInterface $module_handler, DrupalKernelInterface $kernel) { + public function __construct($root, ModuleHandlerInterface $module_handler, DrupalKernelInterface $kernel, SchemaInstallerInterface $schema_installer = NULL) { $this->root = $root; $this->moduleHandler = $module_handler; $this->kernel = $kernel; + if (!$schema_installer) { + $schema_installer = \Drupal::service('schema_installer'); + } + $this->schemaInstaller = $schema_installer; } /** @@ -214,7 +227,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { $this->moduleHandler->invokeAll('module_preinstall', [$module]); // Now install the module's schema if necessary. - drupal_install_schema($module); + $this->schemaInstaller->install($module); // Clear plugin manager caches. \Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions(); @@ -273,7 +286,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { if ($last_removed = $this->moduleHandler->invoke($module, 'update_last_removed')) { $version = max($version, $last_removed); } - drupal_set_installed_schema_version($module, $version); + $this->schemaInstaller->setInstalledVersion($module, $version); // Ensure that all post_update functions are registered already. /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */ @@ -436,7 +449,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { } // Remove the schema. - drupal_uninstall_schema($module); + $this->schemaInstaller->uninstall($module); // Remove the module's entry from the config. Don't check schema when // uninstalling a module since we are only clearing a key. @@ -486,7 +499,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { // fastCGI which executes ::destruct() after the Module uninstallation page // was sent already. \Drupal::service('router.builder')->rebuild(); - drupal_get_installed_schema_version(NULL, TRUE); + $this->schemaInstaller->getInstalledVersion(NULL, TRUE); // Let other modules react. $this->moduleHandler->invokeAll('modules_uninstalled', [$module_list]); diff --git a/core/lib/Drupal/Core/Extension/SchemaInstaller.php b/core/lib/Drupal/Core/Extension/SchemaInstaller.php new file mode 100644 index 0000000000..3acdf4b3cb --- /dev/null +++ b/core/lib/Drupal/Core/Extension/SchemaInstaller.php @@ -0,0 +1,206 @@ +moduleHandler = $module_handler; + $this->cacheBackend = $cache_backend; + $this->keyValue = $key_value_factory; + $this->connection = $connection; + $this->cacheTagsInvalidator = $cache_tags_invalidator; + } + + /** + * {@inheritdoc} + */ + public function getInstalledVersion($module, $reset = FALSE, $array = FALSE) { + if ($reset) { + $this->currentVersions = []; + } + + if (!$this->currentVersions = $this->keyValue->get('system.schema')->getAll()) { + $this->currentVersions = []; + } + + if ($array) { + return $this->currentVersions; + } + return isset($this->currentVersions[$module]) ? $this->currentVersions[$module] : static::UNINSTALLED; + } + + /** + * {@inheritdoc} + */ + public function setInstalledVersion($module, $version) { + $this->keyValue->get('system.schema')->set($module, $version); + // Reset the static cache of module schema currentVersions. + $this->getInstalledVersion(NULL, TRUE); + } + + /** + * {@inheritdoc} + */ + public function install($module) { + $schema = $this->getSchema($module); + $this->initialize($schema, $module, FALSE); + + foreach ($schema as $name => $table) { + $this->connection->schema()->createTable($name, $table); + } + } + + /** + * {@inheritdoc} + */ + public function uninstall($module) { + $schema = $this->getSchema($module); + $this->initialize($schema, $module, FALSE); + $connection_schema = $this->connection->schema(); + + foreach ($schema as $table) { + if ($connection_schema->tableExists($table['name'])) { + $connection_schema->dropTable($table['name']); + } + } + } + + /** + * {@inheritdoc} + */ + public function getSchema($module, $table = NULL) { + // Load the .install file to get hook_schema. + $this->moduleHandler->loadInclude($module, 'install'); + $schema = $this->moduleHandler->invoke($module, 'schema'); + + if (isset($table)) { + if (isset($schema[$table])) { + return $schema[$table]; + } + return []; + } + elseif (!empty($schema)) { + return $schema; + } + + return []; + } + + /** + * Fills in required default values for table definitions from hook_schema(). + * + * @param array $schema + * The schema definition array as it was returned by the module's + * hook_schema(). + * @param string $module + * The module for which hook_schema() was invoked. + * @param bool $remove_descriptions + * (optional) Whether to additionally remove 'description' keys of all + * tables and fields to improve performance of serialize() and + * unserialize(). Defaults to TRUE. + */ + private function initialize(&$schema, $module, $remove_descriptions = TRUE) { + // Set the name and module key for all tables. + foreach ($schema as $name => &$table) { + if (empty($table['module'])) { + $table['module'] = $module; + } + if (!isset($table['name'])) { + $table['name'] = $name; + } + if ($remove_descriptions) { + unset($table['description']); + foreach ($table['fields'] as &$field) { + unset($field['description']); + } + } + } + } + +} diff --git a/core/lib/Drupal/Core/Extension/SchemaInstallerInterface.php b/core/lib/Drupal/Core/Extension/SchemaInstallerInterface.php new file mode 100644 index 0000000000..466e612b08 --- /dev/null +++ b/core/lib/Drupal/Core/Extension/SchemaInstallerInterface.php @@ -0,0 +1,90 @@ +container = $container; + $this->drupalProxyOriginalServiceId = $drupal_proxy_original_service_id; + } + + /** + * Lazy loads the real service from the container. + * + * @return object + * Returns the constructed real service. + */ + protected function lazyLoadItself() + { + if (!isset($this->service)) { + $this->service = $this->container->get($this->drupalProxyOriginalServiceId); + } + + return $this->service; + } + + /** + * {@inheritdoc} + */ + public function getInstalledVersion($module, $reset = false, $array = false) + { + return $this->lazyLoadItself()->getInstalledVersion($module, $reset, $array); + } + + /** + * {@inheritdoc} + */ + public function setInstalledVersion($module, $version) + { + return $this->lazyLoadItself()->setInstalledVersion($module, $version); + } + + /** + * {@inheritdoc} + */ + public function install($module) + { + return $this->lazyLoadItself()->install($module); + } + + /** + * {@inheritdoc} + */ + public function uninstall($module) + { + return $this->lazyLoadItself()->uninstall($module); + } + + /** + * {@inheritdoc} + */ + public function getSchema($module, $table = NULL) + { + return $this->lazyLoadItself()->getSchema($module, $table); + } + + } + +} diff --git a/core/modules/block/block.post_update.php b/core/modules/block/block.post_update.php index 0d49ead480..d00d0df638 100644 --- a/core/modules/block/block.post_update.php +++ b/core/modules/block/block.post_update.php @@ -13,7 +13,7 @@ function block_post_update_disable_blocks_with_missing_contexts() { // which used to do the same. Note: Its okay to check here, because // update_do_one() does not update the installed schema version until the // batch is finished. - $module_schema = drupal_get_installed_schema_version('block'); + $module_schema = \Drupal::service('schema_installer')->getInstalledVersion('block'); // The state entry 'block_update_8002_placeholder' is used in order to // indicate that the placeholder block_update_8002() function has been diff --git a/core/modules/node/node.install b/core/modules/node/node.install index 557153eb59..40396a59fb 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -251,7 +251,7 @@ function node_update_8301() { * Fix realm column description on the node_access table. */ function node_update_8400() { - $schema = drupal_get_module_schema('node', 'node_access'); + $schema = \Drupal::service('schema_installer')->getSchema('node', 'node_access'); $schema['fields']['realm']['description'] = 'The realm in which the user must possess the grant ID. Modules can define one or more realms by implementing hook_node_grants().'; Database::getConnection()->schema()->changeField('node_access', 'realm', 'realm', $schema['fields']['realm']); } diff --git a/core/modules/simpletest/src/KernelTestBase.php b/core/modules/simpletest/src/KernelTestBase.php index 80c8eb0b7f..205f92d5a3 100644 --- a/core/modules/simpletest/src/KernelTestBase.php +++ b/core/modules/simpletest/src/KernelTestBase.php @@ -459,8 +459,9 @@ protected function installSchema($module, $tables) { } $tables = (array) $tables; + $schema_installer = \Drupal::service('schema_installer'); foreach ($tables as $table) { - $schema = drupal_get_module_schema($module, $table); + $schema = $schema_installer->getSchema($module, $table); if (empty($schema)) { // BC layer to avoid some contrib tests to fail. // @todo Remove the BC layer before 8.1.x release. diff --git a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php index fc0d918b8a..bfde117b7c 100644 --- a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php +++ b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php @@ -127,7 +127,7 @@ public function testEnableModulesInstall() { $this->assertTrue(in_array($module, $list), "{$module}_hook_info() in \Drupal::moduleHandler()->getImplementations() found."); $this->assertTrue(Database::getConnection()->schema()->tableExists($table), "'$table' database table found."); - $schema = drupal_get_module_schema($module, $table); + $schema = \Drupal::service('schema_installer')->getSchema($module, $table); $this->assertTrue($schema, "'$table' table schema found."); } @@ -159,7 +159,9 @@ public function testInstallSchema() { $this->assertTrue(Database::getConnection()->schema()->tableExists($table), "'$table' database table found."); // Verify that the schema is known to Schema API. - $schema = drupal_get_module_schema($module, $table); + /** @var \Drupal\Core\Extension\SchemaInstaller $schema_installer */ + $schema_installer = \Drupal::service('schema_installer'); + $schema = $schema_installer->getSchema($module, $table); $this->assertTrue($schema, "'$table' table schema found."); // Verify that a unknown table from an enabled module throws an error. @@ -172,7 +174,7 @@ public function testInstallSchema() { $this->pass('Exception for non-retrievable schema found.'); } $this->assertFalse(Database::getConnection()->schema()->tableExists($table), "'$table' database table not found."); - $schema = drupal_get_module_schema($module, $table); + $schema = $schema_installer->getSchema($module, $table); $this->assertFalse($schema, "'$table' table schema not found."); // Verify that a table from a unknown module cannot be installed. @@ -186,14 +188,15 @@ public function testInstallSchema() { $this->pass('Exception for non-retrievable schema found.'); } $this->assertFalse(Database::getConnection()->schema()->tableExists($table), "'$table' database table not found."); - $schema = drupal_get_module_schema($module, $table); + $schema_installer = \Drupal::service('schema_installer'); + $schema = $schema_installer->getSchema($module, $table); $this->assertTrue($schema, "'$table' table schema found."); // Verify that the same table can be installed after enabling the module. $this->enableModules([$module]); $this->installSchema($module, $table); $this->assertTrue(Database::getConnection()->schema()->tableExists($table), "'$table' database table found."); - $schema = drupal_get_module_schema($module, $table); + $schema = $schema_installer->getSchema($module, $table); $this->assertTrue($schema, "'$table' table schema found."); } diff --git a/core/modules/system/src/Controller/DbUpdateController.php b/core/modules/system/src/Controller/DbUpdateController.php index 25a2a70891..082d55a323 100644 --- a/core/modules/system/src/Controller/DbUpdateController.php +++ b/core/modules/system/src/Controller/DbUpdateController.php @@ -5,6 +5,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Extension\SchemaInstallerInterface; use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface; use Drupal\Core\Render\BareHtmlPageRendererInterface; use Drupal\Core\Session\AccountInterface; @@ -77,6 +78,13 @@ class DbUpdateController extends ControllerBase { */ protected $postUpdateRegistry; + /** + * The schema service. + * + * @var \Drupal\Core\Extension\SchemaDataInterface + */ + protected $schemaInstaller; + /** * Constructs a new UpdateController. * @@ -96,8 +104,10 @@ class DbUpdateController extends ControllerBase { * The bare HTML page renderer. * @param \Drupal\Core\Update\UpdateRegistry $post_update_registry * The post update registry. + * @param \Drupal\Core\Extension\SchemaInstallerInterface $schema_installer + * The schema installer. */ - public function __construct($root, KeyValueExpirableFactoryInterface $key_value_expirable_factory, CacheBackendInterface $cache, StateInterface $state, ModuleHandlerInterface $module_handler, AccountInterface $account, BareHtmlPageRendererInterface $bare_html_page_renderer, UpdateRegistry $post_update_registry) { + public function __construct($root, KeyValueExpirableFactoryInterface $key_value_expirable_factory, CacheBackendInterface $cache, StateInterface $state, ModuleHandlerInterface $module_handler, AccountInterface $account, BareHtmlPageRendererInterface $bare_html_page_renderer, UpdateRegistry $post_update_registry, SchemaInstallerInterface $schema_installer) { $this->root = $root; $this->keyValueExpirableFactory = $key_value_expirable_factory; $this->cache = $cache; @@ -106,6 +116,7 @@ public function __construct($root, KeyValueExpirableFactoryInterface $key_value_ $this->account = $account; $this->bareHtmlPageRenderer = $bare_html_page_renderer; $this->postUpdateRegistry = $post_update_registry; + $this->schemaInstaller = $schema_installer; } /** @@ -120,7 +131,8 @@ public static function create(ContainerInterface $container) { $container->get('module_handler'), $container->get('current_user'), $container->get('bare_html_page_renderer'), - $container->get('update.post_update_registry') + $container->get('update.post_update_registry'), + $container->get('schema_installer') ); } @@ -599,7 +611,7 @@ protected function triggerBatch(Request $request) { // correct place. (The updates are already sorted, so we can simply base // this on the first one we come across in the above foreach loop.) if (isset($start[$update['module']])) { - drupal_set_installed_schema_version($update['module'], $update['number'] - 1); + $this->schemaInstaller->setInstalledVersion($update['module'], $update['number'] - 1); unset($start[$update['module']]); } $operations[] = ['update_do_one', [$update['module'], $update['number'], $dependency_map[$function]]]; diff --git a/core/modules/system/src/Form/ModulesUninstallForm.php b/core/modules/system/src/Form/ModulesUninstallForm.php index 841a741e44..03d9dadc62 100644 --- a/core/modules/system/src/Form/ModulesUninstallForm.php +++ b/core/modules/system/src/Form/ModulesUninstallForm.php @@ -7,6 +7,7 @@ use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface; +use Drupal\Core\Extension\SchemaInstallerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -37,6 +38,13 @@ class ModulesUninstallForm extends FormBase { */ protected $keyValueExpirable; + /** + * The schema service. + * + * @var \Drupal\Core\Extension\SchemaInstallerInterface + */ + protected $schemaInstaller; + /** * {@inheritdoc} */ @@ -44,7 +52,8 @@ public static function create(ContainerInterface $container) { return new static( $container->get('module_handler'), $container->get('module_installer'), - $container->get('keyvalue.expirable')->get('modules_uninstall') + $container->get('keyvalue.expirable')->get('modules_uninstall'), + $container->get('schema_installer') ); } @@ -57,11 +66,14 @@ public static function create(ContainerInterface $container) { * The module installer. * @param \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface $key_value_expirable * The key value expirable factory. + * @param \Drupal\Core\Extension\SchemaInstallerInterface $schema_installer + * The schema installer. */ - public function __construct(ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, KeyValueStoreExpirableInterface $key_value_expirable) { + public function __construct(ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, KeyValueStoreExpirableInterface $key_value_expirable, SchemaInstallerInterface $schema_installer) { $this->moduleHandler = $module_handler; $this->moduleInstaller = $module_installer; $this->keyValueExpirable = $key_value_expirable; + $this->schemaInstaller = $schema_installer; } /** @@ -142,7 +154,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { // All modules which depend on this one must be uninstalled first, before // we can allow this module to be uninstalled. foreach (array_keys($module->required_by) as $dependent) { - if (drupal_get_installed_schema_version($dependent) != SCHEMA_UNINSTALLED) { + if ($this->schemaInstaller->getInstalledVersion($dependent) != SchemaInstallerInterface::UNINSTALLED) { $name = isset($modules[$dependent]->info['name']) ? $modules[$dependent]->info['name'] : $dependent; $form['modules'][$module->getName()]['#required_by'][] = $name; $form['uninstall'][$module->getName()]['#disabled'] = TRUE; diff --git a/core/modules/system/src/Tests/Module/ModuleTestBase.php b/core/modules/system/src/Tests/Module/ModuleTestBase.php index e733dfa4c8..dae44f59a8 100644 --- a/core/modules/system/src/Tests/Module/ModuleTestBase.php +++ b/core/modules/system/src/Tests/Module/ModuleTestBase.php @@ -62,7 +62,7 @@ public function assertTableCount($base_table, $count = TRUE) { * The name of the module. */ public function assertModuleTablesExist($module) { - $tables = array_keys(drupal_get_module_schema($module)); + $tables = array_keys(\Drupal::service('schema_installer')->getSchema($module)); $tables_exist = TRUE; $schema = Database::getConnection()->schema(); foreach ($tables as $table) { @@ -80,7 +80,7 @@ public function assertModuleTablesExist($module) { * The name of the module. */ public function assertModuleTablesDoNotExist($module) { - $tables = array_keys(drupal_get_module_schema($module)); + $tables = array_keys(\Drupal::service('schema_installer')->getSchema($module)); $tables_exist = FALSE; $schema = Database::getConnection()->schema(); foreach ($tables as $table) { 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/system.install b/core/modules/system/system.install index ff6b8fd8ce..b967e68afb 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -723,10 +723,12 @@ function system_requirements($phase) { // Check installed modules. $has_pending_updates = FALSE; + /** @var \Drupal\Core\Extension\SchemaInstallerInterface $schema_installer */ + $schema_installer = \Drupal::service('schema_installer'); foreach (\Drupal::moduleHandler()->getModuleList() as $module => $filename) { $updates = drupal_get_schema_versions($module); if ($updates !== FALSE) { - $default = drupal_get_installed_schema_version($module); + $default = $schema_installer->getInstalledVersion($module); if (max($updates) > $default) { $has_pending_updates = TRUE; break; diff --git a/core/modules/system/tests/modules/module_test/module_test.install b/core/modules/system/tests/modules/module_test/module_test.install index 9d80d89605..9ec2788c5d 100644 --- a/core/modules/system/tests/modules/module_test/module_test.install +++ b/core/modules/system/tests/modules/module_test/module_test.install @@ -30,7 +30,7 @@ function module_test_schema() { * Implements hook_install(). */ function module_test_install() { - $schema = drupal_get_module_schema('module_test', 'module_test'); + $schema = \Drupal::service('schema_installer')->getSchema('module_test', 'module_test'); Database::getConnection()->insert('module_test') ->fields([ 'data' => $schema['fields']['data']['type'], diff --git a/core/modules/system/tests/src/Functional/Module/InstallTest.php b/core/modules/system/tests/src/Functional/Module/InstallTest.php index ccbca6d312..07063f4764 100644 --- a/core/modules/system/tests/src/Functional/Module/InstallTest.php +++ b/core/modules/system/tests/src/Functional/Module/InstallTest.php @@ -44,9 +44,9 @@ public function testEnableUserTwice() { * Tests recorded schema versions of early installed modules in the installer. */ public function testRequiredModuleSchemaVersions() { - $version = drupal_get_installed_schema_version('system', TRUE); + $version = \Drupal::service('schema_installer')->getInstalledVersion('system', TRUE); $this->assertTrue($version > 0, 'System module version is > 0.'); - $version = drupal_get_installed_schema_version('user', TRUE); + $version = \Drupal::service('schema_installer')->getInstalledVersion('user', TRUE); $this->assertTrue($version > 0, 'User module version is > 0.'); $post_update_key_value = \Drupal::keyValue('post_update'); diff --git a/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php b/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php index 40ef29fcc9..aede015045 100644 --- a/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php +++ b/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php @@ -55,7 +55,7 @@ public function assertTableCount($base_table, $count = TRUE) { * The name of the module. */ public function assertModuleTablesExist($module) { - $tables = array_keys(drupal_get_module_schema($module)); + $tables = array_keys(\Drupal::service('schema_installer')->getSchema($module)); $tables_exist = TRUE; $schema = Database::getConnection()->schema(); foreach ($tables as $table) { @@ -73,7 +73,7 @@ public function assertModuleTablesExist($module) { * The name of the module. */ public function assertModuleTablesDoNotExist($module) { - $tables = array_keys(drupal_get_module_schema($module)); + $tables = array_keys(\Drupal::service('schema_installer')->getSchema($module)); $tables_exist = FALSE; $schema = Database::getConnection()->schema(); foreach ($tables as $table) { diff --git a/core/modules/system/tests/src/Functional/System/StatusTest.php b/core/modules/system/tests/src/Functional/System/StatusTest.php index c902a3731f..d10be88926 100644 --- a/core/modules/system/tests/src/Functional/System/StatusTest.php +++ b/core/modules/system/tests/src/Functional/System/StatusTest.php @@ -76,12 +76,12 @@ public function testStatusPage() { // Set the schema version of update_test_postupdate to a lower version, so // update_test_postupdate_update_8001() needs to be executed. - drupal_set_installed_schema_version('update_test_postupdate', 8000); + \Drupal::service('schema_installer')->setInstalledVersion('update_test_postupdate', 8000); $this->drupalGet('admin/reports/status'); $this->assertText(t('Out of date')); // Now cleanup the executed post update functions. - drupal_set_installed_schema_version('update_test_postupdate', 8001); + \Drupal::service('schema_installer')->setInstalledVersion('update_test_postupdate', 8001); /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */ $post_update_registry = \Drupal::service('update.post_update_registry'); $post_update_registry->filterOutInvokedUpdatesByModule('update_test_postupdate'); diff --git a/core/modules/system/tests/src/Functional/Update/UpdatePathRC1TestBaseTest.php b/core/modules/system/tests/src/Functional/Update/UpdatePathRC1TestBaseTest.php index da53ba6e63..53d04b06cc 100644 --- a/core/modules/system/tests/src/Functional/Update/UpdatePathRC1TestBaseTest.php +++ b/core/modules/system/tests/src/Functional/Update/UpdatePathRC1TestBaseTest.php @@ -39,7 +39,7 @@ public function testDatabaseLoaded() { 'system' => '8013', ]; foreach ($hook_updates as $module => $schema) { - $this->assertEqual(drupal_get_installed_schema_version($module), $schema, new FormattableMarkup('Module @module schema is @schema', ['@module' => $module, '@schema' => $schema])); + $this->assertEqual(\Drupal::service('schema_installer')->getInstalledVersion($module), $schema, new FormattableMarkup('Module @module schema is @schema', ['@module' => $module, '@schema' => $schema])); } // Test post_update key value stores contains a list of the update functions diff --git a/core/modules/system/tests/src/Functional/Update/UpdateSchemaTest.php b/core/modules/system/tests/src/Functional/Update/UpdateSchemaTest.php index e35d52b04c..0b82cb104a 100644 --- a/core/modules/system/tests/src/Functional/Update/UpdateSchemaTest.php +++ b/core/modules/system/tests/src/Functional/Update/UpdateSchemaTest.php @@ -46,9 +46,11 @@ protected function setUp() { */ public function testUpdateHooks() { $connection = Database::getConnection(); + /** @var \Drupal\Core\Extension\SchemaInstallerInterface $schema_installer */ + $schema_installer = \Drupal::service('schema_installer'); // Verify that the 8000 schema is in place. - $this->assertEqual(drupal_get_installed_schema_version('update_test_schema'), 8000); + $this->assertEqual($schema_installer->getInstalledVersion('update_test_schema'), 8000); $this->assertFalse($connection->schema()->indexExists('update_test_schema_table', 'test'), 'Version 8000 of the update_test_schema module is installed.'); // Increment the schema version. @@ -63,7 +65,7 @@ public function testUpdateHooks() { $this->checkForMetaRefresh(); // Ensure schema has changed. - $this->assertEqual(drupal_get_installed_schema_version('update_test_schema', TRUE), 8001); + $this->assertEqual($schema_installer->getInstalledVersion('update_test_schema', TRUE), 8001); // Ensure the index was added for column a. $this->assertTrue($connection->schema()->indexExists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.'); @@ -71,7 +73,7 @@ public function testUpdateHooks() { require_once $this->root . '/core/includes/update.inc'; update_set_schema('update_test_schema', 8003); // Ensure schema has changed. - $this->assertEqual(drupal_get_installed_schema_version('update_test_schema'), 8003); + $this->assertEqual($schema_installer->getInstalledVersion('update_test_schema'), 8003); } diff --git a/core/modules/system/tests/src/Functional/Update/UpdateScriptTest.php b/core/modules/system/tests/src/Functional/Update/UpdateScriptTest.php index 8f538795ef..b3ce07014f 100644 --- a/core/modules/system/tests/src/Functional/Update/UpdateScriptTest.php +++ b/core/modules/system/tests/src/Functional/Update/UpdateScriptTest.php @@ -112,7 +112,7 @@ public function testRequirements() { // First, run this test with pending updates to make sure they can be run // successfully. $update_script_test_config->set('requirement_type', REQUIREMENT_WARNING)->save(); - drupal_set_installed_schema_version('update_script_test', drupal_get_installed_schema_version('update_script_test') - 1); + \Drupal::service('schema_installer')->setInstalledVersion('update_script_test', \Drupal::service('schema_installer')->getInstalledVersion('update_script_test') - 1); $this->drupalGet($this->updateUrl, ['external' => TRUE]); $this->assertText('This is a requirements warning provided by the update_script_test module.'); $this->clickLink('try again'); @@ -208,12 +208,14 @@ public function testSuccessfulUpdateFunctionality() { $this->assertEqual($final_maintenance_mode, $initial_maintenance_mode, 'Maintenance mode should not have changed after database updates.'); // Reset the static cache to ensure we have the most current setting. - $schema_version = drupal_get_installed_schema_version('update_script_test', TRUE); + /** @var \Drupal\Core\Extension\SchemaInstallerInterface $schema_installer */ + $schema_installer = \Drupal::service('schema_installer'); + $schema_version = $schema_installer->getInstalledVersion('update_script_test'); $this->assertEqual($schema_version, 8001, 'update_script_test schema version is 8001 after updating.'); // Set the installed schema version to one less than the current update. - drupal_set_installed_schema_version('update_script_test', $schema_version - 1); - $schema_version = drupal_get_installed_schema_version('update_script_test', TRUE); + $schema_installer->setInstalledVersion('update_script_test', $schema_version - 1); + $schema_version = $schema_installer->getInstalledVersion('update_script_test'); $this->assertEqual($schema_version, 8000, 'update_script_test schema version overridden to 8000.'); // Click through update.php with 'access administration pages' and @@ -267,12 +269,12 @@ public function testSuccessfulMultilingualUpdateFunctionality() { $config->save(); // Reset the static cache to ensure we have the most current setting. - $schema_version = drupal_get_installed_schema_version('update_script_test', TRUE); + $schema_version = \Drupal::service('schema_installer')->getInstalledVersion('update_script_test', TRUE); $this->assertEqual($schema_version, 8001, 'update_script_test schema version is 8001 after updating.'); // Set the installed schema version to one less than the current update. - drupal_set_installed_schema_version('update_script_test', $schema_version - 1); - $schema_version = drupal_get_installed_schema_version('update_script_test', TRUE); + \Drupal::service('schema_installer')->setInstalledVersion('update_script_test', $schema_version - 1); + $schema_version = \Drupal::service('schema_installer')->getInstalledVersion('update_script_test', TRUE); $this->assertEqual($schema_version, 8000, 'update_script_test schema version overridden to 8000.'); // Create admin user. @@ -303,12 +305,12 @@ public function testSuccessfulMultilingualUpdateFunctionality() { * Helper function to run updates via the browser. */ protected function runUpdates($maintenance_mode) { - $schema_version = drupal_get_installed_schema_version('update_script_test'); + $schema_version = \Drupal::service('schema_installer')->getInstalledVersion('update_script_test'); $this->assertEqual($schema_version, 8001, 'update_script_test is initially installed with schema version 8001.'); // Set the installed schema version to one less than the current update. - drupal_set_installed_schema_version('update_script_test', $schema_version - 1); - $schema_version = drupal_get_installed_schema_version('update_script_test', TRUE); + \Drupal::service('schema_installer')->setInstalledVersion('update_script_test', $schema_version - 1); + $schema_version = \Drupal::service('schema_installer')->getInstalledVersion('update_script_test', TRUE); $this->assertEqual($schema_version, 8000, 'update_script_test schema version overridden to 8000.'); // Click through update.php with 'administer software updates' permission. diff --git a/core/modules/system/tests/src/Functional/Update/UpdatesWith7xTest.php b/core/modules/system/tests/src/Functional/Update/UpdatesWith7xTest.php index 4f536ea5aa..2fdef15545 100644 --- a/core/modules/system/tests/src/Functional/Update/UpdatesWith7xTest.php +++ b/core/modules/system/tests/src/Functional/Update/UpdatesWith7xTest.php @@ -39,11 +39,11 @@ protected function setUp() { public function testWith7x() { // Ensure that the minimum schema version is 8000, despite 7200 update // hooks and a 7XXX hook_update_last_removed(). - $this->assertEqual(drupal_get_installed_schema_version('update_test_with_7x'), 8000); + $this->assertEqual(\Drupal::service('schema_installer')->getInstalledVersion('update_test_with_7x'), 8000); // Try to manually set the schema version to 7110 and ensure that no // updates are allowed. - drupal_set_installed_schema_version('update_test_with_7x', 7110); + \Drupal::service('schema_installer')->setInstalledVersion('update_test_with_7x', 7110); // Click through update.php with 'administer software updates' permission. $this->drupalLogin($this->updateUser); diff --git a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php index 976032e050..39b361e9ba 100644 --- a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php +++ b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php @@ -4,6 +4,7 @@ use Drupal\Core\Extension\MissingDependencyException; use Drupal\Core\Extension\ModuleUninstallValidatorException; +use Drupal\Core\Extension\SchemaInstallerInterface; use Drupal\entity_test\Entity\EntityTest; use Drupal\KernelTests\KernelTestBase; @@ -125,8 +126,10 @@ public function testDependencyResolution() { $result = $this->moduleInstaller()->uninstall(['config', 'help', 'color']); $this->assertTrue($result, 'ModuleInstaller::uninstall() returned TRUE.'); + /** @var \Drupal\Core\Extension\SchemaInstallerInterface $schema_installer */ + $schema_installer = \Drupal::service('schema_installer'); foreach (['color', 'config', 'help'] as $module) { - $this->assertEqual(drupal_get_installed_schema_version($module), SCHEMA_UNINSTALLED, "$module module was uninstalled."); + $this->assertEqual($schema_installer->getInstalledVersion($module), SchemaInstallerInterface::UNINSTALLED, "$module module was uninstalled."); } $uninstalled_modules = \Drupal::state()->get('module_test.uninstall_order') ?: []; $this->assertEqual($uninstalled_modules, ['color', 'config', 'help'], 'Modules were uninstalled in the correct order.'); @@ -182,7 +185,7 @@ public function testUninstallProfileDependencyBC() { $result = $this->moduleInstaller()->uninstall([$dependency]); $this->assertTrue($result, 'ModuleInstaller::uninstall() returns TRUE.'); $this->assertFalse($this->moduleHandler()->moduleExists($dependency)); - $this->assertEqual(drupal_get_installed_schema_version($dependency), SCHEMA_UNINSTALLED, "$dependency module was uninstalled."); + $this->assertEqual(\Drupal::service('schema_installer')->getInstalledVersion($dependency), SchemaInstallerInterface::UNINSTALLED, "$dependency module was uninstalled."); // Verify that the installation profile itself was not uninstalled. $uninstalled_modules = \Drupal::state()->get('module_test.uninstall_order') ?: []; @@ -217,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), SCHEMA_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') ?: []; @@ -311,7 +314,7 @@ public function testUninstallContentDependency() { $result = $this->moduleInstaller()->uninstall(['help']); $this->assertTrue($result, 'ModuleInstaller::uninstall() returns TRUE.'); - $this->assertEqual(drupal_get_installed_schema_version('entity_test'), SCHEMA_UNINSTALLED, "entity_test module was uninstalled."); + $this->assertEqual(\Drupal::service('schema_installer')->getInstalledVersion('entity_test'), SchemaInstallerInterface::UNINSTALLED, "entity_test module was uninstalled."); } /** diff --git a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php index 1d7462d757..20e2ea26bf 100644 --- a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php @@ -35,9 +35,10 @@ protected function setDatabaseDumpFiles() { public function testDatabaseLoaded() { // Set a value in the cache to prove caches are cleared. \Drupal::service('cache.default')->set(__CLASS__, 'Test'); - + /** @var \Drupal\Core\Extension\SchemaInstallerInterface $schema_installer */ + $schema_installer = \Drupal::service('schema_installer'); foreach (['user', 'node', 'system', 'update_test_schema'] as $module) { - $this->assertEqual(drupal_get_installed_schema_version($module), 8000, new FormattableMarkup('Module @module schema is 8000', ['@module' => $module])); + $this->assertEqual($schema_installer->getInstalledVersion($module), 8000, new FormattableMarkup('Module @module schema is 8000', ['@module' => $module])); } // Ensure that all {router} entries can be unserialized. If they cannot be @@ -98,7 +99,7 @@ public function testUpdateHookN() { $this->assertEqual([], $container_cannot_be_saved_messages); // Ensure schema has changed. - $this->assertEqual(drupal_get_installed_schema_version('update_test_schema', TRUE), 8001); + $this->assertEqual(\Drupal::service('schema_installer')->getInstalledVersion('update_test_schema', TRUE), 8001); // Ensure the index was added for column a. $this->assertTrue($connection->schema()->indexExists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.'); } diff --git a/core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php b/core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php index 13ef94e4cb..98ecb2ae6f 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php @@ -18,7 +18,7 @@ public function testDefaultInsert() { $query = $this->connection->insert('test')->useDefaults(['job']); $id = $query->execute(); - $schema = drupal_get_module_schema('database_test', 'test'); + $schema = \Drupal::service('schema_installer')->getSchema('database_test', 'test'); $job = db_query('SELECT job FROM {test} WHERE id = :id', [':id' => $id])->fetchField(); $this->assertEqual($job, $schema['fields']['job']['default'], 'Default field value is set.'); @@ -52,7 +52,7 @@ public function testDefaultInsertWithFields() { ->useDefaults(['job']); $id = $query->execute(); - $schema = drupal_get_module_schema('database_test', 'test'); + $schema = \Drupal::service('schema_installer')->getSchema('database_test', 'test'); $job = db_query('SELECT job FROM {test} WHERE id = :id', [':id' => $id])->fetchField(); $this->assertEqual($job, $schema['fields']['job']['default'], 'Default field value is set.'); diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index acf85fd590..4e34f2388e 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -714,8 +714,9 @@ protected function installSchema($module, $tables) { throw new \LogicException("$module module is not enabled."); } $tables = (array) $tables; + $schema_installer = \Drupal::service('schema_installer'); foreach ($tables as $table) { - $schema = drupal_get_module_schema($module, $table); + $schema = $schema_installer->getSchema($module, $table); if (empty($schema)) { // BC layer to avoid some contrib tests to fail. if ($module == 'system') {