Commit 2708ff78 authored by catch's avatar catch

Issue #2848812 by harsha012, gaurav.kapoor, Yogesh Pawar, Sharique, techtud,...

Issue #2848812 by harsha012, gaurav.kapoor, Yogesh Pawar, Sharique, techtud, JayKandari, alexpott: Replace all calls to db_set_active, which is deprecated
parent 122b6637
......@@ -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);
}
......
......@@ -59,7 +59,7 @@ public function minimumVersion() {
protected function connect() {
try {
// This doesn't actually test the connection.
db_set_active();
Database::setActiveConnection();
// Now actually do a check.
try {
Database::getConnection();
......
......@@ -58,7 +58,7 @@ public function minimumVersion() {
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.');
......
......@@ -54,7 +54,7 @@ public function getFormOptions(array $database) {
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.');
......
......@@ -156,7 +156,7 @@ public function runTasks() {
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.');
......
......@@ -113,11 +113,11 @@ public function testEnableMultiConnectionLogging() {
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');
......
......@@ -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 @@ public function testDBIndexExists() {
$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');
}
}
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