Compare commits

...

2 Commits

Author SHA1 Message Date
Steve Boyd
87b4f99f91
Merge 5d14e87748 into 097313b0f1 2024-09-24 23:03:25 +00:00
Steve Boyd
5d14e87748 FIX Ensure primary connection is updated with temporary database 2024-09-25 11:03:19 +12:00

View File

@ -570,14 +570,14 @@ class TestSessionEnvironment
}
// Connect to database
DB::connect($databaseConfig);
$this->connectToDB($databaseConfig);
} else {
// We've already connected to the database, do a fast check to see what database we're currently using
$db = DB::get_conn()->getSelectedDatabase();
if (isset($state->database) && $db != $state->database) {
$this->oldDatabaseName = $databaseConfig['database'];
$databaseConfig['database'] = $state->database;
DB::connect($databaseConfig);
$this->connectToDB($databaseConfig);
}
}
}
@ -613,4 +613,15 @@ class TestSessionEnvironment
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);
}
}
}