-
Notifications
You must be signed in to change notification settings - Fork 20
/
_config.php
30 lines (24 loc) · 1.09 KB
/
_config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
use SilverStripe\ORM\DB;
use SilverStripe\TestSession\TestSessionEnvironment;
// Determine whether there is a testsession currently running, and if so - setup the persistent details for it.
TestSessionEnvironment::singleton()->loadFromFile();
/**
* 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).
*/
if (class_exists('Resque_Event') && class_exists('SSResqueRun')) {
Resque_Event::listen('beforeFork', function ($data) {
$databaseConfig = DB::getConfig();
// 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);
$testEnv = TestSessionEnvironment::singleton();
if ($testEnv->isRunningTests()) {
$testEnv->loadFromFile();
} else {
$testEnv->endTestSession();
}
});
}