Skip to content

Commit

Permalink
CHanged a lot of CFG->debug stuff to use the new debuggin() function
Browse files Browse the repository at this point in the history
  • Loading branch information
moodler committed Sep 13, 2006
1 parent c3b307b commit ea82d6b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 50 deletions.
16 changes: 4 additions & 12 deletions lib/accesslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/datalib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
18 changes: 5 additions & 13 deletions lib/dmllib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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'");
Expand Down
8 changes: 6 additions & 2 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 3 additions & 9 deletions lib/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down
6 changes: 1 addition & 5 deletions lib/rsslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,7 @@ function rss_full_tag($tag,$level=0,$endline=true,$content,$attributes=null) {
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);
Expand Down
2 changes: 1 addition & 1 deletion lib/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@

/// Set error reporting back to normal
if ($originaldatabasedebug == -1) {
$CFG->debug = 5;
$CFG->debug = E_PARSE;
} else {
$CFG->debug = $originaldatabasedebug;
}
Expand Down
10 changes: 3 additions & 7 deletions lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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'];
}
}
Expand Down

0 comments on commit ea82d6b

Please sign in to comment.