]> git.mjollnir.org Git - moodle.git/commitdiff
CHanged a lot of CFG->debug stuff to use the new debuggin() function
authormoodler <moodler>
Wed, 13 Sep 2006 09:45:07 +0000 (09:45 +0000)
committermoodler <moodler>
Wed, 13 Sep 2006 09:45:07 +0000 (09:45 +0000)
lib/accesslib.php
lib/datalib.php
lib/dmllib.php
lib/moodlelib.php
lib/pagelib.php
lib/rsslib.php
lib/setup.php
lib/weblib.php

index c1c7abb1c53a2c246a647292895edf4f28a7fdc2..5371569c411e4fddb85f2f6a9ae99b6f558754f6 100755 (executable)
@@ -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
 
index 8869474033e13b666dc813b8ae1479df38c188f0..6f800d6001e6fa6163582e3b53a260f94ed2592f 100644 (file)
@@ -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 '<p>Error: Could not insert a new entry to the Moodle log</p>';  // Don't throw an error
     }
 
index da36bc89d684373b4a0a205ccffcf5ca7adf3337..1edb34e236c9698d0441e7f74f93efef615e90a6 100644 (file)
@@ -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() .'<br /><br />'. $sql);
-        }
+        debugging($db->ErrorMsg() .'<br /><br />'. $sql);
         if (!empty($CFG->dblogerror)) {
             $debug=array_shift(debug_backtrace());
             error_log("SQL ".$db->ErrorMsg()." in {$debug['file']} on line {$debug['line']}. STATEMENT:  $sql with limits ($limitfrom, $limitnum)");
@@ -884,9 +882,7 @@ function get_fieldset_sql($sql) {
 
     $rs = $db->Execute($sql);
     if (!$rs) {
-        if (isset($CFG->debug) and $CFG->debug > 7) {
-            notify($db->ErrorMsg() .'<br /><br />'. $sql);
-        }
+        debugging($db->ErrorMsg() .'<br /><br />'. $sql);
         if (!empty($CFG->dblogerror)) {
             $debug=array_shift(debug_backtrace());
             error_log("SQL ".$db->ErrorMsg()." in {$debug['file']} on line {$debug['line']}. STATEMENT:  $sql");
@@ -1110,9 +1106,7 @@ function insert_record($table, $dataobject, $returnid=true, $primarykey='id') {
 
 /// Run the SQL statement
     if (!$rs = $db->Execute($insertSQL)) {
-        if (isset($CFG->debug) and $CFG->debug > 7) {
-            notify($db->ErrorMsg() .'<br /><br />'.$insertSQL);
-        }
+        debugging($db->ErrorMsg() .'<br /><br />'.$insertSQL);
         if (!empty($CFG->dblogerror)) {
             $debug=array_shift(debug_backtrace());
             error_log("SQL ".$db->ErrorMsg()." in {$debug['file']} on line {$debug['line']}. STATEMENT:  $insertSQL");
@@ -1207,9 +1201,7 @@ function update_record($table, $dataobject) {
     if ($rs = $db->Execute('UPDATE '. $CFG->prefix . $table .' SET '. $update .' WHERE id = \''. $dataobject->id .'\'')) {
         return true;
     } else {
-        if (isset($CFG->debug) and $CFG->debug > 7) {
-            notify($db->ErrorMsg() .'<br /><br />UPDATE '. $CFG->prefix . $table .' SET '. $update .' WHERE id = \''. $dataobject->id .'\'');
-        }
+        debugging($db->ErrorMsg() .'<br /><br />UPDATE '. $CFG->prefix . $table .' SET '. $update .' WHERE id = \''. $dataobject->id .'\'');
         if (!empty($CFG->dblogerror)) {
             $debug=array_shift(debug_backtrace());
             error_log("SQL ".$db->ErrorMsg()." in {$debug['file']} on line {$debug['line']}. STATEMENT:  UPDATE $CFG->prefix$table SET $update WHERE id = '$dataobject->id'");
index f0a4dde7fa949b93ebc363c29410482c5f6516c5..36df6cb72878ac4fe8115179bccfb534da669d56 100644 (file)
@@ -3242,7 +3242,7 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a
 
     } else {
         $mail->IsSMTP();                               // use SMTP directly
-        if ($CFG->debug > 7) {
+        if (debugging()) {
             echo '<pre>' . "\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;
     }
index 3d55e96cf961753772d73b792499a7735a951f99..49950ade3c9186abe96ef429224f6d414b7edd47 100644 (file)
@@ -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];
index 85736d7dfd23e8b61bdf724c3e05c3a24a2f5886..1ea2038cff9b46147bdf83df7db37c369f7050a5 100644 (file)
@@ -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);
index 46d0b25fbbefafe1dfe694de1588f9286fe3ffab..36bb1f5a20c69746d27459b4f2914e3216b89463 100644 (file)
@@ -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;
     }
index 9c7a5577ae127dceeb081c4fa89b4e6578376957..1bb544216ab5457d4f98226e9c4c62661bcd6a03 100644 (file)
@@ -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'];
         }
     }