From 5c92e7a740fbce4184cf204a11ebbb6b918a376b Mon Sep 17 00:00:00 2001 From: sam marshall Date: Thu, 2 May 2013 17:23:54 +0100 Subject: [PATCH] MDL-39474 Library: Make a fast way to check developer debug mode --- admin/cli/install.php | 1 + cache/classes/helper.php | 3 ++- install.php | 1 + lib/moodlelib.php | 5 +++-- lib/setup.php | 10 ++++++++++ lib/upgrade.txt | 3 +++ 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/admin/cli/install.php b/admin/cli/install.php index a84d5562588..946cfcba309 100644 --- a/admin/cli/install.php +++ b/admin/cli/install.php @@ -150,6 +150,7 @@ $CFG->docroot = 'http://docs.moodle.org'; $CFG->running_installer = true; $CFG->early_install_lang = true; $CFG->ostype = (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) ? 'WINDOWS' : 'UNIX'; +$CFG->developerdebug = true; $parts = explode('/', str_replace('\\', '/', dirname(dirname(__FILE__)))); $CFG->admin = array_pop($parts); diff --git a/cache/classes/helper.php b/cache/classes/helper.php index 873dbbe6279..7aff8ecce22 100644 --- a/cache/classes/helper.php +++ b/cache/classes/helper.php @@ -513,8 +513,9 @@ class cache_helper { * @return string */ public static function hash_key($key, cache_definition $definition) { + global $CFG; if ($definition->uses_simple_keys()) { - if (debugging() && preg_match('#[^a-zA-Z0-9_]#', $key)) { + if ($CFG->developerdebug && preg_match('#[^a-zA-Z0-9_]#', $key)) { throw new coding_exception('Cache definition '.$definition->get_id().' requires simple keys. Invalid key provided.', $key); } // We put the key first so that we can be sure the start of the key changes. diff --git a/install.php b/install.php index 7acf6d5d9e7..062694eca81 100644 --- a/install.php +++ b/install.php @@ -169,6 +169,7 @@ $CFG->directorypermissions = isset($distro->directorypermissions) ? $distro->dir $CFG->running_installer = true; $CFG->early_install_lang = true; $CFG->ostype = (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) ? 'WINDOWS' : 'UNIX'; +$CFG->developerdebug = true; // Require all needed libs require_once($CFG->libdir.'/setuplib.php'); diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 463787578a2..f9640197080 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -7563,7 +7563,7 @@ function get_string($identifier, $component = '', $a = NULL, $lazyload = false) return new lang_string($identifier, $component, $a); } - if (debugging('', DEBUG_DEVELOPER) && clean_param($identifier, PARAM_STRINGID) === '') { + if ($CFG->developerdebug && clean_param($identifier, PARAM_STRINGID) === '') { throw new coding_exception('Invalid string identifier. The identifier cannot be empty. Please fix your get_string() call.'); } @@ -11359,6 +11359,7 @@ class lang_string { * @param string $lang The language to use when processing the string. */ public function __construct($identifier, $component = '', $a = null, $lang = null) { + global $CFG; if (empty($component)) { $component = 'moodle'; } @@ -11396,7 +11397,7 @@ class lang_string { } } - if (debugging(false, DEBUG_DEVELOPER)) { + if ($CFG->developerdebug) { if (clean_param($this->identifier, PARAM_STRINGID) == '') { throw new coding_exception('Invalid string identifier. Most probably some illegal character is part of the string identifier. Please check your string definition'); } diff --git a/lib/setup.php b/lib/setup.php index 0b9cbd2f40a..4625988a877 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -54,6 +54,13 @@ if (!isset($CFG)) { } } +// The 'developerdebug' value is relied upon by various functions, so set it +// immediately (before debugging value is actually known). +if (!isset($CFG->developerdebug)) { + $tempdeveloperdebug = true; + $CFG->developerdebug = false; +} + // We can detect real dirroot path reliably since PHP 4.0.2, // it can not be anything else, there is no point in having this in config.php $CFG->dirroot = dirname(dirname(__FILE__)); @@ -612,6 +619,9 @@ if ($originalconfigdebug !== null) { unset($originalconfigdebug); unset($originaldatabasedebug); error_reporting($CFG->debug); +if (!empty($tempdeveloperdebug)) { + $CFG->developerdebug = debugging('', DEBUG_DEVELOPER); +} // find out if PHP configured to display warnings, // this is a security problem because some moodle scripts may diff --git a/lib/upgrade.txt b/lib/upgrade.txt index e33f0c83548..6b1eed1f3ee 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -69,6 +69,9 @@ information provided here is intended especially for developers. uninstall tool is returned. Unless the plugin type needs extra steps that can't be handled by plugininfo_xxx::uninstall() method or xmldb_xxx_uninstall() function, this default URL should satisfy all plugin types. +* New pattern 'if ($CFG->developerdebug) {}' can be used when checking whether to carry + out additional sanity checks - faster than debugging('', DEBUG_DEVELOPER), but + that still works too. Database (DML) layer: * $DB->sql_empty() is deprecated, you have to use sql parameters with empty values instead, -- 2.43.0