MDL-31335 message: wrapped calls to mtrace() in email_to_user() within a check to make sure its a CLI script

This commit is contained in:
Andrew Davis 2012-02-10 10:02:39 +07:00
parent 0dde394db5
commit fc28177f4d

View File

@ -5042,19 +5042,31 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a
global $CFG, $FULLME;
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;
}
if (!empty($user->deleted)) {
// do not mail delted users
mtrace('Error: lib/moodlelib.php email_to_user(): User is deleted');
// do not mail deleted users
$userdeleted = 'User is deleted';
error_log($userdeleted);
if (CLI_SCRIPT) {
mtrace('Error: lib/moodlelib.php email_to_user(): '.$userdeleted);
}
return false;
}
if (!empty($CFG->noemailever)) {
// 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;
}
@ -5074,8 +5086,7 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a
$invalidemail = "User $user->id (".fullname($user).") email ($user->email) is invalid! Not sending.";
error_log($invalidemail);
if (CLI_SCRIPT) {
// do not print this in standard web pages
mtrace($invalidemail);
mtrace('Error: lib/moodlelib.php email_to_user(): '.$invalidemail);
}
return false;
}
@ -5083,7 +5094,9 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a
if (over_bounce_threshold($user)) {
$bouncemsg = "User $user->id (".fullname($user).") is over bounce threshold! Not sending.";
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;
}
@ -5227,8 +5240,10 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a
}
return true;
} else {
mtrace('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)) {
echo '</pre>';
}