mirror of
https://github.com/silverstripe/silverstripe-testsession
synced 2024-10-22 14:06:00 +02:00
Create test DB if 'database' GET param is set, but no matching DB is found
This commit is contained in:
parent
59327aff62
commit
3e9c4b2233
@ -35,7 +35,15 @@ class TestSessionController extends Controller {
|
|||||||
if(SapphireTest::using_temp_db()) return $this->renderWith('TestSession_inprogress');
|
if(SapphireTest::using_temp_db()) return $this->renderWith('TestSession_inprogress');
|
||||||
|
|
||||||
// Database
|
// Database
|
||||||
if(!$request->getVar('database')) {
|
if($request->getVar('database')) {
|
||||||
|
$dbExists = (bool)DB::query(
|
||||||
|
sprintf("SHOW DATABASES LIKE '%s'", Convert::raw2sql($request->getVar('database')))
|
||||||
|
)->value();
|
||||||
|
} else {
|
||||||
|
$dbExists = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$dbExists) {
|
||||||
// Create a new one with a randomized name
|
// Create a new one with a randomized name
|
||||||
$dbname = SapphireTest::create_temp_db();
|
$dbname = SapphireTest::create_temp_db();
|
||||||
DB::set_alternative_database_name($dbname);
|
DB::set_alternative_database_name($dbname);
|
||||||
|
Loading…
Reference in New Issue
Block a user