]> git.mjollnir.org Git - moodle.git/commitdiff
Some changes so that forum_cron is not fooled in case there is already
authormoodler <moodler>
Thu, 9 Oct 2003 04:58:09 +0000 (04:58 +0000)
committermoodler <moodler>
Thu, 9 Oct 2003 04:58:09 +0000 (04:58 +0000)
a real $USER variable present (eg if cron.php was run manually) and
so the timezones are not calculated incorrectly.

mod/forum/lib.php

index 48c48649c1c2ee7cbed7acdd5895b822cb06f013..45e66aa594c05af441a35556f2bfa147634bd01d 100644 (file)
@@ -189,6 +189,10 @@ function forum_cron () {
 
     global $CFG, $USER;
 
+    if (!empty($USER)) { // Remember real USER account if necessary
+        $realuser = $USER;
+    }
+
     $cutofftime = time() - $CFG->maxeditingtime;
 
     if ($posts = forum_get_unmailed_posts($cutofftime)) {
@@ -238,8 +242,11 @@ function forum_cron () {
 
                 $mailcount=0;
                 foreach ($users as $userto) {
-                    /// Override the language of get_string, so that mail is in correct language for the receiver.
-                    $USER->lang = $userto->lang;
+                    /// Override the language and timezone of the "current" user, so that 
+                    /// mail is customised for the receiver.
+                    $USER->lang     = $userto->lang;
+                    $USER->timezone = $userto->timezone;
+
                     $canreply = forum_user_can_post($forum, $userto);
 
                     $by->name = "$userfrom->firstname $userfrom->lastname";
@@ -310,6 +317,10 @@ function forum_cron () {
         }
     }
 
+    if (!empty($realuser)) {   // Restore real USER if necessary
+        $USER = $realuser;
+    }
+
     return true;
 }