Permalink
Browse files

FIX Avoid infinite loops on ?isDev=1 and Deprecation class

If any of the functionality triggered by Director::isDev()
was causing deprecation errors, the system would go into
an infinite loop. Since the only way to cause this is the DB
checking functionality, we disable that for Deprecation.
Side effect of this change: You can't show deprecation notices
on a live site by forcing the session into dev mode.
  • Loading branch information...
chillu committed Jul 17, 2013
1 parent d9b0d14 commit 9d764d6794c60670de30ce07e2beeab75709f546
Showing with 21 additions and 11 deletions.
  1. +20 −10 control/Director.php
  2. +1 −1 dev/Deprecation.php
View
@@ -884,21 +884,25 @@ public static function set_test_servers($servers) {
Director::$test_servers = $servers;
}
- /*
+ /**
* This function will return true if the site is in a live environment.
* For information about environment types, see {@link Director::set_environment_type()}.
+ *
+ * @param $skipDatabase Skips database checks for current login permissions if set to TRUE,
+ * which is useful for checks happening before the database is functional.
*/
- public static function isLive() {
- return !(Director::isDev() || Director::isTest());
+ public static function isLive($skipDatabase = false) {
+ return !(Director::isDev($skipDatabase) || Director::isTest($skipDatabase));
}
/**
* 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.
+ *
+ * @param $skipDatabase Skips database checks for current login permissions if set to TRUE,
+ * which is useful for checks happening before the database is functional.
*/
- public static function isDev($dontTouchDB = false) {
+ public static function isDev($skipDatabase = false) {
// This variable is used to supress repetitions of the isDev security message below.
static $firstTimeCheckingGetVar = true;
@@ -908,7 +912,7 @@ public static function isDev($dontTouchDB = false) {
if(self::$environment_type && self::$environment_type == 'dev') $result = true;
// Use ?isDev=1 to get development access on the live server
- if(!$dontTouchDB && !$result && isset($_GET['isDev'])) {
+ if(!$skipDatabase && !$result && isset($_GET['isDev'])) {
if(Security::database_is_ready()) {
if($firstTimeCheckingGetVar && !Permission::check('ADMIN')){
BasicAuth::requireLogin("SilverStripe developer access. Use your CMS login", "ADMIN");
@@ -933,18 +937,24 @@ public static function isDev($dontTouchDB = false) {
/**
* This function will return true if the site is in a test environment.
* For information about environment types, see {@link Director::set_environment_type()}.
+ *
+ * @param $skipDatabase Skips database checks for current login permissions if set to TRUE,
+ * which is useful for checks happening before the database is functional.
*/
- public static function isTest() {
+ public static function isTest($skipDatabase = false) {
// Use ?isTest=1 to get test access on the live server, or explicitly set your environment
- if(isset($_GET['isTest'])) {
+ if(!$skipDatabase && isset($_GET['isTest'])) {
if(Security::database_is_ready()) {
BasicAuth::requireLogin("SilverStripe developer access. Use your CMS login", "ADMIN");
$_SESSION['isTest'] = $_GET['isTest'];
} else {
return true;
}
}
- if(self::isDev()) return false;
+
+ if(self::isDev($skipDatabase)) {
+ return false;
+ }
if(self::$environment_type) {
return self::$environment_type == 'test';
View
@@ -129,7 +129,7 @@ protected static function get_called_method_from_trace($backtrace, $level = 1) {
*/
public static function notice($atVersion, $string = '', $scope = Deprecation::SCOPE_METHOD) {
// Never raise deprecation notices in a live environment
- if(Director::isLive()) return;
+ if(Director::isLive(true)) return;
// If you pass #.#, assume #.#.0
if(preg_match('/^[0-9]+\.[0-9]+$/', $atVersion)) $atVersion .= '.0';

0 comments on commit 9d764d6

Please sign in to comment.