mirror of
https://github.com/silverstripe/silverstripe-testsession
synced 2024-10-22 12:06:00 +00:00
Compare commits
2 Commits
87b4f99f91
...
051fe891af
Author | SHA1 | Date | |
---|---|---|---|
|
051fe891af | ||
|
d670ff13ef |
@ -570,14 +570,18 @@ class TestSessionEnvironment
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Connect to database
|
// Connect to database
|
||||||
$this->connectToDB($databaseConfig);
|
DB::connect($databaseConfig);
|
||||||
} else {
|
} else {
|
||||||
// We've already connected to the database, do a fast check to see what database we're currently using
|
// We've already connected to the database, do a fast check to see what database we're currently using
|
||||||
$db = DB::get_conn()->getSelectedDatabase();
|
$db = DB::get_conn()->getSelectedDatabase();
|
||||||
if (isset($state->database) && $db != $state->database) {
|
if (isset($state->database) && $db != $state->database) {
|
||||||
$this->oldDatabaseName = $databaseConfig['database'];
|
$this->oldDatabaseName = $databaseConfig['database'];
|
||||||
$databaseConfig['database'] = $state->database;
|
$databaseConfig['database'] = $state->database;
|
||||||
$this->connectToDB($databaseConfig);
|
DB::connect($databaseConfig);
|
||||||
|
// This is required for CMS 5.4+
|
||||||
|
if (method_exists(DB::class, 'hasConfig') && DB::hasConfig('primary')) {
|
||||||
|
DB::connect($databaseConfig, 'primary');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -613,15 +617,4 @@ class TestSessionEnvironment
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function connectToDB(array $databaseConfig): void
|
|
||||||
{
|
|
||||||
if (method_exists(DB::class, 'hasConfig') && DB::hasConfig('primary')) {
|
|
||||||
// CMS 5.4+ - ensure we connect the primary connection and not a replica
|
|
||||||
DB::connect($databaseConfig, 'primary');
|
|
||||||
} else {
|
|
||||||
// CMS 5.3 and below do not support replica connections
|
|
||||||
DB::connect($databaseConfig);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user