diff --git a/core/includes/database.inc b/core/includes/database.inc index ef94fddfb1458fe6a09d8150095446828a6bfd36..1abbe843b65acf23078eed8153c567afb0ec468e 100644 --- a/core/includes/database.inc +++ b/core/includes/database.inc @@ -739,23 +739,6 @@ function db_rename_table($table, $new_name) { return Database::getConnection()->schema()->renameTable($table, $new_name); } -/** - * Copies the structure of a table. - * - * @param string $source - * The name of the table to be copied. - * @param string $destination - * The name for the new table. - * - * @return \Drupal\Core\Database\StatementInterface - * The result of the executed query. - * - * @see \Drupal\Core\Database\Schema::copyTable() - */ -function db_copy_table_schema($source, $destination) { - return Database::getConnection()->schema()->copyTable($source, $destination); -} - /** * Drops a table. * diff --git a/core/lib/Drupal/Core/Database/Driver/fake/FakeDatabaseSchema.php b/core/lib/Drupal/Core/Database/Driver/fake/FakeDatabaseSchema.php index 8d8ea092c180568f8ad4239c13d29bf16c56cce5..d3e916166c7098b70e4fb94367af708e6930b7ea 100644 --- a/core/lib/Drupal/Core/Database/Driver/fake/FakeDatabaseSchema.php +++ b/core/lib/Drupal/Core/Database/Driver/fake/FakeDatabaseSchema.php @@ -102,13 +102,6 @@ public function __clone() { throw new \Exception(sprintf('Unsupported method "%s"', __METHOD__)); } - /** - * {@inheritdoc} - */ - public function copyTable($source, $destination) { - throw new \Exception(sprintf('Unsupported method "%s"', __METHOD__)); - } - /** * {@inheritdoc} */ diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php index 0945fd40f1440a5b095e51f72f426dc7d3b590dc..81b56a247ae4df816fa9e8450ae697795ccfecf0 100644 --- a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php @@ -308,21 +308,6 @@ public function dropTable($table) { return TRUE; } - /** - * {@inheritdoc} - */ - public function copyTable($source, $destination) { - if (!$this->tableExists($source)) { - throw new SchemaObjectDoesNotExistException(String::format("Cannot copy @source to @destination: table @source doesn't exist.", array('@source' => $source, '@destination' => $destination))); - } - if ($this->tableExists($destination)) { - throw new SchemaObjectExistsException(String::format("Cannot copy @source to @destination: table @destination already exists.", array('@source' => $source, '@destination' => $destination))); - } - - $info = $this->getPrefixInfo($destination); - return $this->connection->query('CREATE TABLE `' . $info['table'] . '` LIKE {' . $source . '}'); - } - public function addField($table, $field, $spec, $keys_new = array()) { if (!$this->tableExists($table)) { throw new SchemaObjectDoesNotExistException(t("Cannot add field @table.@field: table doesn't exist.", array('@field' => $field, '@table' => $table))); diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php index 2190ee56f5a3b2bba0a96638609b70549e37119c..b1aa8f7dcd1942b8ae07ecfe8ab581b0a8e49cdb 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php @@ -433,16 +433,6 @@ function renameTable($table, $new_name) { $this->connection->query('ALTER TABLE {' . $table . '} RENAME TO ' . $prefixInfo['table']); } - /** - * {@inheritdoc} - */ - public function copyTable($source, $destination) { - // @TODO The server is likely going to rename indexes and constraints - // during the copy process, and it will not match our - // table_name + constraint name convention anymore. - throw new \Exception('Not implemented, see https://drupal.org/node/2061879'); - } - public function dropTable($table) { if (!$this->tableExists($table)) { return FALSE; diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php index cb836cdd9d1c245f793e67b4fd12a8fe6a46fca1..e393d1531ba263462f274015f3b9e98b9f423dc9 100644 --- a/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php @@ -273,20 +273,6 @@ public function renameTable($table, $new_name) { } } - /** - * {@inheritdoc} - */ - public function copyTable($source, $destination) { - if (!$this->tableExists($source)) { - throw new SchemaObjectDoesNotExistException(String::format("Cannot copy @source to @destination: table @source doesn't exist.", array('@source' => $source, '@destination' => $destination))); - } - if ($this->tableExists($destination)) { - throw new SchemaObjectExistsException(String::format("Cannot copy @source to @destination: table @destination already exists.", array('@source' => $source, '@destination' => $destination))); - } - - $this->createTable($destination, $this->introspectSchema($source)); - } - public function dropTable($table) { if (!$this->tableExists($table)) { return FALSE; diff --git a/core/lib/Drupal/Core/Database/Schema.php b/core/lib/Drupal/Core/Database/Schema.php index b58875600f7f149fb395d96d12808305065a1d19..cae71b86b05acbedbe764429e451cdfa70801b66 100644 --- a/core/lib/Drupal/Core/Database/Schema.php +++ b/core/lib/Drupal/Core/Database/Schema.php @@ -405,24 +405,6 @@ abstract public function renameTable($table, $new_name); */ abstract public function dropTable($table); - /** - * Copies the table schema. - * - * @param string $source - * The name of the table to be used as source. - * @param string $destination - * The name of the table to be used as destination. - * - * @return \Drupal\Core\Database\StatementInterface - * The result of the executed query. - * - * @throws \Drupal\Core\Database\SchemaObjectExistsException - * Thrown when the source table does not exist. - * @throws \Drupal\Core\Database\SchemaObjectDoesNotExistException - * Thrown when the destination table already exists. - */ - abstract public function copyTable($source, $destination); - /** * Add a new field to a table. * diff --git a/core/modules/system/src/Tests/Database/SchemaTest.php b/core/modules/system/src/Tests/Database/SchemaTest.php index 9009e723e9f8563ed47cd3b9a4dc0235a234f364..da8623d88b7ec56bf7c512a9a8201b1c1f2ab632 100644 --- a/core/modules/system/src/Tests/Database/SchemaTest.php +++ b/core/modules/system/src/Tests/Database/SchemaTest.php @@ -91,38 +91,6 @@ function testSchema() { $index_exists = Database::getConnection()->schema()->indexExists('test_table2', 'test_field'); $this->assertTrue($index_exists, 'Index was renamed.'); - // Copy the schema of the table. - db_copy_table_schema('test_table2', 'test_table3'); - - // Index should be copied. - $index_exists = Database::getConnection()->schema()->indexExists('test_table3', 'test_field'); - $this->assertTrue($index_exists, 'Index was copied.'); - - // Data should still exist on the old table but not on the new one. - $count = db_select('test_table2')->countQuery()->execute()->fetchField(); - $this->assertEqual($count, 1, 'The old table still has its content.'); - $count = db_select('test_table3')->countQuery()->execute()->fetchField(); - $this->assertEqual($count, 0, 'The new table has no content.'); - - // Ensure that the proper exceptions are thrown for db_copy_table_schema(). - $fail = FALSE; - try { - db_copy_table_schema('test_table4', 'test_table5'); - } - catch (SchemaObjectDoesNotExistException $e) { - $fail = TRUE; - } - $this->assertTrue($fail, 'Ensure that db_copy_table_schema() throws an exception when the source table does not exist.'); - - $fail = FALSE; - try { - db_copy_table_schema('test_table2', 'test_table3'); - } - catch (SchemaObjectExistsException $e) { - $fail = TRUE; - } - $this->assertTrue($fail, 'Ensure that db_copy_table_schema() throws an exception when the destination table already exists.'); - // We need the default so that we can insert after the rename. db_field_set_default('test_table2', 'test_field', 0); $this->assertFalse($this->tryInsert(), 'Insert into the old table failed.');