function Database::renameConnection

Same name in other branches
  1. 7.x includes/database/database.inc \Database::renameConnection()
  2. 9 core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::renameConnection()
  3. 8.9.x core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::renameConnection()
  4. 11.x core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::renameConnection()

Rename a connection and its corresponding connection information.

Parameters

string $old_key: The old connection key.

string $new_key: The new connection key.

Return value

bool TRUE in case of success, FALSE otherwise.

10 calls to Database::renameConnection()
InstallerIsolationLevelExistingSettingsTest::testInstaller in core/modules/mysql/tests/src/Functional/InstallerIsolationLevelExistingSettingsTest.php
Verifies that isolation_level is not set in the database settings.
InstallerIsolationLevelNoDatabaseSettingsTest::testInstaller in core/modules/mysql/tests/src/Functional/InstallerIsolationLevelNoDatabaseSettingsTest.php
Verifies that the isolation_level was added to the database settings.
InstallerNonDefaultDatabaseDriverTest::testInstalled in core/tests/Drupal/FunctionalTests/Installer/InstallerNonDefaultDatabaseDriverTest.php
Confirms that the installation succeeded.
KernelTestBase::getDatabaseConnectionInfo in core/tests/Drupal/KernelTests/KernelTestBase.php
Returns the Database connection info to be used for this test.
KernelTestBaseDatabaseDriverModuleTest::getDatabaseConnectionInfo in core/tests/Drupal/KernelTests/KernelTestBaseDatabaseDriverModuleTest.php
Returns the Database connection info to be used for this test.

... See full list

File

core/lib/Drupal/Core/Database/Database.php, line 396

Class

Database
Primary front-controller for the database system.

Namespace

Drupal\Core\Database

Code

public static final function renameConnection($old_key, $new_key) {
    if (!empty(self::$databaseInfo[$old_key]) && empty(self::$databaseInfo[$new_key])) {
        // Migrate the database connection information.
        self::$databaseInfo[$new_key] = self::$databaseInfo[$old_key];
        unset(self::$databaseInfo[$old_key]);
        // Migrate over the DatabaseConnection object if it exists.
        if (isset(self::$connections[$old_key])) {
            self::$connections[$new_key] = self::$connections[$old_key];
            unset(self::$connections[$old_key]);
        }
        return TRUE;
    }
    else {
        return FALSE;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.