Skip to content

Commit

Permalink
MDL-31335 message: wrapped calls to mtrace() in email_to_user() withi…
Browse files Browse the repository at this point in the history
…n a check to make sure its a CLI script
  • Loading branch information
andyjdavis committed Feb 20, 2012
1 parent a1063d9 commit f684c55
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions lib/moodlelib.php
Expand Up @@ -4604,19 +4604,31 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a
global $CFG, $FULLME; global $CFG, $FULLME;


if (empty($user) || empty($user->email)) { if (empty($user) || empty($user->email)) {
mtrace('Error: lib/moodlelib.php email_to_user(): User is null or has no email'); $nulluser = 'User is null or has no email';
error_log($nulluser);
if (CLI_SCRIPT) {
mtrace('Error: lib/moodlelib.php email_to_user(): '.$nulluser);
}
return false; return false;
} }


if (!empty($user->deleted)) { if (!empty($user->deleted)) {
// do not mail delted users // do not mail deleted users
mtrace('Error: lib/moodlelib.php email_to_user(): User is deleted'); $userdeleted = 'User is deleted';
error_log($userdeleted);
if (CLI_SCRIPT) {
mtrace('Error: lib/moodlelib.php email_to_user(): '.$userdeleted);
}
return false; return false;
} }


if (!empty($CFG->noemailever)) { if (!empty($CFG->noemailever)) {
// hidden setting for development sites, set in config.php if needed // hidden setting for development sites, set in config.php if needed
mtrace('Error: lib/moodlelib.php email_to_user(): Not sending email due to noemailever config setting'); $noemail = 'Not sending email due to noemailever config setting';
error_log($noemail);
if (CLI_SCRIPT) {
mtrace('Error: lib/moodlelib.php email_to_user(): '.$noemail);
}
return true; return true;
} }


Expand All @@ -4636,16 +4648,17 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a
$invalidemail = "User $user->id (".fullname($user).") email ($user->email) is invalid! Not sending."; $invalidemail = "User $user->id (".fullname($user).") email ($user->email) is invalid! Not sending.";
error_log($invalidemail); error_log($invalidemail);
if (CLI_SCRIPT) { if (CLI_SCRIPT) {
// do not print this in standard web pages mtrace('Error: lib/moodlelib.php email_to_user(): '.$invalidemail);
mtrace($invalidemail);
} }
return false; return false;
} }


if (over_bounce_threshold($user)) { if (over_bounce_threshold($user)) {
$bouncemsg = "User $user->id (".fullname($user).") is over bounce threshold! Not sending."; $bouncemsg = "User $user->id (".fullname($user).") is over bounce threshold! Not sending.";
error_log($bouncemsg); error_log($bouncemsg);
mtrace('Error: lib/moodlelib.php email_to_user(): '.$bouncemsg); if (CLI_SCRIPT) {
mtrace('Error: lib/moodlelib.php email_to_user(): '.$bouncemsg);
}
return false; return false;
} }


Expand Down Expand Up @@ -4789,8 +4802,10 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a
} }
return true; return true;
} else { } else {
mtrace('ERROR: '. $mail->ErrorInfo);
add_to_log(SITEID, 'library', 'mailer', $FULLME, 'ERROR: '. $mail->ErrorInfo); add_to_log(SITEID, 'library', 'mailer', $FULLME, 'ERROR: '. $mail->ErrorInfo);
if (CLI_SCRIPT) {
mtrace('Error: lib/moodlelib.php email_to_user(): '.$mail->ErrorInfo);
}
if (!empty($mail->SMTPDebug)) { if (!empty($mail->SMTPDebug)) {
echo '</pre>'; echo '</pre>';
} }
Expand Down

0 comments on commit f684c55

Please sign in to comment.