summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2018-07-24 13:57:22 (GMT)
committerAlex Pott2018-07-24 13:57:36 (GMT)
commitab302cc34c08d3f56571c2c6d95e69196207e595 (patch)
tree5aacfa0e45eeccc6c9502ac6240012dea2ad9ed0
parentc8afb674c046177f839508abd3f67c051d59112e (diff)
Issue #2848479 by voleger, yogeshmpawar, marvin_B8, gaurav.kapoor, hgunicamp, mondrake, daffie, alexpott, xjm, cilefen: Replace all calls to db_drop_table, which is deprecated
(cherry picked from commit ead36d31b82fccc47a88792cdf204f6d8bc6b763)
-rw-r--r--core/includes/database.inc1
-rw-r--r--core/includes/schema.inc10
-rw-r--r--core/modules/simpletest/simpletest.module3
-rw-r--r--core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php11
-rw-r--r--core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php35
5 files changed, 48 insertions, 12 deletions
diff --git a/core/includes/database.inc b/core/includes/database.inc
index 6891ea9..668b2a6 100644
--- a/core/includes/database.inc
+++ b/core/includes/database.inc
@@ -723,6 +723,7 @@ function db_rename_table($table, $new_name) {
* @see \Drupal\Core\Database\Schema::dropTable()
*/
function db_drop_table($table) {
+ @trigger_error('db_drop_table() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Database\Database::getConnection()->schema()->dropTable() instead. See https://www.drupal.org/node/2987737', E_USER_DEPRECATED);
return Database::getConnection()->schema()->dropTable($table);
}
diff --git a/core/includes/schema.inc b/core/includes/schema.inc
index 4c790dc..f0a104d 100644
--- a/core/includes/schema.inc
+++ b/core/includes/schema.inc
@@ -130,12 +130,12 @@ function drupal_install_schema($module) {
* The module for which the tables will be removed.
*/
function drupal_uninstall_schema($module) {
- $schema = drupal_get_module_schema($module);
- _drupal_schema_initialize($schema, $module, FALSE);
-
- foreach ($schema as $table) {
+ $tables = drupal_get_module_schema($module);
+ _drupal_schema_initialize($tables, $module, FALSE);
+ $schema = \Drupal::database()->schema();
+ foreach ($tables as $table) {
if (db_table_exists($table['name'])) {
- db_drop_table($table['name']);
+ $schema->dropTable($table['name']);
}
}
}
diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module
index c765995..0814d88 100644
--- a/core/modules/simpletest/simpletest.module
+++ b/core/modules/simpletest/simpletest.module
@@ -669,13 +669,14 @@ function simpletest_clean_environment() {
* Removes prefixed tables from the database from crashed tests.
*/
function simpletest_clean_database() {
+ $schema = Database::getConnection()->schema();
$tables = db_find_tables('test%');
$count = 0;
foreach ($tables as $table) {
// Only drop tables which begin wih 'test' followed by digits, for example,
// {test12345678node__body}.
if (preg_match('/^test\d+.*/', $table, $matches)) {
- db_drop_table($matches[0]);
+ $schema->dropTable($matches[0]);
$count++;
}
}
diff --git a/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php b/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php
index 22173da..e4cc868 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php
@@ -71,4 +71,15 @@ class RegressionTest extends DatabaseTestBase {
$this->assert(db_set_active($get_active_db), 'Database connection is active');
}
+ /**
+ * Tests the db_drop_table() function.
+ *
+ * @group legacy
+ *
+ * @expectedDeprecation db_drop_table() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Database\Database::getConnection()->schema()->dropTable() instead. See https://www.drupal.org/node/2987737
+ */
+ public function testDbDropTable() {
+ $this->assertFalse(db_drop_table('temp_test_table'));
+ }
+
}
diff --git a/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
index 259f5f5..01040fb 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
@@ -24,6 +24,29 @@ class SchemaTest extends KernelTestBase {
protected $counter;
/**
+ * Connection to the database.
+ *
+ * @var \Drupal\Core\Database\Connection
+ */
+ protected $connection;
+
+ /**
+ * Database schema instance.
+ *
+ * @var \Drupal\Core\Database\Schema
+ */
+ protected $schema;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ parent::setUp();
+ $this->connection = Database::getConnection();
+ $this->schema = $this->connection->schema();
+ }
+
+ /**
* Tests database interactions.
*/
public function testSchema() {
@@ -121,7 +144,7 @@ class SchemaTest extends KernelTestBase {
$this->assertEqual($count, 2, 'Two fields were successfully inserted.');
// Try to drop the table.
- db_drop_table('test_table2');
+ $this->schema->dropTable('test_table2');
$this->assertFalse(db_table_exists('test_table2'), 'The dropped table does not exist.');
// Recreate the table.
@@ -148,7 +171,7 @@ class SchemaTest extends KernelTestBase {
$this->assertEqual($count, 2, 'There were two rows.');
// Test adding a serial field to an existing table.
- db_drop_table('test_table');
+ $this->schema->dropTable('test_table');
db_create_table('test_table', $table_specification);
db_field_set_default('test_table', 'test_field', 0);
db_add_field('test_table', 'test_serial', ['type' => 'serial', 'not null' => TRUE], ['primary key' => ['test_serial']]);
@@ -174,7 +197,7 @@ class SchemaTest extends KernelTestBase {
$this->assertSame(['test_serial', 'test_composite_primary_key'], $method->invoke($schema, 'test_table'));
// Test renaming of keys and constraints.
- db_drop_table('test_table');
+ $this->schema->dropTable('test_table');
$table_specification = [
'fields' => [
'id' => [
@@ -606,7 +629,7 @@ class SchemaTest extends KernelTestBase {
$this->assertFieldCharacteristics($table_name, 'test_field', $field_spec);
// Clean-up.
- db_drop_table($table_name);
+ $this->schema->dropTable($table_name);
// Try adding a field to an existing table.
$table_name = 'test_table_' . ($this->counter++);
@@ -646,7 +669,7 @@ class SchemaTest extends KernelTestBase {
// key.
db_add_field($table_name, 'test_field', $field_spec);
db_drop_field($table_name, 'serial_column');
- db_drop_table($table_name);
+ $this->schema->dropTable($table_name);
}
/**
@@ -968,7 +991,7 @@ class SchemaTest extends KernelTestBase {
$this->assertFieldCharacteristics($table_name, 'test_field', $new_spec);
// Clean-up.
- db_drop_table($table_name);
+ $this->schema->dropTable($table_name);
}
/**