From d328c7cc53071376bd29153d1b35560928fbca5b Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 19 Oct 2010 04:52:59 +0000 Subject: [PATCH] BUGFIX DB::connect() should not rely on $_SESSION existing, so we check isset() to supress any warnings of undefined indexes MINOR Code formatting tidy of DB::connect() function (from r111772) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112920 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/DB.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/model/DB.php b/core/model/DB.php index a5506ed6e..d3adc263f 100755 --- a/core/model/DB.php +++ b/core/model/DB.php @@ -83,12 +83,14 @@ class DB { */ static function connect($databaseConfig) { // This is used by TestRunner::startsession() to test up a test session using an alt - if(isset($_SESSION["alternativeDatabaseName"]) && $dbname = $_SESSION["alternativeDatabaseName"]) $databaseConfig['database'] = $dbname; - + if(isset($_SESSION) && !empty($_SESSION['alternativeDatabaseName'])) { + $databaseConfig['database'] = $_SESSION['alternativeDatabaseName']; + } + if(!isset($databaseConfig['type']) || empty($databaseConfig['type'])) { user_error("DB::connect: Not passed a valid database config", E_USER_ERROR); } - + self::$connection_attempted = true; $dbClass = $databaseConfig['type']; @@ -332,5 +334,4 @@ class DB { return self::getConn()->alterationMessage($message, $type); } -} -?> \ No newline at end of file +} \ No newline at end of file