Permalink
Browse files

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()
  • Loading branch information...
1 parent 8ff79e8 commit 3d94772d47c2b4d17004245483e770f7ce76e24f gustav_delius committed Jan 30, 2004
Showing with 35 additions and 16 deletions.
  1. +19 −14 lib/datalib.php
  2. +4 −0 lib/db/mysql.php
  3. +5 −1 lib/db/postgres7.php
  4. +6 −0 mod/forum/lib.php
  5. +1 −1 version.php
View
@@ -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 "<P>Error: Could not insert a new entry to the Moodle log</P>"; // 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'");
+ }
+ }
}
View
@@ -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;
View
@@ -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;
}
View
@@ -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");
+ }
}
}
}
View
@@ -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

0 comments on commit 3d94772

Please sign in to comment.