Unverified Commit ab302cc3 authored by alexpott's avatar alexpott

Issue #2848479 by voleger, yogeshmpawar, marvin_B8, gaurav.kapoor, hgunicamp,...

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 ead36d31)
parent c8afb674
......@@ -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);
}
......
......@@ -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']);
}
}
}
......
......@@ -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++;
}
}
......
......@@ -71,4 +71,15 @@ public function testDBIsActive() {
$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'));
}
}
......@@ -23,6 +23,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.
*/
......@@ -121,7 +144,7 @@ public function testSchema() {
$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 @@ public function testSchema() {
$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 @@ public function testSchema() {
$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 @@ protected function assertFieldAdditionRemoval($field_spec) {
$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 @@ protected function assertFieldAdditionRemoval($field_spec) {
// 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 @@ protected function assertFieldChange($old_spec, $new_spec, $test_data = NULL) {
$this->assertFieldCharacteristics($table_name, 'test_field', $new_spec);
// Clean-up.
db_drop_table($table_name);
$this->schema->dropTable($table_name);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment