diff --git a/admin/cli/automated_backups.php b/admin/cli/automated_backups.php index dc80c7aedc10..3c3841e718d1 100644 --- a/admin/cli/automated_backups.php +++ b/admin/cli/automated_backups.php @@ -75,8 +75,7 @@ $DB->set_debug(true); } if (!empty($CFG->showcrondebugging)) { - $CFG->debug = DEBUG_DEVELOPER; - $CFG->debugdisplay = true; + set_debugging(DEBUG_DEVELOPER, true); } $starttime = microtime(); diff --git a/admin/cli/install.php b/admin/cli/install.php index 21617cf0860c..fcd25b248fa9 100644 --- a/admin/cli/install.php +++ b/admin/cli/install.php @@ -162,6 +162,9 @@ $CFG->early_install_lang = true; $CFG->ostype = (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) ? 'WINDOWS' : 'UNIX'; $CFG->dboptions = array(); +$CFG->debug = (E_ALL | E_STRICT); +$CFG->debugdisplay = true; +$CFG->debugdeveloper = true; $parts = explode('/', str_replace('\\', '/', dirname(dirname(__FILE__)))); $CFG->admin = array_pop($parts); diff --git a/admin/tool/generator/cli/generate.php b/admin/tool/generator/cli/generate.php index 4514fd7cea87..353883e1d300 100644 --- a/admin/tool/generator/cli/generate.php +++ b/admin/tool/generator/cli/generate.php @@ -28,7 +28,7 @@ require(dirname(__FILE__) . '/../../../../config.php'); require_once(dirname(__FILE__) . '/../locallib.php'); -if (!debugging('', DEBUG_DEVELOPER)) { +if (!$CFG->debugdeveloper) { echo("This script is for developers only!!!\n"); exit(1); } diff --git a/admin/tool/generator/index.php b/admin/tool/generator/index.php index f77c8e0e1af6..7a917e91bae3 100644 --- a/admin/tool/generator/index.php +++ b/admin/tool/generator/index.php @@ -34,7 +34,7 @@ error('Only for admins'); } -if (!debugging('', DEBUG_DEVELOPER)) { +if (!$CFG->debugdeveloper) { error('This script is for developers only!!!'); } diff --git a/admin/tool/phpunit/webrunner.php b/admin/tool/phpunit/webrunner.php index f697f7ee085c..f52bf6b002ea 100644 --- a/admin/tool/phpunit/webrunner.php +++ b/admin/tool/phpunit/webrunner.php @@ -34,7 +34,7 @@ navigation_node::override_active_url(new moodle_url('/admin/tool/phpunit/index.php')); admin_externalpage_setup('toolphpunitwebrunner'); -if (!debugging('', DEBUG_DEVELOPER)) { +if (!$CFG->debugdeveloper) { error('Not available on production sites, sorry.'); } @@ -82,7 +82,7 @@ if ($code != 0) { tool_phpunit_problem('Can not initialize database'); } - $CFG->debug = 0; // no pesky redirect warning, we really want to redirect + set_debugging(DEBUG_NONE, false); // Hack: no redirect warning, we really want to redirect. redirect(new moodle_url($PAGE->url, array('execute'=>1, 'tespath'=>$testpath, 'testclass'=>$testclass, 'sesskey'=>sesskey())), 'Reloading page'); echo $OUTPUT->footer(); die(); @@ -103,7 +103,7 @@ if ($code != 0) { tool_phpunit_problem('Can not initialize database'); } - $CFG->debug = 0; // no pesky redirect warning, we really want to redirect + set_debugging(DEBUG_NONE, false); // Hack: no redirect warning, we really want to redirect. redirect(new moodle_url($PAGE->url, array('execute'=>1, 'tespath'=>$testpath, 'testclass'=>$testclass, 'sesskey'=>sesskey())), 'Reloading page'); die(); diff --git a/auth/cas/cli/sync_users.php b/auth/cas/cli/sync_users.php index 33cf33abbce3..a02c32f16c32 100644 --- a/auth/cas/cli/sync_users.php +++ b/auth/cas/cli/sync_users.php @@ -48,7 +48,7 @@ require_once($CFG->dirroot.'/course/lib.php'); // Ensure errors are well explained -$CFG->debug = DEBUG_NORMAL; +set_debugging(DEBUG_DEVELOPER, true); if (!is_enabled_auth('cas')) { error_log('[AUTH CAS] '.get_string('pluginnotenabled', 'auth_ldap')); diff --git a/auth/ldap/cli/sync_users.php b/auth/ldap/cli/sync_users.php index ee155384962d..6898293a2e9f 100644 --- a/auth/ldap/cli/sync_users.php +++ b/auth/ldap/cli/sync_users.php @@ -52,7 +52,7 @@ require_once($CFG->dirroot.'/course/lib.php'); // Ensure errors are well explained -$CFG->debug = DEBUG_NORMAL; +set_debugging(DEBUG_DEVELOPER, true); if (!is_enabled_auth('ldap')) { error_log('[AUTH LDAP] '.get_string('pluginnotenabled', 'auth_ldap')); diff --git a/backup/util/factories/backup_factory.class.php b/backup/util/factories/backup_factory.class.php index e2143cd05e9a..6f8ba31d0c82 100644 --- a/backup/util/factories/backup_factory.class.php +++ b/backup/util/factories/backup_factory.class.php @@ -40,7 +40,7 @@ public static function get_logger_chain($interactive, $execution, $backupid) { global $CFG; $dfltloglevel = backup::LOG_WARNING; // Default logging level - if (debugging('', DEBUG_DEVELOPER)) { // Debug developer raises default logging level + if ($CFG->debugdeveloper) { // Debug developer raises default logging level $dfltloglevel = backup::LOG_DEBUG; } diff --git a/backup/util/factories/tests/factories_test.php b/backup/util/factories/tests/factories_test.php index 54dc4e99fd7f..2a3fa1a55eb6 100644 --- a/backup/util/factories/tests/factories_test.php +++ b/backup/util/factories/tests/factories_test.php @@ -94,7 +94,6 @@ function test_backup_factory() { // Instantiate with debugging enabled and $CFG->backup_error_log_logger_level not set $CFG->debugdisplay = true; - $CFG->debug = DEBUG_DEVELOPER; unset($CFG->backup_error_log_logger_level); $logger1 = backup_factory::get_logger_chain(backup::INTERACTIVE_YES, backup::EXECUTION_INMEDIATE, 'test'); $this->assertTrue($logger1 instanceof error_log_logger); // 1st logger is error_log_logger diff --git a/cache/tests/administration_helper_test.php b/cache/tests/administration_helper_test.php index 6a1630d7c692..c30ae0c648eb 100644 --- a/cache/tests/administration_helper_test.php +++ b/cache/tests/administration_helper_test.php @@ -189,11 +189,8 @@ public function test_get_edit_store_form() { * Test the hash_key functionality. */ public function test_hash_key() { - global $CFG; - - $currentdebugging = $CFG->debug; - - $CFG->debug = E_ALL; + $this->resetAfterTest(); + set_debugging(DEBUG_ALL); // First with simplekeys $instance = cache_config_phpunittest::instance(true); @@ -230,7 +227,5 @@ public function test_hash_key() { $result = cache_helper::hash_key('test/test', $definition); $this->assertEquals(sha1($definition->generate_single_key_prefix().'-test/test'), $result); - - $CFG->debug = $currentdebugging; } } diff --git a/enrol/ldap/cli/sync.php b/enrol/ldap/cli/sync.php index e43b12c16654..c1bff98536a4 100644 --- a/enrol/ldap/cli/sync.php +++ b/enrol/ldap/cli/sync.php @@ -46,7 +46,7 @@ require_once("$CFG->libdir/clilib.php"); // Ensure errors are well explained. -$CFG->debug = DEBUG_DEVELOPER; +set_debugging(DEBUG_DEVELOPER, true); if (!enrol_is_enabled('ldap')) { cli_error(get_string('pluginnotenabled', 'enrol_ldap'), 2); diff --git a/install.php b/install.php index 7b5fa2396777..899ebd35e38d 100644 --- a/install.php +++ b/install.php @@ -181,6 +181,9 @@ $CFG->running_installer = true; $CFG->early_install_lang = true; $CFG->ostype = (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) ? 'WINDOWS' : 'UNIX'; +$CFG->debug = (E_ALL | E_STRICT); +$CFG->debugdisplay = true; +$CFG->debugdeveloper = true; // Require all needed libs require_once($CFG->libdir.'/setuplib.php'); diff --git a/lib/accesslib.php b/lib/accesslib.php index 29276381d3bf..386588a29a97 100644 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -3807,7 +3807,7 @@ function get_users_by_capability(context $context, $capability, $fields = '', $s $fields = 'u.*'; } } else { - if (debugging('', DEBUG_DEVELOPER) && strpos($fields, 'u.*') === false && strpos($fields, 'u.id') === false) { + if ($CFG->debugdeveloper && strpos($fields, 'u.*') === false && strpos($fields, 'u.id') === false) { debugging('u.id must be included in the list of fields passed to get_users_by_capability().', DEBUG_DEVELOPER); } } diff --git a/lib/adminlib.php b/lib/adminlib.php index 25ae3d0cae10..5d209bda3a2d 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -968,6 +968,8 @@ public function prune($name) { * @return bool True if successfully added, false if $something can not be added. */ public function add($parentname, $something, $beforesibling = null) { + global $CFG; + $parent = $this->locate($parentname); if (is_null($parent)) { debugging('parent does not exist!'); @@ -979,7 +981,7 @@ public function add($parentname, $something, $beforesibling = null) { debugging('error - parts of tree can be inserted only into parentable parts'); return false; } - if (debugging('', DEBUG_DEVELOPER) && !is_null($this->locate($something->name))) { + if ($CFG->debugdeveloper && !is_null($this->locate($something->name))) { // The name of the node is already used, simply warn the developer that this should not happen. // It is intentional to check for the debug level before performing the check. debugging('Duplicate admin page name: ' . $something->name, DEBUG_DEVELOPER); diff --git a/lib/classes/component.php b/lib/classes/component.php index 3f682218022c..0fa7c30d5feb 100644 --- a/lib/classes/component.php +++ b/lib/classes/component.php @@ -195,12 +195,9 @@ protected static function init() { protected static function is_developer() { global $CFG; + // Note we can not rely on $CFG->debug here because DB is not initialised yet. if (isset($CFG->config_php_settings['debug'])) { - // Standard moodle script. $debug = (int)$CFG->config_php_settings['debug']; - } else if (isset($CFG->debug)) { - // Usually script with ABORT_AFTER_CONFIG. - $debug = (int)$CFG->debug; } else { return false; } diff --git a/lib/classes/event/base.php b/lib/classes/event/base.php index 5fcd4047def8..f520fdd4e865 100644 --- a/lib/classes/event/base.php +++ b/lib/classes/event/base.php @@ -108,7 +108,7 @@ private final function __construct() { * @throws \coding_exception */ public static final function create(array $data = null) { - global $PAGE, $USER; + global $PAGE, $USER, $CFG; $data = (array)$data; @@ -178,7 +178,7 @@ public static final function create(array $data = null) { } // Warn developers if they do something wrong. - if (debugging('', DEBUG_DEVELOPER)) { // This should be replaced by new $CFG->slowdebug flag if introduced. + if ($CFG->debugdeveloper) { static $automatickeys = array('eventname', 'component', 'action', 'target', 'contextlevel', 'contextinstanceid', 'timecreated'); static $initkeys = array('crud', 'level', 'objecttable'); @@ -187,10 +187,10 @@ public static final function create(array $data = null) { continue; } else if (in_array($key, $automatickeys)) { - debugging("Data key '$key' is not allowed in \\core\\event\\base::create() method, it is set automatically"); + debugging("Data key '$key' is not allowed in \\core\\event\\base::create() method, it is set automatically", DEBUG_DEVELOPER); } else if (in_array($key, $initkeys)) { - debugging("Data key '$key' is not allowed in \\core\\event\\base::create() method, you need to set it in init() method"); + debugging("Data key '$key' is not allowed in \\core\\event\\base::create() method, you need to set it in init() method", DEBUG_DEVELOPER); } else if (!in_array($key, self::$fields)) { debugging("Data key '$key' does not exist in \\core\\event\\base"); @@ -395,7 +395,7 @@ protected function get_legacy_logdata() { * @throws \coding_exception */ protected final function validate_before_trigger() { - global $DB; + global $DB, $CFG; if (empty($this->data['crud'])) { throw new \coding_exception('crud must be specified in init() method of each method'); @@ -407,38 +407,38 @@ protected final function validate_before_trigger() { throw new \coding_exception('objecttable must be specified in init() method if objectid present'); } - if (debugging('', DEBUG_DEVELOPER)) { // This should be replaced by new $CFG->slowdebug flag if introduced. + if ($CFG->debugdeveloper) { // Ideally these should be coding exceptions, but we need to skip these for performance reasons // on production servers. if (!in_array($this->data['crud'], array('c', 'r', 'u', 'd'), true)) { - debugging("Invalid event crud value specified."); + debugging("Invalid event crud value specified.", DEBUG_DEVELOPER); } if (!is_number($this->data['level'])) { - debugging('Event property level must be a number'); + debugging('Event property level must be a number', DEBUG_DEVELOPER); } if (self::$fields !== array_keys($this->data)) { - debugging('Number of event data fields must not be changed in event classes'); + debugging('Number of event data fields must not be changed in event classes', DEBUG_DEVELOPER); } $encoded = json_encode($this->data['other']); if ($encoded === false or $this->data['other'] !== json_decode($encoded, true)) { - debugging('other event data must be compatible with json encoding'); + debugging('other event data must be compatible with json encoding', DEBUG_DEVELOPER); } if ($this->data['userid'] and !is_number($this->data['userid'])) { - debugging('Event property userid must be a number'); + debugging('Event property userid must be a number', DEBUG_DEVELOPER); } if ($this->data['courseid'] and !is_number($this->data['courseid'])) { - debugging('Event property courseid must be a number'); + debugging('Event property courseid must be a number', DEBUG_DEVELOPER); } if ($this->data['objectid'] and !is_number($this->data['objectid'])) { - debugging('Event property objectid must be a number'); + debugging('Event property objectid must be a number', DEBUG_DEVELOPER); } if ($this->data['relateduserid'] and !is_number($this->data['relateduserid'])) { - debugging('Event property relateduserid must be a number'); + debugging('Event property relateduserid must be a number', DEBUG_DEVELOPER); } if ($this->data['objecttable']) { if (!$DB->get_manager()->table_exists($this->data['objecttable'])) { - debugging('Unknown table specified in objecttable field'); + debugging('Unknown table specified in objecttable field', DEBUG_DEVELOPER); } } } @@ -521,7 +521,7 @@ public final function is_restored() { * @throws \coding_exception if used after ::trigger() */ public final function add_record_snapshot($tablename, $record) { - global $DB; + global $DB, $CFG; if ($this->triggered) { throw new \coding_exception('It is not possible to add snapshots after triggering of events'); @@ -529,9 +529,9 @@ public final function add_record_snapshot($tablename, $record) { // NOTE: this might use some kind of MUC cache, // hopefully we will not run out of memory here... - if (debugging('', DEBUG_DEVELOPER)) { // This should be replaced by new $CFG->slowdebug flag if introduced. + if ($CFG->debugdeveloper) { if (!$DB->get_manager()->table_exists($tablename)) { - debugging("Invalid table name '$tablename' specified, database table does not exist."); + debugging("Invalid table name '$tablename' specified, database table does not exist.", DEBUG_DEVELOPER); } } $this->recordsnapshots[$tablename][$record->id] = $record; diff --git a/lib/cronlib.php b/lib/cronlib.php index 0bc2f0cebd5d..41c7bb2c604c 100644 --- a/lib/cronlib.php +++ b/lib/cronlib.php @@ -46,8 +46,7 @@ function cron_run() { $DB->set_debug(true); } if (!empty($CFG->showcrondebugging)) { - $CFG->debug = DEBUG_DEVELOPER; - $CFG->debugdisplay = true; + set_debugging(DEBUG_DEVELOPER, true); } set_time_limit(0); diff --git a/lib/dml/pdo_moodle_database.php b/lib/dml/pdo_moodle_database.php index cc7b3bb0e43d..58874bd016ba 100644 --- a/lib/dml/pdo_moodle_database.php +++ b/lib/dml/pdo_moodle_database.php @@ -308,16 +308,17 @@ public function get_fieldset_sql($sql, array $params=null) { * @return array of objects, or empty array if no records were found, or false if an error occurred. */ public function get_records_sql($sql, array $params=null, $limitfrom=0, $limitnum=0) { + global $CFG; + $rs = $this->get_recordset_sql($sql, $params, $limitfrom, $limitnum); if (!$rs->valid()) { $rs->close(); // Not going to iterate (but exit), close rs return false; } $objects = array(); - $debugging = debugging('', DEBUG_DEVELOPER); foreach($rs as $value) { $key = reset($value); - if ($debugging && array_key_exists($key, $objects)) { + if ($CFG->debugdeveloper && array_key_exists($key, $objects)) { debugging("Did you remember to make the first column something unique in your call to get_records? Duplicate value '$key' found in column first column of '$sql'.", DEBUG_DEVELOPER); } $objects[$key] = (object)$value; diff --git a/lib/dml/tests/dml_test.php b/lib/dml/tests/dml_test.php index 59b76019ca0e..07ee27e7d751 100644 --- a/lib/dml/tests/dml_test.php +++ b/lib/dml/tests/dml_test.php @@ -1475,8 +1475,6 @@ public function test_get_records_list() { } public function test_get_records_sql() { - global $CFG; - $DB = $this->tdb; $dbman = $DB->get_manager(); @@ -1518,11 +1516,11 @@ public function test_get_records_sql() { $records = $DB->get_records_sql("SELECT course AS id, course AS course FROM {{$tablename}}", null); $this->assertDebuggingCalled(); $this->assertEquals(6, count($records)); - $CFG->debug = DEBUG_MINIMAL; + set_debugging(DEBUG_MINIMAL); $records = $DB->get_records_sql("SELECT course AS id, course AS course FROM {{$tablename}}", null); $this->assertDebuggingNotCalled(); $this->assertEquals(6, count($records)); - $CFG->debug = DEBUG_DEVELOPER; + set_debugging(DEBUG_DEVELOPER); // negative limits = no limits $records = $DB->get_records_sql("SELECT * FROM {{$tablename}} ORDER BY id", null, -1, -1); @@ -1734,8 +1732,6 @@ public function test_get_record_select() { } public function test_get_record_sql() { - global $CFG; - $DB = $this->tdb; $dbman = $DB->get_manager(); @@ -1774,10 +1770,10 @@ public function test_get_record_sql() { $this->assertNotEmpty($DB->get_record_sql("SELECT * FROM {{$tablename}}", array(), IGNORE_MISSING)); $this->assertDebuggingCalled(); - $CFG->debug = DEBUG_MINIMAL; + set_debugging(DEBUG_MINIMAL); $this->assertNotEmpty($DB->get_record_sql("SELECT * FROM {{$tablename}}", array(), IGNORE_MISSING)); $this->assertDebuggingNotCalled(); - $CFG->debug = DEBUG_DEVELOPER; + set_debugging(DEBUG_DEVELOPER); // multiple matches ignored $this->assertNotEmpty($DB->get_record_sql("SELECT * FROM {{$tablename}}", array(), IGNORE_MULTIPLE)); diff --git a/lib/editor/tinymce/classes/plugin.php b/lib/editor/tinymce/classes/plugin.php index ed33fa49efc0..de303006de45 100644 --- a/lib/editor/tinymce/classes/plugin.php +++ b/lib/editor/tinymce/classes/plugin.php @@ -360,7 +360,7 @@ public function get_tinymce_file_url($file='', $absolute=true) { // Version number comes from plugin version.php, except in developer // mode where the special string 'dev' is used (prevents cacheing and // serves unminified JS). - if (debugging('', DEBUG_DEVELOPER)) { + if ($CFG->debugdeveloper) { $version = '-1'; } else { $version = $this->get_version(); diff --git a/lib/editor/tinymce/cli/update_lang_files.php b/lib/editor/tinymce/cli/update_lang_files.php index 790d42e44f95..1d692229a634 100644 --- a/lib/editor/tinymce/cli/update_lang_files.php +++ b/lib/editor/tinymce/cli/update_lang_files.php @@ -26,7 +26,7 @@ require __DIR__ . '/../../../../config.php'; -if (!debugging('', DEBUG_DEVELOPER)) { +if (!$CFG->debugdeveloper) { die('Only for developers!!!!!'); } diff --git a/lib/editor/tinymce/lib.php b/lib/editor/tinymce/lib.php index eae4a60dd5a6..838f845dcddc 100644 --- a/lib/editor/tinymce/lib.php +++ b/lib/editor/tinymce/lib.php @@ -100,7 +100,7 @@ public function head_setup() { public function use_editor($elementid, array $options=null, $fpoptions=null) { global $PAGE, $CFG; // Note: use full moodle_url instance to prevent standard JS loader, make sure we are using https on profile page if required. - if (debugging('', DEBUG_DEVELOPER)) { + if ($CFG->debugdeveloper) { $PAGE->requires->js(new moodle_url($CFG->httpswwwroot.'/lib/editor/tinymce/tiny_mce/'.$this->version.'/tiny_mce_src.js')); } else { $PAGE->requires->js(new moodle_url($CFG->httpswwwroot.'/lib/editor/tinymce/tiny_mce/'.$this->version.'/tiny_mce.js')); diff --git a/lib/filestorage/file_storage.php b/lib/filestorage/file_storage.php index 9eeca4aab7b4..3783eeeba521 100644 --- a/lib/filestorage/file_storage.php +++ b/lib/filestorage/file_storage.php @@ -1624,6 +1624,8 @@ public function convert_image($filerecord, $fid, $newwidth = null, $newheight = * @return array (contenthash, filesize, newfile) */ public function add_file_to_pool($pathname, $contenthash = NULL) { + global $CFG; + if (!is_readable($pathname)) { throw new file_exception('storedfilecannotread', '', $pathname); } @@ -1635,14 +1637,14 @@ public function add_file_to_pool($pathname, $contenthash = NULL) { if (is_null($contenthash)) { $contenthash = sha1_file($pathname); - } else if (debugging('', DEBUG_DEVELOPER)) { + } else if ($CFG->debugdeveloper) { $filehash = sha1_file($pathname); if ($filehash === false) { throw new file_exception('storedfilecannotread', '', $pathname); } if ($filehash !== $contenthash) { // Hopefully this never happens, if yes we need to fix calling code. - debugging("Invalid contenthash submitted for file $pathname"); + debugging("Invalid contenthash submitted for file $pathname", DEBUG_DEVELOPER); $contenthash = $filehash; } } diff --git a/lib/formslib.php b/lib/formslib.php index 075bd8039198..abeb09d1b468 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -61,7 +61,7 @@ function pear_handle_error($error){ print_object($error->backtrace); } -if (!empty($CFG->debug) and ($CFG->debug >= DEBUG_ALL or $CFG->debug == -1)){ +if ($CFG->debugdeveloper) { //TODO: this is a wrong place to init PEAR! $GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_CALLBACK; $GLOBALS['_PEAR_default_error_options'] = 'pear_handle_error'; @@ -1261,7 +1261,9 @@ public static function get_js_module() { * @return void */ private function detectMissingSetType() { - if (!debugging('', DEBUG_DEVELOPER)) { + global $CFG; + + if (!$CFG->debugdeveloper) { // Only for devs. return; } diff --git a/lib/installlib.php b/lib/installlib.php index 461f552ff849..f60605b1eef5 100644 --- a/lib/installlib.php +++ b/lib/installlib.php @@ -424,6 +424,7 @@ function install_cli_database(array $options, $interactive) { @ini_set('display_errors', '1'); $CFG->debug = (E_ALL | E_STRICT); $CFG->debugdisplay = true; + $CFG->debugdeveloper = true; $CFG->version = ''; $CFG->release = ''; diff --git a/lib/minify/config.php b/lib/minify/config.php index bf8fc20c9bf9..0750f229ae9a 100644 --- a/lib/minify/config.php +++ b/lib/minify/config.php @@ -14,7 +14,7 @@ $min_enableBuilder = false; $min_errorLogger = false; -$min_allowDebugFlag = debugging('', DEBUG_DEVELOPER); +$min_allowDebugFlag = $CFG->debugdeveloper; $min_cachePath = $CFG->tempdir; $min_documentRoot = $CFG->dirroot.'/lib/minify'; $min_cacheFileLocking = empty($CFG->preventfilelocking); diff --git a/lib/moodlelib.php b/lib/moodlelib.php index cfab5d8cbe1c..f32215c0cbbe 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -6728,8 +6728,8 @@ 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) === '') { - throw new coding_exception('Invalid string identifier. The identifier cannot be empty. Please fix your get_string() call.'); + if ($CFG->debugdeveloper && clean_param($identifier, PARAM_STRINGID) === '') { + throw new coding_exception('Invalid string identifier. The identifier cannot be empty. Please fix your get_string() call.', DEBUG_DEVELOPER); } // There is now a forth argument again, this time it is a boolean however so @@ -7222,7 +7222,7 @@ function get_list_of_plugins($directory='mod', $exclude='', $basedir='') { $basedir = $basedir .'/'. $directory; } - if (empty($exclude) and debugging('', DEBUG_DEVELOPER)) { + if ($CFG->debugdeveloper and empty($exclude)) { // Make sure devs do not use this to list normal plugins, // this is intended for general directories that are not plugins! @@ -10068,8 +10068,8 @@ protected function get_string() { // Check if we need to process the string. if ($this->string === null) { // Check the quality of the identifier. - if (debugging('', DEBUG_DEVELOPER) && 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'); + if ($CFG->debugdeveloper && 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', DEBUG_DEVELOPER); } // Process the string. diff --git a/lib/outputlib.php b/lib/outputlib.php index 08da9d89ea35..be02e35db1e5 100644 --- a/lib/outputlib.php +++ b/lib/outputlib.php @@ -1678,7 +1678,8 @@ class xhtml_container_stack { * Constructor */ public function __construct() { - $this->isdebugging = debugging('', DEBUG_DEVELOPER); + global $CFG; + $this->isdebugging = $CFG->debugdeveloper; } /** diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index be2dfea5836c..d61279a473b7 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -2532,7 +2532,7 @@ public function fatal_error($message, $moreinfourl, $link, $backtrace, $debuginf } $output .= $this->box($message, 'errorbox', null, array('data-rel' => 'fatalerror')); - if (debugging('', DEBUG_DEVELOPER)) { + if ($CFG->debugdeveloper) { if (!empty($debuginfo)) { $debuginfo = s($debuginfo); // removes all nasty JS $debuginfo = str_replace("\n", '
', $debuginfo); // keep newlines @@ -3364,7 +3364,7 @@ public function heading($text, $level = 2, $classes = 'main', $id = null) { public function fatal_error($message, $moreinfourl, $link, $backtrace, $debuginfo = null) { $output = "!!! $message !!!\n"; - if (debugging('', DEBUG_DEVELOPER)) { + if ($CFG->debugdeveloper) { if (!empty($debuginfo)) { $output .= $this->notification($debuginfo, 'notifytiny'); } diff --git a/lib/outputrequirementslib.php b/lib/outputrequirementslib.php index 4374c77a0585..ac06df994349 100644 --- a/lib/outputrequirementslib.php +++ b/lib/outputrequirementslib.php @@ -224,7 +224,7 @@ public function __construct() { )); // Set some more loader options applying to groups too. - if (debugging('', DEBUG_DEVELOPER)) { + if ($CFG->debugdeveloper) { // When debugging is enabled, we want to load the non-minified (RAW) versions of YUI library modules rather // than the DEBUG versions as these generally generate too much logging for our purposes. // However we do want the DEBUG versions of our Moodle-specific modules. @@ -270,7 +270,7 @@ protected function init_requirements_data(moodle_page $page, core_renderer $rend 'jsrev' => ((empty($CFG->cachejs) or empty($CFG->jsrev)) ? -1 : $CFG->jsrev), 'svgicons' => $page->theme->use_svg_icons() ); - if (debugging('', DEBUG_DEVELOPER)) { + if ($CFG->debugdeveloper) { $this->M_cfg['developerdebug'] = true; } @@ -436,7 +436,7 @@ public function jquery_plugin($plugin, $component = 'core') { $this->jqueryplugins[$plugin]->urls = array(); foreach ($plugins[$plugin]['files'] as $file) { - if (debugging('', DEBUG_DEVELOPER)) { + if ($CFG->debugdeveloper) { if (!file_exists("$componentdir/jquery/$file")) { debugging("Invalid file '$file' specified in jQuery plugin '$plugin' in component '$component'"); continue; @@ -746,7 +746,7 @@ public function js_module($module) { // Don't load this module if we already have, no need to! if ($this->js_module_loaded($module['name'])) { - if (debugging('', DEBUG_DEVELOPER)) { + if ($CFG->debugdeveloper) { $this->debug_moduleloadstacktraces[$module['name']][] = format_backtrace(debug_backtrace()); } return; @@ -780,7 +780,7 @@ public function js_module($module) { } else { $this->YUI_config->add_module_config($module['name'], $module); } - if (debugging('', DEBUG_DEVELOPER)) { + if ($CFG->debugdeveloper) { if (!array_key_exists($module['name'], $this->debug_moduleloadstacktraces)) { $this->debug_moduleloadstacktraces[$module['name']] = array(); } diff --git a/lib/phpunit/bootstrap.php b/lib/phpunit/bootstrap.php index 6dee6211041c..749bcfa8b731 100644 --- a/lib/phpunit/bootstrap.php +++ b/lib/phpunit/bootstrap.php @@ -198,6 +198,7 @@ // force the same CFG settings in all sites $CFG->debug = (E_ALL | E_STRICT); // can not use DEBUG_DEVELOPER yet +$CFG->debugdeveloper = true; $CFG->debugdisplay = 1; error_reporting($CFG->debug); ini_set('display_errors', '1'); diff --git a/lib/phpunit/classes/advanced_testcase.php b/lib/phpunit/classes/advanced_testcase.php index 0a4848d9141f..1bd0d7d891fe 100644 --- a/lib/phpunit/classes/advanced_testcase.php +++ b/lib/phpunit/classes/advanced_testcase.php @@ -248,7 +248,8 @@ public function getDebuggingMessages() { } /** - * Clear all previous debugging messages in current test. + * Clear all previous debugging messages in current test + * and revert to default DEVELOPER_DEBUG level. */ public function resetDebugging() { phpunit_util::reset_debugging(); diff --git a/lib/phpunit/classes/util.php b/lib/phpunit/classes/util.php index 552e78aaca8b..4b9d7a046580 100644 --- a/lib/phpunit/classes/util.php +++ b/lib/phpunit/classes/util.php @@ -594,6 +594,7 @@ public static function debugging_triggered($message, $level, $from) { */ public static function reset_debugging() { self::$debuggings = array(); + set_debugging(DEBUG_DEVELOPER); } /** diff --git a/lib/phpunit/tests/advanced_test.php b/lib/phpunit/tests/advanced_test.php index 61f5a30f951a..f6c071908c9f 100644 --- a/lib/phpunit/tests/advanced_test.php +++ b/lib/phpunit/tests/advanced_test.php @@ -65,9 +65,10 @@ public function test_debugging() { $debuggings = $this->getDebuggingMessages(); $this->assertEquals(0, count($debuggings)); - $CFG->debug = DEBUG_NONE; + set_debugging(DEBUG_NONE); debugging('hokus'); $this->assertDebuggingNotCalled(); + set_debugging(DEBUG_DEVELOPER); } public function test_set_user() { diff --git a/lib/setup.php b/lib/setup.php index acc466adfc91..f0ba4a5561f0 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -143,6 +143,11 @@ } } +// Make sure there is some database table prefix. +if (!isset($CFG->prefix)) { + $CFG->prefix = ''; +} + // Define admin directory if (!isset($CFG->admin)) { // Just in case it isn't defined in config.php $CFG->admin = 'admin'; // This is relative to the wwwroot and dirroot @@ -166,6 +171,16 @@ $CFG->localcachedir = "$CFG->dataroot/localcache"; } +// Location of all languages except core English pack. +if (!isset($CFG->langotherroot)) { + $CFG->langotherroot = $CFG->dataroot.'/lang'; +} + +// Location of local lang pack customisations (dirs with _local suffix). +if (!isset($CFG->langlocalroot)) { + $CFG->langlocalroot = $CFG->dataroot.'/lang'; +} + // The current directory in PHP version 4.3.0 and above isn't necessarily the // directory of the script when run from the command line. The require_once() // would fail, so we'll have to chdir() @@ -309,6 +324,23 @@ $CFG->yui2version = '2.9.0'; $CFG->yui3version = '3.9.1'; +// Store settings from config.php in array in $CFG - we can use it later to detect problems and overrides. +if (!isset($CFG->config_php_settings)) { + $CFG->config_php_settings = (array)$CFG; + // Forced plugin settings override values from config_plugins table. + unset($CFG->config_php_settings['forced_plugin_settings']); + if (!isset($CFG->forced_plugin_settings)) { + $CFG->forced_plugin_settings = array(); + } +} + +if (isset($CFG->debug)) { + $CFG->debug = (int)$CFG->debug; +} else { + $CFG->debug = 0; +} +$CFG->debugdeveloper = ($CFG->debug & E_ALL and $CFG->debug & E_STRICT); // DEBUG_DEVELOPER is not available yet. + if (!defined('MOODLE_INTERNAL')) { // Necessary because cli installer has to define it earlier. /** Used by library scripts to check they are being called by Moodle. */ define('MOODLE_INTERNAL', true); @@ -321,11 +353,7 @@ if (defined('ABORT_AFTER_CONFIG')) { if (!defined('ABORT_AFTER_CONFIG_CANCEL')) { // hide debugging if not enabled in config.php - we do not want to disclose sensitive info - if (isset($CFG->debug)) { - error_reporting($CFG->debug); - } else { - error_reporting(0); - } + error_reporting($CFG->debug); if (NO_DEBUG_DISPLAY) { // Some parts of Moodle cannot display errors and debug at all. ini_set('display_errors', '0'); @@ -454,13 +482,6 @@ */ global $SCRIPT; -// Store settings from config.php in array in $CFG - we can use it later to detect problems and overrides -$CFG->config_php_settings = (array)$CFG; -// Forced plugin settings override values from config_plugins table -unset($CFG->config_php_settings['forced_plugin_settings']); -if (!isset($CFG->forced_plugin_settings)) { - $CFG->forced_plugin_settings = array(); -} // Set httpswwwroot default value (this variable will replace $CFG->wwwroot // inside some URLs used in HTTPSPAGEREQUIRED pages. $CFG->httpswwwroot = $CFG->wwwroot; @@ -505,20 +526,6 @@ exit(1); } -if (!isset($CFG->prefix)) { // Just in case it isn't defined in config.php - $CFG->prefix = ''; -} - -// location of all languages except core English pack -if (!isset($CFG->langotherroot)) { - $CFG->langotherroot = $CFG->dataroot.'/lang'; -} - -// location of local lang pack customisations (dirs with _local suffix) -if (!isset($CFG->langlocalroot)) { - $CFG->langlocalroot = $CFG->dataroot.'/lang'; -} - //point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else //the problem is that we need specific version of quickforms and hacked excel files :-( ini_set('include_path', $CFG->libdir.'/pear' . PATH_SEPARATOR . ini_get('include_path')); @@ -579,20 +586,40 @@ unset($dbhash); } -// Disable errors for now - needed for installation when debug enabled in config.php -if (isset($CFG->debug)) { - $originalconfigdebug = $CFG->debug; - unset($CFG->debug); +// Load up any configuration from the config table or MUC cache. +if (PHPUNIT_TEST) { + phpunit_util::initialise_cfg(); } else { - $originalconfigdebug = null; + initialise_cfg(); } -// Load up any configuration from the config table +if (isset($CFG->debug)) { + $CFG->debug = (int)$CFG->debug; + error_reporting($CFG->debug); +} else { + $CFG->debug = 0; +} +$CFG->debugdeveloper = ($CFG->debug & DEBUG_DEVELOPER); -if (PHPUNIT_TEST) { - phpunit_util::initialise_cfg(); +// Find out if PHP configured to display warnings, +// this is a security problem because some moodle scripts may +// disclose sensitive information. +if (ini_get_bool('display_errors')) { + define('WARN_DISPLAY_ERRORS_ENABLED', true); +} +// If we want to display Moodle errors, then try and set PHP errors to match. +if (!isset($CFG->debugdisplay)) { + // Keep it "as is" during installation. +} else if (NO_DEBUG_DISPLAY) { + // Some parts of Moodle cannot display errors and debug at all. + ini_set('display_errors', '0'); + ini_set('log_errors', '1'); +} else if (empty($CFG->debugdisplay)) { + ini_set('display_errors', '0'); + ini_set('log_errors', '1'); } else { - initialise_cfg(); + // This is very problematic in XHTML strict mode! + ini_set('display_errors', '1'); } // Verify upgrade is not running unless we are in a script that needs to execute in any case @@ -609,14 +636,6 @@ $DB->set_logging(true); } -// Prevent warnings from roles when upgrading with debug on -if (isset($CFG->debug)) { - $originaldatabasedebug = $CFG->debug; - unset($CFG->debug); -} else { - $originaldatabasedebug = null; -} - // enable circular reference collector in PHP 5.3, // it helps a lot when using large complex OOP structures such as in amos or gradebook if (function_exists('gc_enable')) { @@ -628,40 +647,6 @@ register_shutdown_function('moodle_request_shutdown'); } -// Set error reporting back to normal -if ($originaldatabasedebug === null) { - $CFG->debug = DEBUG_MINIMAL; -} else { - $CFG->debug = $originaldatabasedebug; -} -if ($originalconfigdebug !== null) { - $CFG->debug = $originalconfigdebug; -} -unset($originalconfigdebug); -unset($originaldatabasedebug); -error_reporting($CFG->debug); - -// find out if PHP configured to display warnings, -// this is a security problem because some moodle scripts may -// disclose sensitive information -if (ini_get_bool('display_errors')) { - define('WARN_DISPLAY_ERRORS_ENABLED', true); -} -// If we want to display Moodle errors, then try and set PHP errors to match -if (!isset($CFG->debugdisplay)) { - // keep it "as is" during installation -} else if (NO_DEBUG_DISPLAY) { - // some parts of Moodle cannot display errors and debug at all. - ini_set('display_errors', '0'); - ini_set('log_errors', '1'); -} else if (empty($CFG->debugdisplay)) { - ini_set('display_errors', '0'); - ini_set('log_errors', '1'); -} else { - // This is very problematic in XHTML strict mode! - ini_set('display_errors', '1'); -} - // detect unsupported upgrade jump as soon as possible - do not change anything, do not use system functions if (!empty($CFG->version) and $CFG->version < 2007101509) { print_error('upgraderequires19', 'error'); diff --git a/lib/setuplib.php b/lib/setuplib.php index f75a8a9bd04c..1b43764f4498 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -729,25 +729,28 @@ function setup_validate_php_configuration() { } /** - * Initialise global $CFG variable - * @return void + * Initialise global $CFG variable. + * @private to be used only from lib/setup.php */ function initialise_cfg() { global $CFG, $DB; + if (!$DB) { + // This should not happen. + return; + } + try { - if ($DB) { - $localcfg = get_config('core'); - foreach ($localcfg as $name => $value) { - if (property_exists($CFG, $name)) { - // config.php settings always take precedence - continue; - } - $CFG->{$name} = $value; - } - } + $localcfg = get_config('core'); } catch (dml_exception $e) { - // most probably empty db, going to install soon + // Most probably empty db, going to install soon. + return; + } + + foreach ($localcfg as $name => $value) { + // Note that get_config() keeps forced settings + // and normalises values to string if possible. + $CFG->{$name} = $value; } } diff --git a/lib/tests/event_test.php b/lib/tests/event_test.php index 414d105ff9b6..2c06a4306dea 100644 --- a/lib/tests/event_test.php +++ b/lib/tests/event_test.php @@ -637,10 +637,10 @@ public function test_problematic_events() { $event2 = \core_tests\event\problematic_event1::create(array('xxx'=>0, 'context'=>\context_system::instance())); $this->assertDebuggingCalled(); - $CFG->debug = 0; + set_debugging(DEBUG_NONE); $event3 = \core_tests\event\problematic_event1::create(array('xxx'=>0, 'context'=>\context_system::instance())); $this->assertDebuggingNotCalled(); - $CFG->debug = E_ALL | E_STRICT; + set_debugging(DEBUG_DEVELOPER); $event4 = \core_tests\event\problematic_event1::create(array('context'=>\context_system::instance(), 'other'=>array('a'=>1))); $event4->trigger(); diff --git a/lib/tests/statslib_test.php b/lib/tests/statslib_test.php index fe9728caf060..50fd289d7f5e 100644 --- a/lib/tests/statslib_test.php +++ b/lib/tests/statslib_test.php @@ -299,24 +299,22 @@ protected function verify_stats($expected, $output = '') { * Test progress output when debug is on. */ public function test_statslib_progress_debug() { - global $CFG; - - $CFG->debug = DEBUG_ALL; + set_debugging(DEBUG_ALL); $this->expectOutputString('1:0 '); stats_progress('init'); stats_progress('1'); + $this->resetDebugging(); } /** * Test progress output when debug is off. */ public function test_statslib_progress_no_debug() { - global $CFG; - - $CFG->debug = DEBUG_NONE; + set_debugging(DEBUG_NONE); $this->expectOutputString('.'); stats_progress('init'); stats_progress('1'); + $this->resetDebugging(); } /** diff --git a/lib/upgrade.txt b/lib/upgrade.txt index f7fc350bebba..29a297f941f7 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -16,6 +16,8 @@ information provided here is intended especially for developers. * The string manager classes were renamed. Note that they should not be modified or used directly, always use get_string_manager() to get instance of the string manager. * The ability to use an 'insecure' rc4encrypt/rc4decrypt key has been removed. +* Use $CFG->debugdeveloper instead of debugging('', DEBUG_DEVELOPER). +* Use set_debugging(DEBUG_xxx) when changing debugging level for current request. DEPRECATIONS: Various previously deprecated functions have now been altered to throw DEBUG_DEVELOPER debugging notices diff --git a/lib/upgradelib.php b/lib/upgradelib.php index e49b9568f5fd..3edf94dc598a 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -1148,7 +1148,7 @@ function upgrade_handle_exception($ex, $plugin = null) { upgrade_log(UPGRADE_LOG_ERROR, $plugin, 'Exception: ' . get_class($ex), $info->message, $info->backtrace); // Always turn on debugging - admins need to know what is going on - $CFG->debug = DEBUG_DEVELOPER; + set_debugging(DEBUG_DEVELOPER, true); default_exception_handler($ex, true, $plugin); } diff --git a/lib/weblib.php b/lib/weblib.php index ee1d160bdd44..2b6c7d7f9817 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -1216,7 +1216,7 @@ function format_text($text, $format = FORMAT_MOODLE, $options = null, $courseidd // the text before storing into database which would be itself big bug.. $text = str_replace("\"$CFG->httpswwwroot/draftfile.php", "\"$CFG->httpswwwroot/brokenfile.php#", $text); - if (debugging('', DEBUG_DEVELOPER)) { + if ($CFG->debugdeveloper) { if (strpos($text, '@@PLUGINFILE@@/') !== false) { debugging('Before calling format_text(), the content must be processed with file_rewrite_pluginfile_urls()', DEBUG_DEVELOPER); @@ -2791,6 +2791,24 @@ function print_tabs($tabrows, $selected = null, $inactive = null, $activated = n } } +/** + * Alter debugging level for the current request, + * the change is not saved in database. + * + * @param int $level one of the DEBUG_* constants + * @param bool $debugdisplay + */ +function set_debugging($level, $debugdisplay = null) { + global $CFG; + + $CFG->debug = (int)$level; + $CFG->debugdeveloper = ($CFG->debug & DEBUG_DEVELOPER); + + if ($debugdisplay !== null) { + $CFG->debugdisplay = (bool)$debugdisplay; + } +} + /** * Standard Debugging Function * diff --git a/mod/workshop/renderer.php b/mod/workshop/renderer.php index a4311a8a5970..4a29a74b9f86 100644 --- a/mod/workshop/renderer.php +++ b/mod/workshop/renderer.php @@ -339,6 +339,7 @@ protected function render_workshop_user_plan(workshop_user_plan $plan) { * @return string HTML to be echoed */ protected function render_workshop_allocation_result(workshop_allocation_result $result) { + global $CFG; $status = $result->get_status(); @@ -384,7 +385,7 @@ protected function render_workshop_allocation_result(workshop_allocation_result if (is_array($logs) and !empty($logs)) { $o .= html_writer::start_tag('ul', array('class' => 'allocation-init-results')); foreach ($logs as $log) { - if ($log->type == 'debug' and !debugging('', DEBUG_DEVELOPER)) { + if ($log->type == 'debug' and !$CFG->debugdeveloper) { // display allocation debugging messages for developers only continue; } diff --git a/report/performance/locallib.php b/report/performance/locallib.php index b14a12756800..993054638bb4 100644 --- a/report/performance/locallib.php +++ b/report/performance/locallib.php @@ -209,13 +209,9 @@ public static function report_performance_check_debugmsg() { DEBUG_NORMAL => 'debugnormal', DEBUG_ALL => 'debugall', DEBUG_DEVELOPER => 'debugdeveloper'); - // If debug is not set then consider it as 0. - if (!isset($CFG->themedesignermode)) { - $CFG->debug = DEBUG_NONE; - } $issueresult->statusstr = get_string($debugchoices[$CFG->debug], 'admin'); - if ($CFG->debug != DEBUG_DEVELOPER) { + if (!$CFG->debugdeveloper) { $issueresult->status = self::REPORT_PERFORMANCE_OK; $issueresult->comment = get_string('check_debugmsg_comment_nodeveloper', 'report_performance'); } else {