summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2018-02-22 10:16:55 (GMT)
committerNathaniel Catchpole2018-02-22 10:16:55 (GMT)
commit2708ff78d1ae2b02a37520f4330acea5b28cc9bc (patch)
treedd5b9a27a62a678d36c2eda1b685e4141380dc66
parent122b6637796b35d0c68d9b16425574663849b5a0 (diff)
Issue #2848812 by harsha012, gaurav.kapoor, Yogesh Pawar, Sharique, techtud, JayKandari, alexpott: Replace all calls to db_set_active, which is deprecated
-rw-r--r--core/includes/database.inc1
-rw-r--r--core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php2
-rw-r--r--core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php2
-rw-r--r--core/lib/Drupal/Core/Database/Driver/sqlite/Install/Tasks.php2
-rw-r--r--core/lib/Drupal/Core/Database/Install/Tasks.php2
-rw-r--r--core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php4
-rw-r--r--core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php14
7 files changed, 21 insertions, 6 deletions
diff --git a/core/includes/database.inc b/core/includes/database.inc
index d4cb593..6891ea9 100644
--- a/core/includes/database.inc
+++ b/core/includes/database.inc
@@ -335,6 +335,7 @@ function db_transaction($name = NULL, array $options = []) {
* \Drupal\Core\Database\Database::setActiveConnection().
*/
function db_set_active($key = 'default') {
+ @trigger_error('db_set_active() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Database\Database::setActiveConnection() instead. See https://www.drupal.org/node/2944084.', E_USER_DEPRECATED);
return Database::setActiveConnection($key);
}
diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php b/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php
index 67f2526..6a639d7 100644
--- a/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php
+++ b/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php
@@ -59,7 +59,7 @@ class Tasks extends InstallTasks {
protected function connect() {
try {
// This doesn't actually test the connection.
- db_set_active();
+ Database::setActiveConnection();
// Now actually do a check.
try {
Database::getConnection();
diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php
index 70d9a33..e3312d2 100644
--- a/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php
+++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php
@@ -58,7 +58,7 @@ class Tasks extends InstallTasks {
protected function connect() {
try {
// This doesn't actually test the connection.
- db_set_active();
+ Database::setActiveConnection();
// Now actually do a check.
Database::getConnection();
$this->pass('Drupal can CONNECT to the database ok.');
diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Install/Tasks.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Install/Tasks.php
index b0ea188..f5cb289 100644
--- a/core/lib/Drupal/Core/Database/Driver/sqlite/Install/Tasks.php
+++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Install/Tasks.php
@@ -54,7 +54,7 @@ class Tasks extends InstallTasks {
protected function connect() {
try {
// This doesn't actually test the connection.
- db_set_active();
+ Database::setActiveConnection();
// Now actually do a check.
Database::getConnection();
$this->pass('Drupal can CONNECT to the database ok.');
diff --git a/core/lib/Drupal/Core/Database/Install/Tasks.php b/core/lib/Drupal/Core/Database/Install/Tasks.php
index a2ea41b..44bddea 100644
--- a/core/lib/Drupal/Core/Database/Install/Tasks.php
+++ b/core/lib/Drupal/Core/Database/Install/Tasks.php
@@ -156,7 +156,7 @@ abstract class Tasks {
protected function connect() {
try {
// This doesn't actually test the connection.
- db_set_active();
+ Database::setActiveConnection();
// Now actually do a check.
Database::getConnection();
$this->pass('Drupal can CONNECT to the database ok.');
diff --git a/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php b/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php
index 28d9ff2..383b532 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php
@@ -113,11 +113,11 @@ class LoggingTest extends DatabaseTestBase {
db_query('SELECT name FROM {test} WHERE age > :age', [':age' => 25])->fetchCol();
- $old_key = db_set_active('test2');
+ $old_key = Database::setActiveConnection('test2');
db_query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Ringo'], ['target' => 'replica'])->fetchCol();
- db_set_active($old_key);
+ Database::setActiveConnection($old_key);
$queries1 = Database::getLog('testing1');
$queries2 = Database::getLog('testing1', 'test2');
diff --git a/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php b/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php
index 66eed0a..22173da 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php
@@ -2,6 +2,8 @@
namespace Drupal\KernelTests\Core\Database;
+use Drupal\Core\Database\Database;
+
/**
* Regression tests cases for the database layer.
*
@@ -57,4 +59,16 @@ class RegressionTest extends DatabaseTestBase {
$this->assertSame(FALSE, db_index_exists('test', 'nosuchindex'), 'Returns false for nonexistent index.');
}
+ /**
+ * Tests the db_set_active() function.
+ *
+ * @group legacy
+ *
+ * @expectedDeprecation db_set_active() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Database\Database::setActiveConnection() instead. See https://www.drupal.org/node/2944084.
+ */
+ public function testDBIsActive() {
+ $get_active_db = Database::getConnection()->getKey();
+ $this->assert(db_set_active($get_active_db), 'Database connection is active');
+ }
+
}