diff --git a/core/core.services.yml b/core/core.services.yml index 16893a85de..bbc4345aa4 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -554,8 +554,8 @@ services: - { name: module_install.uninstall_validator } arguments: ['@string_translation', '@extension.list.module', '@extension.list.theme'] lazy: true - module_required_by_database_driver_uninstall_validator: - class: Drupal\Core\Extension\ModuleRequiredByDatabaseDriverUninstallValidator + database_driver_uninstall_validator: + class: Drupal\Core\Extension\DatabaseDriverUninstallValidator tags: - { name: module_install.uninstall_validator } arguments: ['@string_translation', '@extension.list.module', '@database'] diff --git a/core/includes/install.inc b/core/includes/install.inc index ff83191582..10388de749 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -622,15 +622,13 @@ function drupal_install_system($install_state) { // When the database driver is provided by a module, then install that module. // System module declares schema and therefore depends on the database driver. - if ($connection = Database::getConnection()) { - if ($module = $connection->getModuleName()) { - $autoload = $connection->getConnectionOptions()['autoload'] ?? ''; - if (($pos = strpos($autoload, 'src/Driver/Database/')) !== FALSE) { - $module_info_yml = substr($autoload, 0, $pos) . $module . '.info.yml'; - if (file_exists($module_info_yml)) { - \Drupal::service('extension.list.module')->setPathname($module, $module_info_yml); - $kernel->getContainer()->get('module_installer')->install([$module], FALSE); - } + if ($connection = Database::getConnection() && $module = $connection->getModuleName()) { + $autoload = $connection->getConnectionOptions()['autoload'] ?? ''; + if (($pos = strpos($autoload, 'src/Driver/Database/')) !== FALSE) { + $module_info_yml = substr($autoload, 0, $pos) . $module . '.info.yml'; + if (file_exists($module_info_yml)) { + \Drupal::service('extension.list.module')->setPathname($module, $module_info_yml); + $kernel->getContainer()->get('module_installer')->install([$module], FALSE); } } } diff --git a/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php index 800837e5d0..256f5e4bfd 100644 --- a/core/lib/Drupal/Core/Database/Connection.php +++ b/core/lib/Drupal/Core/Database/Connection.php @@ -1953,9 +1953,9 @@ public static function createUrlFromConnectionOptions(array $connection_options) /** * Get the module name of the module that is providing the database driver. * - * @return string|false + * @return ?string * The module name of the module that is providing the database driver, or - * FALSE when there is no providing module. + * NULL when there is no providing module. */ public function getModuleName(): ?string { [$first, $second] = explode('\\', $this->connectionOptions['namespace'], 3); @@ -1965,7 +1965,7 @@ public function getModuleName() { // letters (e.g., "Core", "Component", "Driver") are not modules. // @see \Drupal\Core\DrupalKernel::getModuleNamespacesPsr4() // @see https://www.drupal.org/docs/8/creating-custom-modules/naming-and-placing-your-drupal-8-module#s-name-your-module - return ($first === 'Drupal' && strtolower($second) === $second) ? $second : FALSE; + return ($first === 'Drupal' && strtolower($second) === $second) ? $second : NULL; } } diff --git a/core/lib/Drupal/Core/Extension/ModuleRequiredByDatabaseDriverUninstallValidator.php b/core/lib/Drupal/Core/Extension/DatabaseDriverUninstallValidator.php similarity index 91% rename from core/lib/Drupal/Core/Extension/ModuleRequiredByDatabaseDriverUninstallValidator.php rename to core/lib/Drupal/Core/Extension/DatabaseDriverUninstallValidator.php index bd931e2b23..17400ac128 100644 --- a/core/lib/Drupal/Core/Extension/ModuleRequiredByDatabaseDriverUninstallValidator.php +++ b/core/lib/Drupal/Core/Extension/DatabaseDriverUninstallValidator.php @@ -10,7 +10,7 @@ /** * Ensures installed modules providing a database driver are not uninstalled. */ -class ModuleRequiredByDatabaseDriverUninstallValidator implements ModuleUninstallValidatorInterface { +class DatabaseDriverUninstallValidator implements ModuleUninstallValidatorInterface { use StringTranslationTrait; @@ -29,7 +29,7 @@ class ModuleRequiredByDatabaseDriverUninstallValidator implements ModuleUninstal protected $connection; /** - * Constructs a new ModuleRequiredByDatabaseDriverUninstallValidator. + * Constructs a new DatabaseDriverUninstallValidator. * * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The string translation service. diff --git a/core/lib/Drupal/Core/ProxyClass/Extension/ModuleRequiredByDatabaseDriverUninstallValidator.php b/core/lib/Drupal/Core/ProxyClass/Extension/DatabaseDriverUninstallValidator.php similarity index 83% rename from core/lib/Drupal/Core/ProxyClass/Extension/ModuleRequiredByDatabaseDriverUninstallValidator.php rename to core/lib/Drupal/Core/ProxyClass/Extension/DatabaseDriverUninstallValidator.php index b08e0d4501..2390c26f8c 100644 --- a/core/lib/Drupal/Core/ProxyClass/Extension/ModuleRequiredByDatabaseDriverUninstallValidator.php +++ b/core/lib/Drupal/Core/ProxyClass/Extension/DatabaseDriverUninstallValidator.php @@ -2,17 +2,17 @@ // @codingStandardsIgnoreFile /** - * This file was generated via php core/scripts/generate-proxy-class.php 'Drupal\Core\Extension\ModuleRequiredByDatabaseDriverUninstallValidator' "core/lib/Drupal/Core". + * This file was generated via php core/scripts/generate-proxy-class.php 'Drupal\Core\Extension\DatabaseDriverUninstallValidator' "core/lib/Drupal/Core". */ namespace Drupal\Core\ProxyClass\Extension { /** - * Provides a proxy class for \Drupal\Core\Extension\ModuleRequiredByDatabaseDriverUninstallValidator. + * Provides a proxy class for \Drupal\Core\Extension\DatabaseDriverUninstallValidator. * * @see \Drupal\Component\ProxyBuilder */ - class ModuleRequiredByDatabaseDriverUninstallValidator implements \Drupal\Core\Extension\ModuleUninstallValidatorInterface + class DatabaseDriverUninstallValidator implements \Drupal\Core\Extension\ModuleUninstallValidatorInterface { use \Drupal\Core\DependencyInjection\DependencySerializationTrait; @@ -27,7 +27,7 @@ class ModuleRequiredByDatabaseDriverUninstallValidator implements \Drupal\Core\E /** * The real proxied service, after it was lazy loaded. * - * @var \Drupal\Core\Extension\ModuleRequiredByDatabaseDriverUninstallValidator + * @var \Drupal\Core\Extension\DatabaseDriverUninstallValidator */ protected $service; diff --git a/core/tests/Drupal/KernelTests/KernelTestBaseDatabaseDriverModuleTest.php b/core/tests/Drupal/KernelTests/KernelTestBaseDatabaseDriverModuleTest.php index 1883047a59..b72e2972e2 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBaseDatabaseDriverModuleTest.php +++ b/core/tests/Drupal/KernelTests/KernelTestBaseDatabaseDriverModuleTest.php @@ -55,7 +55,7 @@ protected function getDatabaseConnectionInfo() { /** * @covers ::bootEnvironment */ - public function testDatabaseDriverModuleEnabled() { + public function testDatabaseDriverModuleEnabled(): void { $driver = Database::getConnection()->driver(); if (!in_array($driver, ['DrivertestMysql', 'DrivertestPgsql'])) { $this->markTestSkipped("This test does not support the {$driver} database driver.");