diff --git a/lib/accesslib.php b/lib/accesslib.php index c1c7abb1c53..5371569c411 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -361,9 +361,7 @@ function capability_search($capability, $context, $capabilities) { global $USER, $CFG; if (isset($capabilities[$context->id][$capability])) { - if ($CFG->debug > 15) { - notify("Found $capability in context $context->id at level $context->aggregatelevel: ".$capabilities[$context->id][$capability], 'notifytiny'); - } + debugging("Found $capability in context $context->id at level $context->aggregatelevel: ".$capabilities[$context->id][$capability], E_ALL); return ($capabilities[$context->id][$capability]); } @@ -425,9 +423,7 @@ function capability_search($capability, $context, $capabilities) { error ('This is an unknown context!'); return false; } - if ($CFG->debug > 15) { - notify("Found $capability recursively from context $context->id at level $context->aggregatelevel: $permission", 'notifytiny'); - } + debugging("Found $capability recursively from context $context->id at level $context->aggregatelevel: $permission", E_ALL); return $permission; } @@ -1012,9 +1008,7 @@ function get_context_instance($aggregatelevel=NULL, $instance=SITEID) { /// If no level is supplied then return the current global context if there is one if (empty($aggregatelevel)) { if (empty($CONTEXT)) { - if ($CFG->debug > 7) { - notify("Error: get_context_instance() called without a context"); - } + debugging("Error: get_context_instance() called without a context"); } else { return $CONTEXT; } @@ -1232,9 +1226,7 @@ function get_roles_with_capability($capability, $permission=NULL, $context='') { function role_assign($roleid, $userid, $groupid, $contextid, $timestart=0, $timeend=0, $hidden=0, $enrol='manual') { global $USER, $CFG; - if ($CFG->debug > 7) { - notify("Assign roleid $roleid userid $userid contextid $contextid", 'notifytiny'); - } + debugging("Assign roleid $roleid userid $userid contextid $contextid", E_ALL); /// Do some data validation diff --git a/lib/datalib.php b/lib/datalib.php index 8869474033e..6f800d6001e 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -1238,7 +1238,7 @@ function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user $result = $db->Execute('INSERT INTO '. $CFG->prefix .'log (time, userid, course, ip, module, cmid, action, url, info) VALUES (' . "'$timenow', '$userid', '$courseid', '$REMOTE_ADDR', '$module', '$cm', '$action', '$url', '$info')"); - if (!$result and ($CFG->debug > 7)) { + if (!$result and debugging()) { echo '
Error: Could not insert a new entry to the Moodle log
'; // Don't throw an error } diff --git a/lib/dmllib.php b/lib/dmllib.php index da36bc89d68..1edb34e236c 100644 --- a/lib/dmllib.php +++ b/lib/dmllib.php @@ -402,7 +402,7 @@ function get_record_sql($sql, $expectmultiple=false, $nolimit=false) { } else if ($expectmultiple) { $limitfrom = 0; $limitnum = 1; - } else if (isset($CFG->debug) && $CFG->debug > 7) { + } else if (debugging()) { // Debugging mode - don't use a limit of 1, but do change the SQL, because sometimes that // causes errors, and in non-debug mode you don't see the error message and it is // impossible to know what's wrong. @@ -608,9 +608,7 @@ function get_recordset_sql($sql, $limitfrom=null, $limitnum=null) { $rs = $db->Execute($sql); } if (!$rs) { - if (isset($CFG->debug) and $CFG->debug > 7) { - notify($db->ErrorMsg() .'' . "\n"; $mail->SMTPDebug = true; } @@ -6645,9 +6645,13 @@ function debugging($message='', $level=E_NOTICE) { global $CFG; + if (empty($CFG->debug)) { + return false; + } + if ($CFG->debug >= $level) { if ($message) { - notify($message); + notify($message, 'notifytiny'); } return true; } diff --git a/lib/pagelib.php b/lib/pagelib.php index 3d55e96cf96..49950ade3c9 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -69,9 +69,7 @@ function page_create_object($type, $id = NULL) { if ($object->get_type() !== $type) { // Somehow somewhere someone made a mistake - if ($CFG->debug > 7) { - error('Page object\'s type ('. $object->get_type() .') does not match requested type ('. $type .')'); - } + debugging('Page object\'s type ('. $object->get_type() .') does not match requested type ('. $type .')'); } $object->init_quick($data); @@ -99,15 +97,11 @@ function page_map_class($type, $classname = NULL) { } if (!isset($mappings[$type])) { - if ($CFG->debug > 7) { - error('Page class mapping requested for unknown type: '.$type); - } + debugging('Page class mapping requested for unknown type: '.$type); } if (empty($classname) && !class_exists($mappings[$type])) { - if ($CFG->debug > 7) { - error('Page class mapping for id "'.$type.'" exists but class "'.$mappings[$type].'" is not defined'); - } + debugging('Page class mapping for id "'.$type.'" exists but class "'.$mappings[$type].'" is not defined'); } return $mappings[$type]; diff --git a/lib/rsslib.php b/lib/rsslib.php index 85736d7dfd2..1ea2038cff9 100644 --- a/lib/rsslib.php +++ b/lib/rsslib.php @@ -354,11 +354,7 @@ define('MAGPIE_CACHE_DIR', $CFG->dataroot .'/cache/rsscache'); define('MAGPIE_CACHE_ON', true); //might want to expose as an admin config option, but perhaps this is something that should truly just be on unless the code is tweaked define('MAGPIE_CACHE_FRESH_ONLY', false); //should be exposed as an admin config option define('MAGPIE_CACHE_AGE', $CFG->block_rss_timeout); -if ($CFG->debug) { - define('MAGPIE_DEBUG', $CFG->debug); // magpie, like moodle, takes an integer debug -} else { - define('MAGPIE_DEBUG', 0); // 0 is DEBUG off for magpie -} +define('MAGPIE_DEBUG', $CFG->debug); // magpie, like moodle, takes an integer debug // defines for config var block_rss_client_submitters define('SUBMITTERS_ALL_ACCOUNT_HOLDERS', 0); diff --git a/lib/setup.php b/lib/setup.php index 46d0b25fbbe..36bb1f5a20c 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -258,7 +258,7 @@ global $HTTPSPAGEREQUIRED; /// Set error reporting back to normal if ($originaldatabasedebug == -1) { - $CFG->debug = 5; + $CFG->debug = E_PARSE; } else { $CFG->debug = $originaldatabasedebug; } diff --git a/lib/weblib.php b/lib/weblib.php index 9c7a5577ae1..1bb544216ab 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -333,9 +333,7 @@ function data_submitted($url='') { if (match_referer($url)) { return (object)$_POST; } else { - if ($CFG->debug > 10) { - notice('The form did not come from this page! (referer = '. get_referer() .')'); - } + debugging('The form did not come from this page! (referer = '. get_referer() .')'); return false; } } @@ -2021,9 +2019,7 @@ function print_header ($title='', $heading='', $navigation='', $focus='', /// This makes sure that the header is never repeated twice on a page if (defined('HEADER_PRINTED')) { - if ($CFG->debug > 7) { - notify('print_header() was called more than once - this should not happen. Please check the code for this page closely. Note: error() and redirect() are now safe to call after print_header().'); - } + debugging('print_header() was called more than once - this should not happen. Please check the code for this page closely. Note: error() and redirect() are now safe to call after print_header().'); return; } define('HEADER_PRINTED', 'true'); @@ -2324,7 +2320,7 @@ function print_footer($course=NULL, $usercourse=NULL, $return=false) { if (defined('MDL_PERFTOLOG')) { error_log("PERF: " . $perf['txt']); } - if (defined('MDL_PERFTOFOOT') || $CFG->debug > 7 || $CFG->perfdebug > 7) { + if (defined('MDL_PERFTOFOOT') || debugging() || $CFG->perfdebug > 7) { $performanceinfo = $perf['html']; } }