Commit 27bc1f74 authored by alexpott's avatar alexpott

Issue #2848817 by voleger, andypost, hgunicamp, JacobSanford, techtud,...

Issue #2848817 by voleger, andypost, hgunicamp, JacobSanford, techtud, alexpott, vidhatanand, Sharique, JayKandari, kiamlaluno, cilefen, borisson_: Replace all calls to db_table_exists, which is deprecated
parent d712f83e
...@@ -645,6 +645,11 @@ function db_index_exists($table, $name) { ...@@ -645,6 +645,11 @@ function db_index_exists($table, $name) {
* @see \Drupal\Core\Database\Schema::tableExists() * @see \Drupal\Core\Database\Schema::tableExists()
*/ */
function db_table_exists($table) { function db_table_exists($table) {
@trigger_error(
'db_table_exists() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use $injected_database->schema()->tableExists($table) instead. See https://www.drupal.org/node/2947929.',
E_USER_DEPRECATED
);
return Database::getConnection()->schema()->tableExists($table); return Database::getConnection()->schema()->tableExists($table);
} }
......
...@@ -134,7 +134,7 @@ function drupal_uninstall_schema($module) { ...@@ -134,7 +134,7 @@ function drupal_uninstall_schema($module) {
_drupal_schema_initialize($tables, $module, FALSE); _drupal_schema_initialize($tables, $module, FALSE);
$schema = \Drupal::database()->schema(); $schema = \Drupal::database()->schema();
foreach ($tables as $table) { foreach ($tables as $table) {
if (db_table_exists($table['name'])) { if ($schema->tableExists($table['name'])) {
$schema->dropTable($table['name']); $schema->dropTable($table['name']);
} }
} }
......
...@@ -62,7 +62,7 @@ public function testSetUp() { ...@@ -62,7 +62,7 @@ public function testSetUp() {
$this->assertIdentical(\Drupal::moduleHandler()->getImplementations('entity_type_alter'), ['entity_test']); $this->assertIdentical(\Drupal::moduleHandler()->getImplementations('entity_type_alter'), ['entity_test']);
// Verify that no modules have been installed. // Verify that no modules have been installed.
$this->assertFalse(db_table_exists($table), "'$table' database table not found."); $this->assertFalse(Database::getConnection()->schema()->tableExists($table), "'$table' database table not found.");
// Verify that the settings.testing.php got taken into account. // Verify that the settings.testing.php got taken into account.
$this->assertTrue(function_exists('simpletest_test_stub_settings_function')); $this->assertTrue(function_exists('simpletest_test_stub_settings_function'));
...@@ -114,7 +114,7 @@ public function testEnableModulesInstall() { ...@@ -114,7 +114,7 @@ public function testEnableModulesInstall() {
$list = \Drupal::moduleHandler()->getImplementations('hook_info'); $list = \Drupal::moduleHandler()->getImplementations('hook_info');
$this->assertFalse(in_array($module, $list), "{$module}_hook_info() in \Drupal::moduleHandler()->getImplementations() not found."); $this->assertFalse(in_array($module, $list), "{$module}_hook_info() in \Drupal::moduleHandler()->getImplementations() not found.");
$this->assertFalse(db_table_exists($table), "'$table' database table not found."); $this->assertFalse(Database::getConnection()->schema()->tableExists($table), "'$table' database table not found.");
// Install the module. // Install the module.
\Drupal::service('module_installer')->install([$module]); \Drupal::service('module_installer')->install([$module]);
...@@ -126,7 +126,7 @@ public function testEnableModulesInstall() { ...@@ -126,7 +126,7 @@ public function testEnableModulesInstall() {
$list = \Drupal::moduleHandler()->getImplementations('hook_info'); $list = \Drupal::moduleHandler()->getImplementations('hook_info');
$this->assertTrue(in_array($module, $list), "{$module}_hook_info() in \Drupal::moduleHandler()->getImplementations() found."); $this->assertTrue(in_array($module, $list), "{$module}_hook_info() in \Drupal::moduleHandler()->getImplementations() found.");
$this->assertTrue(db_table_exists($table), "'$table' database table found."); $this->assertTrue(Database::getConnection()->schema()->tableExists($table), "'$table' database table found.");
$schema = drupal_get_module_schema($module, $table); $schema = drupal_get_module_schema($module, $table);
$this->assertTrue($schema, "'$table' table schema found."); $this->assertTrue($schema, "'$table' table schema found.");
} }
...@@ -156,7 +156,7 @@ public function testInstallSchema() { ...@@ -156,7 +156,7 @@ public function testInstallSchema() {
$table = 'entity_test_example'; $table = 'entity_test_example';
// Verify that we can install a table from the module schema. // Verify that we can install a table from the module schema.
$this->installSchema($module, $table); $this->installSchema($module, $table);
$this->assertTrue(db_table_exists($table), "'$table' database table found."); $this->assertTrue(Database::getConnection()->schema()->tableExists($table), "'$table' database table found.");
// Verify that the schema is known to Schema API. // Verify that the schema is known to Schema API.
$schema = drupal_get_module_schema($module, $table); $schema = drupal_get_module_schema($module, $table);
...@@ -171,7 +171,7 @@ public function testInstallSchema() { ...@@ -171,7 +171,7 @@ public function testInstallSchema() {
catch (\Exception $e) { catch (\Exception $e) {
$this->pass('Exception for non-retrievable schema found.'); $this->pass('Exception for non-retrievable schema found.');
} }
$this->assertFalse(db_table_exists($table), "'$table' database table not found."); $this->assertFalse(Database::getConnection()->schema()->tableExists($table), "'$table' database table not found.");
$schema = drupal_get_module_schema($module, $table); $schema = drupal_get_module_schema($module, $table);
$this->assertFalse($schema, "'$table' table schema not found."); $this->assertFalse($schema, "'$table' table schema not found.");
...@@ -185,14 +185,14 @@ public function testInstallSchema() { ...@@ -185,14 +185,14 @@ public function testInstallSchema() {
catch (\Exception $e) { catch (\Exception $e) {
$this->pass('Exception for non-retrievable schema found.'); $this->pass('Exception for non-retrievable schema found.');
} }
$this->assertFalse(db_table_exists($table), "'$table' database table not found."); $this->assertFalse(Database::getConnection()->schema()->tableExists($table), "'$table' database table not found.");
$schema = drupal_get_module_schema($module, $table); $schema = drupal_get_module_schema($module, $table);
$this->assertTrue($schema, "'$table' table schema found."); $this->assertTrue($schema, "'$table' table schema found.");
// Verify that the same table can be installed after enabling the module. // Verify that the same table can be installed after enabling the module.
$this->enableModules([$module]); $this->enableModules([$module]);
$this->installSchema($module, $table); $this->installSchema($module, $table);
$this->assertTrue(db_table_exists($table), "'$table' database table found."); $this->assertTrue(Database::getConnection()->schema()->tableExists($table), "'$table' database table found.");
$schema = drupal_get_module_schema($module, $table); $schema = drupal_get_module_schema($module, $table);
$this->assertTrue($schema, "'$table' table schema found."); $this->assertTrue($schema, "'$table' table schema found.");
} }
...@@ -206,7 +206,7 @@ public function testInstallEntitySchema() { ...@@ -206,7 +206,7 @@ public function testInstallEntitySchema() {
$this->enableModules(['user']); $this->enableModules(['user']);
// Verity that the entity schema is created properly. // Verity that the entity schema is created properly.
$this->installEntitySchema($entity); $this->installEntitySchema($entity);
$this->assertTrue(db_table_exists($entity), "'$entity' database table found."); $this->assertTrue(Database::getConnection()->schema()->tableExists($entity), "'$entity' database table found.");
} }
/** /**
......
...@@ -59,8 +59,9 @@ public function assertTableCount($base_table, $count = TRUE) { ...@@ -59,8 +59,9 @@ public function assertTableCount($base_table, $count = TRUE) {
public function assertModuleTablesExist($module) { public function assertModuleTablesExist($module) {
$tables = array_keys(drupal_get_module_schema($module)); $tables = array_keys(drupal_get_module_schema($module));
$tables_exist = TRUE; $tables_exist = TRUE;
$schema = Database::getConnection()->schema();
foreach ($tables as $table) { foreach ($tables as $table) {
if (!db_table_exists($table)) { if (!$schema->tableExists($table)) {
$tables_exist = FALSE; $tables_exist = FALSE;
} }
} }
...@@ -76,8 +77,9 @@ public function assertModuleTablesExist($module) { ...@@ -76,8 +77,9 @@ public function assertModuleTablesExist($module) {
public function assertModuleTablesDoNotExist($module) { public function assertModuleTablesDoNotExist($module) {
$tables = array_keys(drupal_get_module_schema($module)); $tables = array_keys(drupal_get_module_schema($module));
$tables_exist = FALSE; $tables_exist = FALSE;
$schema = Database::getConnection()->schema();
foreach ($tables as $table) { foreach ($tables as $table) {
if (db_table_exists($table)) { if ($schema->tableExists($table)) {
$tables_exist = TRUE; $tables_exist = TRUE;
} }
} }
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace Drupal\Tests\system\Functional\Database; namespace Drupal\Tests\system\Functional\Database;
use Drupal\Core\Database\Database;
/** /**
* Tests the temporary query functionality. * Tests the temporary query functionality.
* *
...@@ -29,7 +31,7 @@ public function testTemporaryQuery() { ...@@ -29,7 +31,7 @@ public function testTemporaryQuery() {
$data = json_decode($this->getSession()->getPage()->getContent()); $data = json_decode($this->getSession()->getPage()->getContent());
if ($data) { if ($data) {
$this->assertEqual($this->countTableRows('test'), $data->row_count, 'The temporary table contains the correct amount of rows.'); $this->assertEqual($this->countTableRows('test'), $data->row_count, 'The temporary table contains the correct amount of rows.');
$this->assertFalse(db_table_exists($data->table_name), 'The temporary table is, indeed, temporary.'); $this->assertFalse(Database::getConnection()->schema()->tableExists($data->table_name), 'The temporary table is, indeed, temporary.');
} }
else { else {
$this->fail('The creation of the temporary table failed.'); $this->fail('The creation of the temporary table failed.');
......
...@@ -56,8 +56,9 @@ public function assertTableCount($base_table, $count = TRUE) { ...@@ -56,8 +56,9 @@ public function assertTableCount($base_table, $count = TRUE) {
public function assertModuleTablesExist($module) { public function assertModuleTablesExist($module) {
$tables = array_keys(drupal_get_module_schema($module)); $tables = array_keys(drupal_get_module_schema($module));
$tables_exist = TRUE; $tables_exist = TRUE;
$schema = Database::getConnection()->schema();
foreach ($tables as $table) { foreach ($tables as $table) {
if (!db_table_exists($table)) { if (!$schema->tableExists($table)) {
$tables_exist = FALSE; $tables_exist = FALSE;
} }
} }
...@@ -73,8 +74,9 @@ public function assertModuleTablesExist($module) { ...@@ -73,8 +74,9 @@ public function assertModuleTablesExist($module) {
public function assertModuleTablesDoNotExist($module) { public function assertModuleTablesDoNotExist($module) {
$tables = array_keys(drupal_get_module_schema($module)); $tables = array_keys(drupal_get_module_schema($module));
$tables_exist = FALSE; $tables_exist = FALSE;
$schema = Database::getConnection()->schema();
foreach ($tables as $table) { foreach ($tables as $table) {
if (db_table_exists($table)) { if ($schema->tableExists($table)) {
$tables_exist = TRUE; $tables_exist = TRUE;
} }
} }
......
...@@ -37,6 +37,10 @@ public function testRegression_310447() { ...@@ -37,6 +37,10 @@ public function testRegression_310447() {
/** /**
* Tests the db_table_exists() function. * Tests the db_table_exists() function.
*
* @group legacy
*
* @expectedDeprecation db_table_exists() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use $injected_database->schema()->tableExists($table) instead. See https://www.drupal.org/node/2947929.
*/ */
public function testDBTableExists() { public function testDBTableExists() {
$this->assertSame(TRUE, db_table_exists('test'), 'Returns true for existent table.'); $this->assertSame(TRUE, db_table_exists('test'), 'Returns true for existent table.');
......
...@@ -379,8 +379,9 @@ public function testFieldUpdateFailure() { ...@@ -379,8 +379,9 @@ public function testFieldUpdateFailure() {
$this->tableMapping->getDedicatedDataTableName($prior_field_storage), $this->tableMapping->getDedicatedDataTableName($prior_field_storage),
$this->tableMapping->getDedicatedRevisionTableName($prior_field_storage), $this->tableMapping->getDedicatedRevisionTableName($prior_field_storage),
]; ];
$schema = Database::getConnection()->schema();
foreach ($tables as $table_name) { foreach ($tables as $table_name) {
$this->assertTrue(db_table_exists($table_name), t('Table %table exists.', ['%table' => $table_name])); $this->assertTrue($schema->tableExists($table_name), t('Table %table exists.', ['%table' => $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