From 627708e3a827e2ad0741131e70b376535a977e61 Mon Sep 17 00:00:00 2001 From: Mark Stephens Date: Fri, 9 Mar 2012 14:15:34 +1300 Subject: [PATCH] BUGFIX: add Director::isDev parameter so we can test if we know we're dev mode already without touching the database. Used in showqueries on MySQL, so that errors are avoided when showing queries on initial switch to dev move (#6856) --- control/Director.php | 29 ++++++++++++++++------------- model/MySQLDatabase.php | 4 ++-- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/control/Director.php b/control/Director.php index 403b01bc1..5d00b4c45 100644 --- a/control/Director.php +++ b/control/Director.php @@ -802,19 +802,31 @@ class Director implements TemplateGlobalProvider { /** * This function will return true if the site is in a development environment. * For information about environment types, see {@link Director::set_environment_type()}. + * @param $dontTouchDB If true, the database checks are not performed, which allows certain DB checks + * to not fail before the DB is ready. If false (default), DB checks are included. */ - static function isDev() { + static function isDev($dontTouchDB = false) { // This variable is used to supress repetitions of the isDev security message below. static $firstTimeCheckingGetVar = true; + + $result = false; + + if(isset($_SESSION['isDev']) && $_SESSION['isDev']) $result = true; + if(self::$environment_type && self::$environment_type == 'dev') $result = true; + + if(!empty(Director::$dev_servers)) { + Deprecation::notice('3.0', 'Director::$dev_servers doesn\'t work anymore'); + } // Use ?isDev=1 to get development access on the live server - if(isset($_GET['isDev'])) { + if(!$dontTouchDB && !$result && isset($_GET['isDev'])) { if(Security::database_is_ready()) { if($firstTimeCheckingGetVar && !Permission::check('ADMIN')){ BasicAuth::requireLogin("SilverStripe developer access. Use your CMS login", "ADMIN"); } $_SESSION['isDev'] = $_GET['isDev']; - if($firstTimeCheckingGetVar) $firstTimeCheckingGetVar = false; + $firstTimeCheckingGetVar = false; + $result = $_GET['isDev']; } else { if($firstTimeCheckingGetVar && DB::connection_attempted()) { echo "

dbConn->query($sql); - if(isset($_REQUEST['showqueries'])) { + if(isset($_REQUEST['showqueries']) && Director::isDev(true)) { $endtime = round(microtime(true) - $starttime,4); Debug::message("\n$sql\n{$endtime}ms\n", false); }