From d67a1b252e71042107adf537af36e89ceafd5e34 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Sat, 8 Jan 2022 10:22:25 +0000 Subject: [PATCH] Issue #3256687 by mondrake, murilohp, daffie, alexpott, catch: Deprecate db_installer_object() --- core/includes/install.core.inc | 4 ++-- core/includes/install.inc | 12 +++++++++--- .../InstallerDependenciesResolutionTest.php | 3 +++ .../FunctionalTests/Update/UpdatePathTestBase.php | 8 +++----- core/tests/Drupal/KernelTests/KernelTestBase.php | 6 +++--- .../Tests/Core/Database/InstallerObjectTest.php | 2 ++ 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 6c492363da77..a3e1c9489566 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1209,8 +1209,8 @@ function install_database_errors($database, $settings_file) { // Run tasks associated with the database type. Any errors are caught in the // calling function. Database::addConnectionInfo('default', 'default', $database); - - $errors = db_installer_object($driver, $database['namespace'] ?? NULL)->runTasks(); + $installer_class = $database['namespace'] . "\\Install\\Tasks"; + $errors = (new $installer_class())->runTasks(); } return $errors; } diff --git a/core/includes/install.inc b/core/includes/install.inc index f85499042f8e..2b3232942c33 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -202,8 +202,7 @@ function drupal_get_database_types() { if (file_exists($tasks_file)) { $namespace = 'Drupal\\' . $module->getName() . '\\Driver\\Database\\' . $driver_file->filename; - // The namespace needs to be added for db_installer_object() to find - // it. + // Add the driver with its own classes' namespace. $drivers[$driver_file->filename] = $namespace; // The directory needs to be added to the autoloader, because this is @@ -217,7 +216,8 @@ function drupal_get_database_types() { } foreach ($drivers as $driver => $namespace) { - $installer = db_installer_object($driver, $namespace); + $installer_class = $namespace . "\\Install\\Tasks"; + $installer = new $installer_class(); if ($installer->installable()) { $databases[$driver] = $installer; } @@ -1167,10 +1167,16 @@ function install_profile_info($profile, $langcode = 'en') { * @return \Drupal\Core\Database\Install\Tasks * A class defining the requirements and tasks for installing the database. * + * @deprecated in drupal:10.0.0 and is removed from drupal:11.0.0. There is no + * replacement. + * + * @see https://www.drupal.org/node/3256641 * @see drupal_get_database_types() * @see \Drupal\Core\Site\Settings::initialize() */ function db_installer_object($driver, $namespace = NULL) { + @trigger_error('db_installer_object() is deprecated in drupal:10.0.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3256641', E_USER_DEPRECATED); + // We cannot use Database::getConnection->getDriverClass() here, because // the connection object is not yet functional. if ($namespace) { diff --git a/core/modules/system/tests/src/Kernel/Installer/InstallerDependenciesResolutionTest.php b/core/modules/system/tests/src/Kernel/Installer/InstallerDependenciesResolutionTest.php index 065ff69bea4c..73ec8999f94c 100644 --- a/core/modules/system/tests/src/Kernel/Installer/InstallerDependenciesResolutionTest.php +++ b/core/modules/system/tests/src/Kernel/Installer/InstallerDependenciesResolutionTest.php @@ -30,6 +30,9 @@ public function testDependenciesResolution() { assert($profile_list instanceof ProfileExtensionList); $profile_list->setPathname('testing_missing_dependencies', 'core/profiles/testing_missing_dependencies/testing_missing_dependencies.info.yml'); + // Requires install.inc to be able to use drupal_verify_profile. + require_once dirname(__FILE__, 7) . '/includes/install.inc'; + $info = drupal_verify_profile([ 'parameters' => ['profile' => 'testing_missing_dependencies'], 'profile_info' => install_profile_info('testing_missing_dependencies'), diff --git a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php index 22b6aeabc73b..301ac93c3a08 100644 --- a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php +++ b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php @@ -286,11 +286,9 @@ protected function runDbTasks() { ->addArgument(new Reference('language.default')); \Drupal::setContainer($container); - require_once __DIR__ . '/../../../../includes/install.inc'; - $connection_info = Database::getConnectionInfo(); - $driver = $connection_info['default']['driver']; - $namespace = $connection_info['default']['namespace'] ?? NULL; - $errors = db_installer_object($driver, $namespace)->runTasks(); + // Run database tasks and check for errors. + $installer_class = Database::getConnectionInfo()['default']['namespace'] . "\\Install\\Tasks"; + $errors = (new $installer_class())->runTasks(); if (!empty($errors)) { $this->fail('Failed to run installer database tasks: ' . implode(', ', $errors)); } diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index a75d45758cc0..148c6d3d9418 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -378,9 +378,9 @@ private function bootKernel() { $this->container = $kernel->getContainer(); - // Ensure database tasks have been run. - require_once __DIR__ . '/../../../includes/install.inc'; - $errors = db_installer_object($driver, $namespace)->runTasks(); + // Run database tasks and check for errors. + $installer_class = $namespace . "\\Install\\Tasks"; + $errors = (new $installer_class())->runTasks(); if (!empty($errors)) { $this->fail('Failed to run installer database tasks: ' . implode(', ', $errors)); } diff --git a/core/tests/Drupal/Tests/Core/Database/InstallerObjectTest.php b/core/tests/Drupal/Tests/Core/Database/InstallerObjectTest.php index 278ace0becd4..80f8a4070599 100644 --- a/core/tests/Drupal/Tests/Core/Database/InstallerObjectTest.php +++ b/core/tests/Drupal/Tests/Core/Database/InstallerObjectTest.php @@ -21,6 +21,7 @@ * @preserveGlobalState disabled * * @group Database + * @group legacy */ class InstallerObjectTest extends UnitTestCase { @@ -42,6 +43,7 @@ protected function setUp(): void { * @dataProvider providerDbInstallerObject */ public function testDbInstallerObject($driver, $namespace, $expected_class_name) { + $this->expectDeprecation('db_installer_object() is deprecated in drupal:10.0.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3256641'); $object = db_installer_object($driver, $namespace); $this->assertEquals(get_class($object), $expected_class_name); } -- GitLab