diff --git a/core/drivers/fake/fake.info.yml b/core/drivers/fake/fake.info.yml index 34d07f5..0c4fbd6 100644 --- a/core/drivers/fake/fake.info.yml +++ b/core/drivers/fake/fake.info.yml @@ -1 +1,5 @@ +# @todo Rename this driver from 'fake' to e.g. 'test_db_driver'. +# (\Drupal\fake\* lacks context.) type: driver +core: 8.x +name: Fake database driver for use in unit tests diff --git a/core/drivers/fake/src/Install/Tasks.php b/core/drivers/fake/src/Install/Tasks.php index 6a40442..709a205 100644 --- a/core/drivers/fake/src/Install/Tasks.php +++ b/core/drivers/fake/src/Install/Tasks.php @@ -8,9 +8,6 @@ namespace Drupal\fake\Install; use Drupal\Core\Database\Install\Tasks as InstallTasks; -use Drupal\Core\Database\Database; -use Drupal\mysql\Connection; -use Drupal\Core\Database\DatabaseNotFoundException; /** * Usually used to specify installation tasks but here we're only interested diff --git a/core/drivers/mysql/mysql.info.yml b/core/drivers/mysql/mysql.info.yml index 34d07f5..b6939d9 100644 --- a/core/drivers/mysql/mysql.info.yml +++ b/core/drivers/mysql/mysql.info.yml @@ -1 +1,3 @@ type: driver +core: 8.x +name: MySQL, MariaDB, Percona Server, or equivalent diff --git a/core/drivers/pgsql/pgsql.info.yml b/core/drivers/pgsql/pgsql.info.yml index 34d07f5..1e994c4 100644 --- a/core/drivers/pgsql/pgsql.info.yml +++ b/core/drivers/pgsql/pgsql.info.yml @@ -1 +1,3 @@ type: driver +core: 8.x +name: PostgreSQL diff --git a/core/drivers/sqlite/sqlite.info.yml b/core/drivers/sqlite/sqlite.info.yml index 34d07f5..288dfa4 100644 --- a/core/drivers/sqlite/sqlite.info.yml +++ b/core/drivers/sqlite/sqlite.info.yml @@ -1 +1,3 @@ type: driver +core: 8.x +name: SQLite diff --git a/core/includes/install.inc b/core/includes/install.inc index 81288c5..2b82f0b 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -135,9 +135,10 @@ function drupal_detect_database_types() { function drupal_get_database_types() { $databases = array(); $discovery = new ExtensionDiscovery(); + $discovery->setProfileDirectories(array()); foreach ($discovery->scan('driver') as $driver_name => $driver) { - drupal_classloader_register($driver_name, dirname($driver->getPathname())); + drupal_classloader_register($driver_name, $driver->getPath()); $installer = db_installer_object($driver_name); if ($installer->installable()) { diff --git a/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php index 7cbe167..ed323e5 100644 --- a/core/lib/Drupal/Core/Database/Connection.php +++ b/core/lib/Drupal/Core/Database/Connection.php @@ -635,13 +635,7 @@ protected function expandArguments(&$query, &$args) { public function getDriverClass($class) { if (empty($this->driverClasses[$class])) { $driver = $this->driver(); - if (!empty($this->connectionOptions['namespace'])) { - $driver_class = $this->connectionOptions['namespace'] . '\\' . $class; - } - else { - // Fallback for Drupal 7 settings.php. - $driver_class = "Drupal\\Core\\Database\\Driver\\{$driver}\\{$class}"; - } + $driver_class = "Drupal\\{$driver}\\{$class}"; $this->driverClasses[$class] = class_exists($driver_class) ? $driver_class : $class; } return $this->driverClasses[$class]; diff --git a/core/lib/Drupal/Core/Database/Database.php b/core/lib/Drupal/Core/Database/Database.php index a799926..7113254 100644 --- a/core/lib/Drupal/Core/Database/Database.php +++ b/core/lib/Drupal/Core/Database/Database.php @@ -255,7 +255,13 @@ */ final public static function addConnectionInfo($key, $target, array $info) { if (empty(self::$databaseInfo[$key][$target])) { - self::$databaseInfo[$key][$target] = self::parseConnectionInfo($info); + $info = self::parseConnectionInfo($info); + self::$databaseInfo[$key][$target] = $info; + + // @todo Hard-wired dependency on Composer's ClassLoader. + \ComposerAutoloaderInitDrupal8::getLoader() + // Ensure to set (replace), not add (cumulative) for each connection. + ->setPsr4('Drupal\\' . $info['driver'] . '\\', $info['path']); } } @@ -370,13 +376,7 @@ throw new DriverNotSpecifiedException('Driver not specified for this database connection: ' . $key); } - if (!empty(self::$databaseInfo[$key][$target]['namespace'])) { - $driver_class = self::$databaseInfo[$key][$target]['namespace'] . '\\Connection'; - } - else { - // Fallback for Drupal 7 settings.php. - $driver_class = "Drupal\\Core\\Database\\Driver\\{$driver}\\Connection"; - } + $driver_class = "Drupal\\$driver\\Connection"; $pdo_connection = $driver_class::open(self::$databaseInfo[$key][$target]); $new_connection = new $driver_class($pdo_connection, self::$databaseInfo[$key][$target]); diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 716ae20..da657c5 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -369,12 +369,6 @@ public function boot() { require_once DRUPAL_ROOT . '/core/includes/schema.inc'; require_once DRUPAL_ROOT . '/core/includes/entity.inc'; - // Register autoload namespaces for database drivers. - $discovery = new ExtensionDiscovery(); - foreach ($discovery->scan('driver') as $driver_name => $driver) { - drupal_classloader_register($driver_name, dirname($driver->getPathname())); - } - // Ensure that findSitePath is set. if (!$this->sitePath) { throw new \Exception('Kernel does not have site path set before calling boot()'); diff --git a/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php index e9994f5..39137fb 100644 --- a/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php +++ b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php @@ -97,7 +97,7 @@ class ExtensionDiscovery { * compatible with the current version of Drupal core. * * @param string $type - * The extension type to search for. One of 'profile', 'module', 'theme', or + * The extension type to search for. One of 'profile', 'module', 'theme', * 'theme_engine', or 'driver'. * @param bool $include_tests * (optional) Whether to explicitly include or exclude test extensions. By diff --git a/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php b/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php index 48fadf6..1b2487f 100644 --- a/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php +++ b/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php @@ -120,11 +120,17 @@ public function validateForm(array &$form, FormStateInterface $form_state) { $driver = $form_state->getValue('driver'); $database = $form_state->getValue($driver); $drivers = drupal_get_database_types(); + $reflection = new \ReflectionClass($drivers[$driver]); - $install_namespace = $reflection->getNamespaceName(); + + $database['driver'] = $driver; + // Record the effective filesystem path of this driver (without /Install). + $database['path'] = dirname(dirname($reflection->getFileName())); + // Cut the trailing \Install from namespace. + // @todo 'namespace' is theoretically obsolete now? + $install_namespace = $reflection->getNamespaceName(); $database['namespace'] = substr($install_namespace, 0, strrpos($install_namespace, '\\')); - $database['driver'] = $driver; $form_state['storage']['database'] = $database; $errors = install_database_errors($database, $form_state->getValue('settings_file'));