2014-02-04 23:38:22 +01:00
|
|
|
<?php
|
|
|
|
|
2016-06-27 04:51:15 +02:00
|
|
|
use SilverStripe\ORM\DB;
|
2017-04-21 01:58:27 +02:00
|
|
|
use SilverStripe\TestSession\TestSessionEnvironment;
|
2016-06-27 04:51:15 +02:00
|
|
|
|
2014-02-04 23:38:22 +01:00
|
|
|
// Determine whether there is a testsession currently running, and if so - setup the persistent details for it.
|
2017-04-21 01:58:27 +02:00
|
|
|
TestSessionEnvironment::singleton()->loadFromFile();
|
2014-02-12 01:47:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This closure will run every time a Resque_Event is forked (just before it is forked, so it applies to the parent
|
|
|
|
* and child process).
|
|
|
|
*/
|
2017-06-22 05:15:17 +02:00
|
|
|
if (class_exists('Resque_Event') && class_exists('SSResqueRun')) {
|
|
|
|
Resque_Event::listen('beforeFork', function ($data) {
|
|
|
|
$databaseConfig = DB::getConfig();
|
2014-02-12 01:47:40 +01:00
|
|
|
|
2017-06-22 05:15:17 +02:00
|
|
|
// Reconnect to the database - this may connect to the old DB first, but is required because these processes
|
|
|
|
// are long-lived, and MySQL connections often get closed in between worker runs. We need to connect before
|
|
|
|
// calling {@link TestSessionEnvironment::loadFromFile()}.
|
|
|
|
DB::connect($databaseConfig);
|
2014-02-12 01:47:40 +01:00
|
|
|
|
2017-06-22 05:15:17 +02:00
|
|
|
$testEnv = TestSessionEnvironment::singleton();
|
2014-02-12 01:47:40 +01:00
|
|
|
|
2017-06-22 05:15:17 +02:00
|
|
|
if ($testEnv->isRunningTests()) {
|
|
|
|
$testEnv->loadFromFile();
|
|
|
|
} else {
|
|
|
|
$testEnv->endTestSession();
|
|
|
|
}
|
|
|
|
});
|
2014-02-12 01:47:40 +01:00
|
|
|
}
|