summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2018-08-06 09:41:05 (GMT)
committerAlex Pott2018-08-06 09:41:12 (GMT)
commit6173d843673019da2eded794721ce077dbac4190 (patch)
tree70a5a6e4269cf0f5203ba64b7ada9c37b0ddc0fb
parent0fc35d3efc06b247a202d0931303b201684e0887 (diff)
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
(cherry picked from commit 27bc1f74cb7894abe8910da41d3383773a4fe68f)
-rw-r--r--core/includes/database.inc5
-rw-r--r--core/includes/schema.inc2
-rw-r--r--core/modules/simpletest/src/Tests/KernelTestBaseTest.php16
-rw-r--r--core/modules/system/src/Tests/Module/ModuleTestBase.php6
-rw-r--r--core/modules/system/tests/src/Functional/Database/TemporaryQueryTest.php4
-rw-r--r--core/modules/system/tests/src/Functional/Module/ModuleTestBase.php6
-rw-r--r--core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php4
-rw-r--r--core/tests/Drupal/KernelTests/Core/Entity/FieldSqlStorageTest.php3
8 files changed, 31 insertions, 15 deletions
diff --git a/core/includes/database.inc b/core/includes/database.inc
index 668b2a6..ad203e3 100644
--- a/core/includes/database.inc
+++ b/core/includes/database.inc
@@ -645,6 +645,11 @@ function db_index_exists($table, $name) {
* @see \Drupal\Core\Database\Schema::tableExists()
*/
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);
}
diff --git a/core/includes/schema.inc b/core/includes/schema.inc
index f0a104d..978ec23 100644
--- a/core/includes/schema.inc
+++ b/core/includes/schema.inc
@@ -134,7 +134,7 @@ function drupal_uninstall_schema($module) {
_drupal_schema_initialize($tables, $module, FALSE);
$schema = \Drupal::database()->schema();
foreach ($tables as $table) {
- if (db_table_exists($table['name'])) {
+ if ($schema->tableExists($table['name'])) {
$schema->dropTable($table['name']);
}
}
diff --git a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php
index 7131041..fc0d918 100644
--- a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php
+++ b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php
@@ -62,7 +62,7 @@ EOS;
$this->assertIdentical(\Drupal::moduleHandler()->getImplementations('entity_type_alter'), ['entity_test']);
// 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.
$this->assertTrue(function_exists('simpletest_test_stub_settings_function'));
@@ -114,7 +114,7 @@ EOS;
$list = \Drupal::moduleHandler()->getImplementations('hook_info');
$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.
\Drupal::service('module_installer')->install([$module]);
@@ -126,7 +126,7 @@ EOS;
$list = \Drupal::moduleHandler()->getImplementations('hook_info');
$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);
$this->assertTrue($schema, "'$table' table schema found.");
}
@@ -156,7 +156,7 @@ EOS;
$table = 'entity_test_example';
// Verify that we can install a table from the module schema.
$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.
$schema = drupal_get_module_schema($module, $table);
@@ -171,7 +171,7 @@ EOS;
catch (\Exception $e) {
$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);
$this->assertFalse($schema, "'$table' table schema not found.");
@@ -185,14 +185,14 @@ EOS;
catch (\Exception $e) {
$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);
$this->assertTrue($schema, "'$table' table schema found.");
// Verify that the same table can be installed after enabling the module.
$this->enableModules([$module]);
$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);
$this->assertTrue($schema, "'$table' table schema found.");
}
@@ -206,7 +206,7 @@ EOS;
$this->enableModules(['user']);
// Verity that the entity schema is created properly.
$this->installEntitySchema($entity);
- $this->assertTrue(db_table_exists($entity), "'$entity' database table found.");
+ $this->assertTrue(Database::getConnection()->schema()->tableExists($entity), "'$entity' database table found.");
}
/**
diff --git a/core/modules/system/src/Tests/Module/ModuleTestBase.php b/core/modules/system/src/Tests/Module/ModuleTestBase.php
index cc5a7ef..257bb87 100644
--- a/core/modules/system/src/Tests/Module/ModuleTestBase.php
+++ b/core/modules/system/src/Tests/Module/ModuleTestBase.php
@@ -59,8 +59,9 @@ abstract class ModuleTestBase extends WebTestBase {
public function assertModuleTablesExist($module) {
$tables = array_keys(drupal_get_module_schema($module));
$tables_exist = TRUE;
+ $schema = Database::getConnection()->schema();
foreach ($tables as $table) {
- if (!db_table_exists($table)) {
+ if (!$schema->tableExists($table)) {
$tables_exist = FALSE;
}
}
@@ -76,8 +77,9 @@ abstract class ModuleTestBase extends WebTestBase {
public function assertModuleTablesDoNotExist($module) {
$tables = array_keys(drupal_get_module_schema($module));
$tables_exist = FALSE;
+ $schema = Database::getConnection()->schema();
foreach ($tables as $table) {
- if (db_table_exists($table)) {
+ if ($schema->tableExists($table)) {
$tables_exist = TRUE;
}
}
diff --git a/core/modules/system/tests/src/Functional/Database/TemporaryQueryTest.php b/core/modules/system/tests/src/Functional/Database/TemporaryQueryTest.php
index 5226585..e7d0850 100644
--- a/core/modules/system/tests/src/Functional/Database/TemporaryQueryTest.php
+++ b/core/modules/system/tests/src/Functional/Database/TemporaryQueryTest.php
@@ -2,6 +2,8 @@
namespace Drupal\Tests\system\Functional\Database;
+use Drupal\Core\Database\Database;
+
/**
* Tests the temporary query functionality.
*
@@ -29,7 +31,7 @@ class TemporaryQueryTest extends DatabaseTestBase {
$data = json_decode($this->getSession()->getPage()->getContent());
if ($data) {
$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 {
$this->fail('The creation of the temporary table failed.');
diff --git a/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php b/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php
index 425073e..6cc7263 100644
--- a/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php
+++ b/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php
@@ -56,8 +56,9 @@ abstract class ModuleTestBase extends BrowserTestBase {
public function assertModuleTablesExist($module) {
$tables = array_keys(drupal_get_module_schema($module));
$tables_exist = TRUE;
+ $schema = Database::getConnection()->schema();
foreach ($tables as $table) {
- if (!db_table_exists($table)) {
+ if (!$schema->tableExists($table)) {
$tables_exist = FALSE;
}
}
@@ -73,8 +74,9 @@ abstract class ModuleTestBase extends BrowserTestBase {
public function assertModuleTablesDoNotExist($module) {
$tables = array_keys(drupal_get_module_schema($module));
$tables_exist = FALSE;
+ $schema = Database::getConnection()->schema();
foreach ($tables as $table) {
- if (db_table_exists($table)) {
+ if ($schema->tableExists($table)) {
$tables_exist = TRUE;
}
}
diff --git a/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php b/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php
index e4cc868..a8a8b90 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php
@@ -37,6 +37,10 @@ class RegressionTest extends DatabaseTestBase {
/**
* 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() {
$this->assertSame(TRUE, db_table_exists('test'), 'Returns true for existent table.');
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/FieldSqlStorageTest.php b/core/tests/Drupal/KernelTests/Core/Entity/FieldSqlStorageTest.php
index 0ef35db..376a2fa 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/FieldSqlStorageTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/FieldSqlStorageTest.php
@@ -379,8 +379,9 @@ class FieldSqlStorageTest extends EntityKernelTestBase {
$this->tableMapping->getDedicatedDataTableName($prior_field_storage),
$this->tableMapping->getDedicatedRevisionTableName($prior_field_storage),
];
+ $schema = Database::getConnection()->schema();
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]));
}
}