better logging of forum mail errors, see http://moodle.org/mod/forum/discuss.php...
authorgustav_delius <gustav_delius>
Fri, 30 Jan 2004 18:21:56 +0000 (18:21 +0000)
committergustav_delius <gustav_delius>
Fri, 30 Jan 2004 18:21:56 +0000 (18:21 +0000)
lib/datalib.php
lib/db/mysql.php
lib/db/postgres7.php
mod/forum/lib.php
version.php

index 751b9a21a12ebb4af14d8bcaf237cbf242ede49d..4a8e126b6d0a098f7be97c34c8cd3c77e2ceef43 100644 (file)
@@ -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'");
+        }
+    }     
 }
 
 
index 1fe42506f7e0b1e0adfcc32ee55c09585ae1d621..6f220b143df31d06cb7cb3ae9be6c5f9f4014006 100644 (file)
@@ -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;
 
index 5470e3e24e17054c172e0bf3a215bcd2b7dfa7e0..944b1a9c7aa64eafb6629cf237054a3f8c347ca2 100644 (file)
@@ -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;
 }
 
index 8fcb66fc91eb7c412c7ed47dce7fcdb1d6670aac..47e0543ef1c5b97a31eb5aa68a67637cfeeca7e5 100644 (file)
@@ -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");
+                }
             }
         }
     }
index be3924d3d24e6455c900d082a8aaffc82f29f8cc..08ff4e603538b528c92fe5e973aebc41e69c34c4 100644 (file)
@@ -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