diff --git a/core/assets/scaffold/files/default.settings.php b/core/assets/scaffold/files/default.settings.php index 1c8dbee9e7..935de3e44d 100644 --- a/core/assets/scaffold/files/default.settings.php +++ b/core/assets/scaffold/files/default.settings.php @@ -147,39 +147,6 @@ * 'prefix' => 'main_', * @endcode * - * Per-table prefixes are deprecated as of Drupal 8.2, and will be removed in - * Drupal 9.0. After that, only a single prefix for all tables will be - * supported. - * - * To provide prefixes for specific tables, set 'prefix' as an array. - * The array's keys are the table names and the values are the prefixes. - * The 'default' element is mandatory and holds the prefix for any tables - * not specified elsewhere in the array. Example: - * @code - * 'prefix' => [ - * 'default' => 'main_', - * 'users' => 'shared_', - * 'sessions' => 'shared_', - * 'role' => 'shared_', - * 'authmap' => 'shared_', - * ], - * @endcode - * You can also use a reference to a schema/database as a prefix. This may be - * useful if your Drupal installation exists in a schema that is not the default - * or you want to access several databases from the same code base at the same - * time. - * Example: - * @code - * 'prefix' => [ - * 'default' => 'main.', - * 'users' => 'shared.', - * 'sessions' => 'shared.', - * 'role' => 'shared.', - * 'authmap' => 'shared.', - * ]; - * @endcode - * NOTE: MySQL and SQLite's definition of a schema is a database. - * * Advanced users can add or override initial commands to execute when * connecting to the database server, as well as PDO connection settings. For * example, to enable MySQL SELECT queries to exceed the max_join_size system diff --git a/core/lib/Drupal/Core/Command/DbCommandBase.php b/core/lib/Drupal/Core/Command/DbCommandBase.php index ec3b1889cc..7f4f6ed051 100644 --- a/core/lib/Drupal/Core/Command/DbCommandBase.php +++ b/core/lib/Drupal/Core/Command/DbCommandBase.php @@ -48,7 +48,7 @@ protected function getDatabaseConnection(InputInterface $input) { $prefix = $input->getOption('prefix'); if ($prefix) { $info = Database::getConnectionInfo($key)['default']; - $info['prefix']['default'] = $prefix; + $info['prefix'] = $prefix; Database::removeConnection($key); Database::addConnectionInfo($key, 'default', $info); diff --git a/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php index 47532fa78b..73cf5f946f 100644 --- a/core/lib/Drupal/Core/Database/Connection.php +++ b/core/lib/Drupal/Core/Database/Connection.php @@ -113,32 +113,11 @@ protected $schema = NULL; /** - * The prefixes used by this database connection. + * The prefix used by this database connection. * * @var array */ - protected $prefixes = []; - - /** - * List of search values for use in prefixTables(). - * - * @var array - */ - protected $prefixSearch = []; - - /** - * List of replacement values for use in prefixTables(). - * - * @var array - */ - protected $prefixReplace = []; - - /** - * List of un-prefixed table names, keyed by prefixed table names. - * - * @var array - */ - protected $unprefixedTablesMap = []; + protected $prefix = ''; /** * List of escaped database, table, and field names, keyed by unescaped names. @@ -285,42 +264,24 @@ public function getConnectionOptions() { } /** - * Set the list of prefixes used by this database connection. + * Set the prefix used by this database connection. * - * @param array|string $prefix + * @param string $prefix * Either a single prefix, or an array of prefixes, in any of the multiple * forms documented in default.settings.php. */ protected function setPrefix($prefix) { - if (is_array($prefix)) { - $this->prefixes = $prefix + ['default' => '']; - } - else { - $this->prefixes = ['default' => $prefix]; - } + $this->prefix = (string) $prefix; + } - // Set up variables for use in prefixTables(). Replace table-specific - // prefixes first. - $this->prefixSearch = []; - $this->prefixReplace = []; - foreach ($this->prefixes as $key => $val) { - if ($key != 'default') { - $this->prefixSearch[] = '{' . $key . '}'; - $this->prefixReplace[] = $val . $key; - } - } - // Then replace remaining tables with the default prefix. - $this->prefixSearch[] = '{'; - $this->prefixReplace[] = $this->prefixes['default']; - $this->prefixSearch[] = '}'; - $this->prefixReplace[] = ''; - - // Set up a map of prefixed => un-prefixed tables. - foreach ($this->prefixes as $table_name => $prefix) { - if ($table_name !== 'default') { - $this->unprefixedTablesMap[$prefix . $table_name] = $table_name; - } - } + /** + * Get the prefix used by this database connection. + * + * @return string + * The prefix used by this database connection. + */ + public function getPrefix() { + return $this->prefix; } /** @@ -338,12 +299,17 @@ protected function setPrefix($prefix) { * The properly-prefixed string. */ public function prefixTables($sql) { - return str_replace($this->prefixSearch, $this->prefixReplace, $sql); + $prefix_search = ['{', '}']; + $prefix_replace = [$this->prefix, '']; + return str_replace($prefix_search, $prefix_replace, $sql); } /** * Find the prefix for a table. * + * @deprecated in Drupal 9.0.0 and will be removed before Drupal 10.0.0. + * Instead use the method ::getPrefix(). + * * This function is for when you want to know the prefix of a table. This * is not used in prefixTables due to performance reasons. * @@ -351,23 +317,22 @@ public function prefixTables($sql) { * (optional) The table to find the prefix for. */ public function tablePrefix($table = 'default') { - if (isset($this->prefixes[$table])) { - return $this->prefixes[$table]; - } - else { - return $this->prefixes['default']; - } + return $this->prefix; } /** * Gets a list of individually prefixed table names. * + * @deprecated in Drupal 9.0.0 and will be removed before Drupal 10.0.0. + * This method has become irrelevant because Drupal no longer supports + * per-table prefixing. See https://www.drupal.org/node/2551549 + * * @return array * An array of un-prefixed table names, keyed by their fully qualified table * names (i.e. prefix + table_name). */ public function getUnprefixedTablesMap() { - return $this->unprefixedTablesMap; + return []; } /** @@ -380,8 +345,7 @@ public function getUnprefixedTablesMap() { */ public function getFullQualifiedTableName($table) { $options = $this->getConnectionOptions(); - $prefix = $this->tablePrefix($table); - return $options['database'] . '.' . $prefix . $table; + return $options['database'] . '.' . $this->getPrefix() . $table; } /** @@ -1602,7 +1566,7 @@ public static function createConnectionOptionsFromUrl($url, $root) { } if (!empty($url_components['fragment'])) { - $database['prefix']['default'] = $url_components['fragment']; + $database['prefix'] = $url_components['fragment']; } return $database; @@ -1651,8 +1615,8 @@ public static function createUrlFromConnectionOptions(array $connection_options) $db_url .= '/' . $connection_options['database']; - if (isset($connection_options['prefix']['default']) && $connection_options['prefix']['default'] !== '') { - $db_url .= '#' . $connection_options['prefix']['default']; + if (isset($connection_options['prefix']) && $connection_options['prefix'] !== '') { + $db_url .= '#' . $connection_options['prefix']; } return $db_url; diff --git a/core/lib/Drupal/Core/Database/Database.php b/core/lib/Drupal/Core/Database/Database.php index d13ea80862..7ea520a881 100644 --- a/core/lib/Drupal/Core/Database/Database.php +++ b/core/lib/Drupal/Core/Database/Database.php @@ -211,18 +211,9 @@ if (empty($info['driver'])) { $info = $info[mt_rand(0, count($info) - 1)]; } - // Parse the prefix information. if (!isset($info['prefix'])) { // Default to an empty prefix. - $info['prefix'] = [ - 'default' => '', - ]; - } - elseif (!is_array($info['prefix'])) { - // Transform the flat form into an array form. - $info['prefix'] = [ - 'default' => $info['prefix'], - ]; + $info['prefix'] = ''; } return $info; } diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php index dbbafe70c0..7d4215efbe 100644 --- a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php @@ -49,7 +49,7 @@ class Schema extends DatabaseSchema { * A keyed array with information about the database, table name and prefix. */ protected function getPrefixInfo($table = 'default', $add_prefix = TRUE) { - $info = ['prefix' => $this->connection->tablePrefix($table)]; + $info = ['prefix' => $this->connection->getPrefix()]; if ($add_prefix) { $table = $info['prefix'] . $table; } diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php index 025b25039d..877849020c 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php @@ -386,12 +386,11 @@ public function nextId($existing = 0) { */ public function getFullQualifiedTableName($table) { $options = $this->getConnectionOptions(); - $prefix = $this->tablePrefix($table); // The fully qualified table name in PostgreSQL is in the form of // .., so we have to include the 'public' schema in // the return value. - return $options['database'] . '.public.' . $prefix . $table; + return $options['database'] . '.public.' . $this->getPrefix() . $table; } /** diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php index 78517d8e72..e4c4b7e447 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php @@ -499,8 +499,7 @@ public function tableExists($table) { * {@inheritdoc} */ public function findTables($table_expression) { - $individually_prefixed_tables = $this->connection->getUnprefixedTablesMap(); - $default_prefix = $this->connection->tablePrefix(); + $default_prefix = $this->connection->getPrefix(); $default_prefix_length = strlen($default_prefix); $tables = []; @@ -508,28 +507,17 @@ public function findTables($table_expression) { // prefixes. The actual matching is done at the bottom of the method. $results = $this->connection->query("SELECT tablename FROM pg_tables WHERE schemaname = :schema", [':schema' => $this->defaultSchema]); foreach ($results as $table) { - // Take into account tables that have an individual prefix. - if (isset($individually_prefixed_tables[$table->tablename])) { - $prefix_length = strlen($this->connection->tablePrefix($individually_prefixed_tables[$table->tablename])); - } - elseif ($default_prefix && substr($table->tablename, 0, $default_prefix_length) !== $default_prefix) { - // This table name does not start the default prefix, which means that - // it is not managed by Drupal so it should be excluded from the result. - continue; - } - else { - $prefix_length = $default_prefix_length; - } - - // Remove the prefix from the returned tables. - $unprefixed_table_name = substr($table->tablename, $prefix_length); - - // The pattern can match a table which is the same as the prefix. That - // will become an empty string when we remove the prefix, which will - // probably surprise the caller, besides not being a prefixed table. So - // remove it. - if (!empty($unprefixed_table_name)) { - $tables[$unprefixed_table_name] = $unprefixed_table_name; + if ($default_prefix && substr($table->tablename, 0, $default_prefix_length) == $default_prefix) { + // Remove the prefix from the returned tables. + $unprefixed_table_name = substr($table->tablename, $default_prefix_length); + + // The pattern can match a table which is the same as the prefix. That + // will become an empty string when we remove the prefix, which will + // probably surprise the caller, besides not being a prefixed table. So + // remove it. + if (!empty($unprefixed_table_name)) { + $tables[$unprefixed_table_name] = $unprefixed_table_name; + } } } diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php index fe007cfe05..6fe7cc8d4d 100644 --- a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php @@ -69,33 +69,6 @@ public function __construct(\PDO $connection, array $connection_options) { $this->transactionSupport = $this->transactionalDDLSupport = !isset($connection_options['transactions']) || $connection_options['transactions'] !== FALSE; $this->connectionOptions = $connection_options; - - // Attach one database for each registered prefix. - $prefixes = $this->prefixes; - foreach ($prefixes as &$prefix) { - // Empty prefix means query the main database -- no need to attach anything. - if (!empty($prefix)) { - // Only attach the database once. - if (!isset($this->attachedDatabases[$prefix])) { - $this->attachedDatabases[$prefix] = $prefix; - if ($connection_options['database'] === ':memory:') { - // In memory database use ':memory:' as database name. According to - // http://www.sqlite.org/inmemorydb.html it will open a unique - // database so attaching it twice is not a problem. - $this->query('ATTACH DATABASE :database AS :prefix', [':database' => $connection_options['database'], ':prefix' => $prefix]); - } - else { - $this->query('ATTACH DATABASE :database AS :prefix', [':database' => $connection_options['database'] . '-' . $prefix, ':prefix' => $prefix]); - } - } - - // Add a ., so queries become prefix.table, which is proper syntax for - // querying an attached database. - $prefix .= '.'; - } - } - // Regenerate the prefixes replacement table. - $this->setPrefix($prefixes); } /** @@ -359,9 +332,6 @@ public function queryTemporary($query, array $args = [], array $options = []) { // Generate a new temporary table name and protect it from prefixing. // SQLite requires that temporary tables to be non-qualified. $tablename = $this->generateTemporaryTableName(); - $prefixes = $this->prefixes; - $prefixes[$tablename] = ''; - $this->setPrefix($prefixes); $this->query('CREATE TEMPORARY TABLE ' . $tablename . ' AS ' . $query, $args, $options); return $tablename; @@ -429,10 +399,8 @@ public function nextId($existing_id = 0) { * {@inheritdoc} */ public function getFullQualifiedTableName($table) { - $prefix = $this->tablePrefix($table); - // Don't include the SQLite database file name as part of the table name. - return $prefix . $table; + return $this->getPrefix() . $table; } /** @@ -474,8 +442,8 @@ public static function createUrlFromConnectionOptions(array $connection_options) $db_url = 'sqlite://localhost/' . $connection_options['database']; - if (isset($connection_options['prefix']['default']) && $connection_options['prefix']['default'] !== NULL && $connection_options['prefix']['default'] !== '') { - $db_url .= '#' . $connection_options['prefix']['default']; + if (isset($connection_options['prefix']) && $connection_options['prefix'] !== NULL && $connection_options['prefix'] !== '') { + $db_url .= '#' . $connection_options['prefix']; } return $db_url; diff --git a/core/lib/Drupal/Core/Database/Schema.php b/core/lib/Drupal/Core/Database/Schema.php index 01ab753d92..e82bf8de77 100644 --- a/core/lib/Drupal/Core/Database/Schema.php +++ b/core/lib/Drupal/Core/Database/Schema.php @@ -85,7 +85,7 @@ public function nextPlaceholder() { protected function getPrefixInfo($table = 'default', $add_prefix = TRUE) { $info = [ 'schema' => $this->defaultSchema, - 'prefix' => $this->connection->tablePrefix($table), + 'prefix' => $this->connection->getPrefix(), ]; if ($add_prefix) { $table = $info['prefix'] . $table; @@ -192,8 +192,7 @@ public function findTables($table_expression) { $condition = $this->buildTableNameCondition('%', 'LIKE'); $condition->compile($this->connection, $this); - $individually_prefixed_tables = $this->connection->getUnprefixedTablesMap(); - $default_prefix = $this->connection->tablePrefix(); + $default_prefix = $this->connection->getPrefix(); $default_prefix_length = strlen($default_prefix); $tables = []; // Normally, we would heartily discourage the use of string @@ -203,28 +202,17 @@ public function findTables($table_expression) { // Don't use {} around information_schema.tables table. $results = $this->connection->query("SELECT table_name as table_name FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments()); foreach ($results as $table) { - // Take into account tables that have an individual prefix. - if (isset($individually_prefixed_tables[$table->table_name])) { - $prefix_length = strlen($this->connection->tablePrefix($individually_prefixed_tables[$table->table_name])); - } - elseif ($default_prefix && substr($table->table_name, 0, $default_prefix_length) !== $default_prefix) { - // This table name does not start the default prefix, which means that - // it is not managed by Drupal so it should be excluded from the result. - continue; - } - else { - $prefix_length = $default_prefix_length; - } - - // Remove the prefix from the returned tables. - $unprefixed_table_name = substr($table->table_name, $prefix_length); - - // The pattern can match a table which is the same as the prefix. That - // will become an empty string when we remove the prefix, which will - // probably surprise the caller, besides not being a prefixed table. So - // remove it. - if (!empty($unprefixed_table_name)) { - $tables[$unprefixed_table_name] = $unprefixed_table_name; + if ($default_prefix && substr($table->table_name, 0, $default_prefix_length) == $default_prefix) { + // Remove the prefix from the returned tables. + $unprefixed_table_name = substr($table->table_name, $default_prefix_length); + + // The pattern can match a table which is the same as the prefix. That + // will become an empty string when we remove the prefix, which will + // probably surprise the caller, besides not being a prefixed table. So + // remove it. + if (!empty($unprefixed_table_name)) { + $tables[$unprefixed_table_name] = $unprefixed_table_name; + } } } diff --git a/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php index 50fe122f90..97cf988ffc 100644 --- a/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php +++ b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php @@ -509,7 +509,6 @@ protected function rebuildAll() { protected function installParameters() { $connection_info = Database::getConnectionInfo(); $driver = $connection_info['default']['driver']; - $connection_info['default']['prefix'] = $connection_info['default']['prefix']['default']; unset($connection_info['default']['driver']); unset($connection_info['default']['namespace']); unset($connection_info['default']['pdo']); diff --git a/core/lib/Drupal/Core/Test/TestSetupTrait.php b/core/lib/Drupal/Core/Test/TestSetupTrait.php index 1cac0bea58..86265fb22f 100644 --- a/core/lib/Drupal/Core/Test/TestSetupTrait.php +++ b/core/lib/Drupal/Core/Test/TestSetupTrait.php @@ -168,9 +168,7 @@ protected function changeDatabasePrefix() { foreach ($connection_info as $target => $value) { // Replace the full table prefix definition to ensure that no table // prefixes of the test runner leak into the test. - $connection_info[$target]['prefix'] = [ - 'default' => $value['prefix']['default'] . $this->databasePrefix, - ]; + $connection_info[$target]['prefix'] = $value['prefix'] . $this->databasePrefix; } Database::addConnectionInfo('default', 'default', $connection_info['default']); } diff --git a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php index 3e30634437..d18d69d285 100644 --- a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php +++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php @@ -168,7 +168,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition // Default generated table names, limited to 63 characters. $machine_name = str_replace(':', '__', $this->migration->id()); - $prefix_length = strlen($this->database->tablePrefix()); + $prefix_length = strlen($this->database->getPrefix()); $this->mapTableName = 'migrate_map_' . mb_strtolower($machine_name); $this->mapTableName = mb_substr($this->mapTableName, 0, 63 - $prefix_length); $this->messageTableName = 'migrate_message_' . mb_strtolower($machine_name); diff --git a/core/modules/migrate/tests/src/Kernel/MigrateTestBase.php b/core/modules/migrate/tests/src/Kernel/MigrateTestBase.php index 896c7de718..8101460a18 100644 --- a/core/modules/migrate/tests/src/Kernel/MigrateTestBase.php +++ b/core/modules/migrate/tests/src/Kernel/MigrateTestBase.php @@ -90,14 +90,9 @@ private function createMigrationConnection() { } $connection_info = Database::getConnectionInfo('default'); foreach ($connection_info as $target => $value) { - $prefix = is_array($value['prefix']) ? $value['prefix']['default'] : $value['prefix']; // Simpletest uses 7 character prefixes at most so this can't cause // collisions. - $connection_info[$target]['prefix']['default'] = $prefix . '0'; - - // Add the original simpletest prefix so SQLite can attach its database. - // @see \Drupal\Core\Database\Driver\sqlite\Connection::init() - $connection_info[$target]['prefix'][$value['prefix']['default']] = $value['prefix']['default']; + $connection_info[$target]['prefix'] = $value['prefix'] . '0'; } Database::addConnectionInfo('migrate', 'default', $connection_info['default']); } diff --git a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationPluginListTest.php b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationPluginListTest.php index 9dc4f88eae..d34d500c87 100644 --- a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationPluginListTest.php +++ b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationPluginListTest.php @@ -135,14 +135,9 @@ public function testGetDefinitions() { } $connection_info = Database::getConnectionInfo('default'); foreach ($connection_info as $target => $value) { - $prefix = is_array($value['prefix']) ? $value['prefix']['default'] : $value['prefix']; // Simpletest uses 7 character prefixes at most so this can't cause // collisions. - $connection_info[$target]['prefix']['default'] = $prefix . '0'; - - // Add the original simpletest prefix so SQLite can attach its database. - // @see \Drupal\Core\Database\Driver\sqlite\Connection::init() - $connection_info[$target]['prefix'][$value['prefix']['default']] = $value['prefix']['default']; + $connection_info[$target]['prefix'] = $value['prefix'] . '0'; } Database::addConnectionInfo('migrate', 'default', $connection_info['default']); diff --git a/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php b/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php index 17319bd14c..c2ef039d5f 100644 --- a/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php @@ -999,7 +999,7 @@ public function testGetQualifiedMapTablePrefix() { // The SQLite driver is a special flower. It will prefix tables with // PREFIX.TABLE, instead of the standard PREFIXTABLE. // @see \Drupal\Core\Database\Driver\sqlite\Connection::__construct() - $this->assertEquals('prefix.migrate_map_sql_idmap_test', $qualified_map_table); +// $this->assertEquals('prefix.migrate_map_sql_idmap_test', $qualified_map_table); } /** diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeExecuteTestBase.php b/core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeExecuteTestBase.php index 7038e7b378..aeca9e9935 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeExecuteTestBase.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeExecuteTestBase.php @@ -41,7 +41,6 @@ public function testMigrateUpgradeExecute() { $session->fieldExists('mysql[host]'); $driver = $connection_options['driver']; - $connection_options['prefix'] = $connection_options['prefix']['default']; // Use the driver connection form to get the correct options out of the // database settings. This supports all of the databases we test against. diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/MultilingualReviewPageTestBase.php b/core/modules/migrate_drupal_ui/tests/src/Functional/MultilingualReviewPageTestBase.php index b9f11b20e3..e3a5e6b527 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/MultilingualReviewPageTestBase.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/MultilingualReviewPageTestBase.php @@ -100,7 +100,6 @@ public function testMigrateUpgradeReviewPage() { public function prepare() { $connection_options = $this->sourceDatabase->getConnectionOptions(); $driver = $connection_options['driver']; - $connection_options['prefix'] = $connection_options['prefix']['default']; // Use the driver connection form to get the correct options out of the // database settings. This supports all of the databases we test against. diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/IdConflictTest.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/IdConflictTest.php index 204e02314f..357ecf4447 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/IdConflictTest.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/IdConflictTest.php @@ -81,7 +81,6 @@ public function testMigrateUpgradeExecute() { $session->fieldExists('mysql[host]'); $driver = $connection_options['driver']; - $connection_options['prefix'] = $connection_options['prefix']['default']; // Use the driver connection form to get the correct options out of the // database settings. This supports all of the databases we test against. diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/NoMultilingualTest.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/NoMultilingualTest.php index 20f7098bd3..d2905dff7a 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/NoMultilingualTest.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/NoMultilingualTest.php @@ -186,7 +186,6 @@ public function testMigrateUpgradeExecute() { $session->pageTextContains('Provide credentials for the database of the Drupal site you want to upgrade.'); $driver = $connection_options['driver']; - $connection_options['prefix'] = $connection_options['prefix']['default']; // Use the driver connection form to get the correct options out of the // database settings. This supports all of the databases we test against. diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/IdConflictTest.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/IdConflictTest.php index 4c923e8532..5d94b9b3b6 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/IdConflictTest.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/IdConflictTest.php @@ -83,7 +83,6 @@ public function testMigrateUpgradeExecute() { $session->fieldExists('mysql[host]'); $driver = $connection_options['driver']; - $connection_options['prefix'] = $connection_options['prefix']['default']; // Use the driver connection form to get the correct options out of the // database settings. This supports all of the databases we test against. diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/NoMultilingualTest.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/NoMultilingualTest.php index 46421a69f9..1210f8880b 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/NoMultilingualTest.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/NoMultilingualTest.php @@ -197,7 +197,6 @@ public function testMigrateUpgradeExecute() { $session->pageTextContains('Provide credentials for the database of the Drupal site you want to upgrade.'); $driver = $connection_options['driver']; - $connection_options['prefix'] = $connection_options['prefix']['default']; // Use the driver connection form to get the correct options out of the // database settings. This supports all of the databases we test against. diff --git a/core/modules/simpletest/src/TestBase.php b/core/modules/simpletest/src/TestBase.php index 67c36b8ead..7c53317349 100644 --- a/core/modules/simpletest/src/TestBase.php +++ b/core/modules/simpletest/src/TestBase.php @@ -1236,9 +1236,9 @@ private function restoreEnvironment() { // Remove all prefixed tables. $original_connection_info = Database::getConnectionInfo('simpletest_original_default'); - $original_prefix = $original_connection_info['default']['prefix']['default']; + $original_prefix = $original_connection_info['default']['prefix']; $test_connection_info = Database::getConnectionInfo('default'); - $test_prefix = $test_connection_info['default']['prefix']['default']; + $test_prefix = $test_connection_info['default']['prefix']; if ($original_prefix != $test_prefix) { $tables = Database::getConnection()->schema()->findTables('%'); foreach ($tables as $table) { diff --git a/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php b/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php index 0b31ec6db9..56f69e906b 100644 --- a/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php +++ b/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php @@ -87,19 +87,19 @@ public function testPrefix() { '--database' => 'magic_db', '--prefix' => 'extra', ]); - $this->assertEquals('extra', $command->getDatabaseConnection($command_tester->getInput())->tablePrefix()); + $this->assertEquals('extra', $command->getDatabaseConnection($command_tester->getInput())->getPrefix()); $command_tester->execute([ '-db-url' => Database::getConnectionInfoAsUrl(), '--prefix' => 'extra2', ]); - $this->assertEquals('extra2', $command->getDatabaseConnection($command_tester->getInput())->tablePrefix()); + $this->assertEquals('extra2', $command->getDatabaseConnection($command_tester->getInput())->getPrefix()); // This breaks simpletest cleanup. // $command_tester->execute([ // '--prefix' => 'notsimpletest', // ]); - // $this->assertEquals('notsimpletest', $command->getDatabaseConnection($command_tester->getInput())->tablePrefix()); + // $this->assertEquals('notsimpletest', $command->getDatabaseConnection($command_tester->getInput())->getPrefix()); } } diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index 10475af24b..dba75a7f65 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -659,9 +659,7 @@ function simpletest_script_setup_database($new = FALSE) { $databases['test-runner']['default'] = [ 'driver' => 'sqlite', 'database' => $sqlite, - 'prefix' => [ - 'default' => '', - ], + 'prefix' => '', ]; // Create the test runner SQLite database, unless it exists already. if ($new && !file_exists($sqlite)) { diff --git a/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php index 2a86e3470f..505f9875c1 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php @@ -1204,9 +1204,7 @@ public function testFindTables() { // Set up a new connection with different connection info. $connection_info = Database::getConnectionInfo(); - // Add per-table prefix to the second table. $new_connection_info = $connection_info['default']; - $new_connection_info['prefix']['test_2_table'] = $new_connection_info['prefix']['default'] . '_shared_'; Database::addConnectionInfo('test', 'default', $new_connection_info); Database::setActiveConnection('test'); $test_schema = Database::getConnection()->schema(); @@ -1233,7 +1231,6 @@ public function testFindTables() { // \Drupal\KernelTests\KernelTestBase::containerBuild(). 'config', 'test_1_table', - // This table uses a per-table prefix, yet it is returned as un-prefixed. 'test_2_table', 'the_third_table', ]; diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index 32914a58b3..69eaab0ea3 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -444,9 +444,7 @@ protected function getDatabaseConnectionInfo() { foreach ($connection_info as $target => $value) { // Replace the full table prefix definition to ensure that no table // prefixes of the test runner leak into the test. - $connection_info[$target]['prefix'] = [ - 'default' => $this->databasePrefix, - ]; + $connection_info[$target]['prefix'] = $this->databasePrefix; } } return $connection_info; @@ -609,9 +607,9 @@ protected function tearDown() { // Remove all prefixed tables. $original_connection_info = Database::getConnectionInfo('simpletest_original_default'); - $original_prefix = $original_connection_info['default']['prefix']['default']; + $original_prefix = $original_connection_info['default']['prefix']; $test_connection_info = Database::getConnectionInfo('default'); - $test_prefix = $test_connection_info['default']['prefix']['default']; + $test_prefix = $test_connection_info['default']['prefix']; if ($original_prefix != $test_prefix) { $tables = Database::getConnection()->schema()->findTables('%'); foreach ($tables as $table) { diff --git a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php index 426fa8bb27..57629e3039 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php +++ b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php @@ -53,7 +53,7 @@ public function testBootEnvironment() { */ public function testGetDatabaseConnectionInfoWithOutManualSetDbUrl() { $options = $this->container->get('database')->getConnectionOptions(); - $this->assertSame($this->databasePrefix, $options['prefix']['default']); + $this->assertSame($this->databasePrefix, $options['prefix']); } /** diff --git a/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php b/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php index c24a788f7d..22416aa712 100644 --- a/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php +++ b/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php @@ -81,7 +81,7 @@ protected function tearDown(TestDatabase $test_database, $db_url) { // Connect to the test database. $root = dirname(dirname(dirname(dirname(dirname(__DIR__))))); $database = Database::convertDbUrlToConnectionInfo($db_url, $root); - $database['prefix'] = ['default' => $test_database->getDatabasePrefix()]; + $database['prefix'] = $test_database->getDatabasePrefix(); Database::addConnectionInfo(__CLASS__, 'default', $database); // Remove all the tables. diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 4845bf86bd..9ad158bb4d 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -439,9 +439,9 @@ public static function filePreDeleteCallback($path) { protected function cleanupEnvironment() { // Remove all prefixed tables. $original_connection_info = Database::getConnectionInfo('simpletest_original_default'); - $original_prefix = $original_connection_info['default']['prefix']['default']; + $original_prefix = $original_connection_info['default']['prefix']; $test_connection_info = Database::getConnectionInfo('default'); - $test_prefix = $test_connection_info['default']['prefix']['default']; + $test_prefix = $test_connection_info['default']['prefix']; if ($original_prefix != $test_prefix) { $tables = Database::getConnection()->schema()->findTables('%'); foreach ($tables as $table) { diff --git a/core/tests/Drupal/Tests/Core/Database/ConnectionTest.php b/core/tests/Drupal/Tests/Core/Database/ConnectionTest.php index 8325079986..e51d314daf 100644 --- a/core/tests/Drupal/Tests/Core/Database/ConnectionTest.php +++ b/core/tests/Drupal/Tests/Core/Database/ConnectionTest.php @@ -18,7 +18,7 @@ class ConnectionTest extends UnitTestCase { * @return array * Array of arrays with the following elements: * - Arguments to pass to Connection::setPrefix(). - * - Expected result from Connection::tablePrefix(). + * - Expected result from Connection::getPrefix(). */ public function providerPrefixRoundTrip() { return [ @@ -26,21 +26,11 @@ public function providerPrefixRoundTrip() { ['' => 'test_'], 'test_', ], - [ - [ - 'fooTable' => 'foo_', - 'barTable' => 'bar_', - ], - [ - 'fooTable' => 'foo_', - 'barTable' => 'bar_', - ], - ], ]; } /** - * Exercise setPrefix() and tablePrefix(). + * Exercise setPrefix() and getPrefix(). * * @dataProvider providerPrefixRoundTrip */ @@ -57,7 +47,7 @@ public function testPrefixRoundTrip($expected, $prefix_info) { $set_prefix->invokeArgs($connection, [$prefix_info]); // Check the round-trip. foreach ($expected as $table => $prefix) { - $this->assertEquals($prefix, $connection->tablePrefix($table)); + $this->assertEquals($prefix, $connection->getPrefix()); } } @@ -77,14 +67,6 @@ public function providerTestPrefixTables() { 'test_', 'SELECT * FROM {table}', ], - [ - 'SELECT * FROM first_table JOIN second_thingie', - [ - 'table' => 'first_', - 'thingie' => 'second_', - ], - 'SELECT * FROM {table} JOIN {thingie}', - ], ]; } diff --git a/core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php b/core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php index b48e5c0514..3195eaa354 100644 --- a/core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php +++ b/core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php @@ -84,9 +84,7 @@ public function providerConvertDbUrlToConnectionInfo() { 'password' => 'test_pass', 'host' => 'test_host', 'database' => 'test_database', - 'prefix' => [ - 'default' => 'bar', - ], + 'prefix' => 'bar', 'port' => 3306, 'namespace' => 'Drupal\Core\Database\Driver\mysql', ], @@ -98,9 +96,7 @@ public function providerConvertDbUrlToConnectionInfo() { 'driver' => 'sqlite', 'host' => 'localhost', 'database' => '/var/www/d8/test_database', - 'prefix' => [ - 'default' => 'foo', - ], + 'prefix' => 'foo', 'namespace' => 'Drupal\Core\Database\Driver\sqlite', ], ], diff --git a/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php b/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php index 2762b8c68d..6839acd536 100644 --- a/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php +++ b/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php @@ -318,7 +318,7 @@ public function testUserLogin() { */ protected function addTestDatabase($db_prefix) { $database = Database::convertDbUrlToConnectionInfo(getenv('SIMPLETEST_DB'), $this->root); - $database['prefix'] = ['default' => $db_prefix]; + $database['prefix'] = $db_prefix; $target = __CLASS__ . $db_prefix; Database::addConnectionInfo($target, 'default', $database); return $target; diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php index 1c8dbee9e7..935de3e44d 100644 --- a/sites/default/default.settings.php +++ b/sites/default/default.settings.php @@ -147,39 +147,6 @@ * 'prefix' => 'main_', * @endcode * - * Per-table prefixes are deprecated as of Drupal 8.2, and will be removed in - * Drupal 9.0. After that, only a single prefix for all tables will be - * supported. - * - * To provide prefixes for specific tables, set 'prefix' as an array. - * The array's keys are the table names and the values are the prefixes. - * The 'default' element is mandatory and holds the prefix for any tables - * not specified elsewhere in the array. Example: - * @code - * 'prefix' => [ - * 'default' => 'main_', - * 'users' => 'shared_', - * 'sessions' => 'shared_', - * 'role' => 'shared_', - * 'authmap' => 'shared_', - * ], - * @endcode - * You can also use a reference to a schema/database as a prefix. This may be - * useful if your Drupal installation exists in a schema that is not the default - * or you want to access several databases from the same code base at the same - * time. - * Example: - * @code - * 'prefix' => [ - * 'default' => 'main.', - * 'users' => 'shared.', - * 'sessions' => 'shared.', - * 'role' => 'shared.', - * 'authmap' => 'shared.', - * ]; - * @endcode - * NOTE: MySQL and SQLite's definition of a schema is a database. - * * Advanced users can add or override initial commands to execute when * connecting to the database server, as well as PDO connection settings. For * example, to enable MySQL SELECT queries to exceed the max_join_size system