From 3d94772d47c2b4d17004245483e770f7ce76e24f Mon Sep 17 00:00:00 2001 From: gustav_delius Date: Fri, 30 Jan 2004 18:21:56 +0000 Subject: [PATCH] better logging of forum mail errors, see http://moodle.org/mod/forum/discuss.php?d=4865. Required the addition of an extra optional argument $user="" to add_to_log() --- lib/datalib.php | 33 +++++++++++++++++++-------------- lib/db/mysql.php | 4 ++++ lib/db/postgres7.php | 6 +++++- mod/forum/lib.php | 6 ++++++ version.php | 2 +- 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/lib/datalib.php b/lib/datalib.php index 751b9a21a1..4a8e126b6d 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -1958,17 +1958,21 @@ function instance_is_visible($moduletype, $module) { * @param string $action view, edit, post (often but not always the same as the file.php) * @param string $url the file and parameters used to see the results of the action * @param string $info additional description information +* @param string $user optional, if log regards $user other than $USER */ -function add_to_log($courseid, $module, $action, $url="", $info="") { +function add_to_log($courseid, $module, $action, $url="", $info="", $user="") { global $db, $CFG, $USER, $REMOTE_ADDR; - if (isset($USER->realuser)) { // Don't log - return; + if ($user) { + $userid = $user; + } else { + if (isset($USER->realuser)) { // Don't log + return; + } + $userid = empty($USER->id) ? "" : $USER->id; } - $userid = empty($USER->id) ? "" : $USER->id; - $timenow = time(); $info = addslashes($info); @@ -1992,16 +1996,17 @@ function add_to_log($courseid, $module, $action, $url="", $info="") { if (!$result and ($CFG->debug > 7)) { echo "

Error: Could not insert a new entry to the Moodle log

"; // Don't throw an error } + if (!$user) { + if (isstudent($courseid)) { + $db->Execute("UPDATE {$CFG->prefix}user_students SET timeaccess = '$timenow' ". + "WHERE course = '$courseid' AND userid = '$userid'"); + } - if (isstudent($courseid)) { - $db->Execute("UPDATE {$CFG->prefix}user_students SET timeaccess = '$timenow' ". - "WHERE course = '$courseid' AND userid = '$userid'"); - } - - if (isteacher($courseid, false, false)) { - $db->Execute("UPDATE {$CFG->prefix}user_teachers SET timeaccess = '$timenow' ". - "WHERE course = '$courseid' AND userid = '$userid'"); - } + if (isteacher($courseid, false, false)) { + $db->Execute("UPDATE {$CFG->prefix}user_teachers SET timeaccess = '$timenow' ". + "WHERE course = '$courseid' AND userid = '$userid'"); + } + } } diff --git a/lib/db/mysql.php b/lib/db/mysql.php index 1fe42506f7..6f220b143d 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -633,6 +633,10 @@ function main_upgrade($oldversion=0) { if ($oldversion < 2004012900) { table_column("config", "value", "value", "text", "", "", ""); } + + if ($oldversion < 2004013000) { + table_column("forum_posts", "mailed", "mailed", "tinyint", "2"); + } return $result; diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index 5470e3e24e..944b1a9c7a 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -379,7 +379,11 @@ function main_upgrade($oldversion=0) { if ($oldversion < 2004012900) { table_column("config", "value", "value", "text", "", "", ""); } - + + if ($oldversion < 2004013000) { + table_column("forum_posts", "mailed", "mailed", "tinyint", "2"); + } + return $result; } diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 8fcb66fc91..47e0543ef1 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -251,6 +251,7 @@ function forum_cron () { $canunsubscribe = ! forum_is_forcesubscribed($forum->id); $mailcount=0; + $errorcount=0; foreach ($users as $userto) { if ($groupmode) { // Look for a reason not to send this email if (!isteacheredit($course->id, $userto->id)) { @@ -328,12 +329,17 @@ function forum_cron () { if (! email_to_user($userto, $userfrom, $postsubject, $posttext, $posthtml)) { echo "Error: mod/forum/cron.php: Could not send out mail for id $post->id to user $userto->id ($userto->email) .. not trying again.\n"; + add_to_log($course->id, 'forum', 'mail error', "discuss.php?d=$discussion->id#$post->id", substr($post->subject,0,15), $userto->id); + $errorcount++; } else { $mailcount++; } } echo ".... mailed to $mailcount users.\n"; + if ($errorcount) { + set_field("forum_posts", "mailed", "2", "id", "$post->id"); + } } } } diff --git a/version.php b/version.php index be3924d3d2..08ff4e6035 100644 --- a/version.php +++ b/version.php @@ -5,7 +5,7 @@ // database to determine whether upgrades should // be performed (see lib/db/*.php) -$version = 2004012900; // The current version is a date (YYYYMMDDXX) +$version = 2004013000; // The current version is a date (YYYYMMDDXX) $release = "1.2 development"; // User-friendly version number -- 2.39.5