Merge pull request #7308 from creative-commoners/pulls/4.0/fix-alternative-db-name-when-session-not-started

FIX Do not try and access sessions when they are not ready
This commit is contained in:
Damian Mooyman 2017-08-24 16:07:52 +12:00 committed by GitHub
commit d52e972453

View File

@ -233,11 +233,17 @@ class DB
if (Director::is_cli()) { if (Director::is_cli()) {
return false; return false;
} }
// Skip if there's no request object yet
if (!Injector::inst()->has(HTTPRequest::class)) { if (!Injector::inst()->has(HTTPRequest::class)) {
return null; return null;
} }
/** @var HTTPRequest $request */ /** @var HTTPRequest $request */
$request = Injector::inst()->get(HTTPRequest::class); $request = Injector::inst()->get(HTTPRequest::class);
// Skip if the session hasn't been started
if (!$request->getSession()->isStarted()) {
return null;
}
$name = $request->getSession()->get(self::ALT_DB_KEY); $name = $request->getSession()->get(self::ALT_DB_KEY);
if (self::valid_alternative_database_name($name)) { if (self::valid_alternative_database_name($name)) {
return $name; return $name;