MDL-29534 Forum: Fixed userfrom reference problem
authorRajesh Taneja <rajesh@moodle.com>
Thu, 17 Jan 2013 05:45:01 +0000 (13:45 +0800)
committerRajesh Taneja <rajesh@moodle.com>
Thu, 17 Jan 2013 05:45:01 +0000 (13:45 +0800)
mod/forum/lib.php

index 6e2aafd..c2c3679 100644 (file)
@@ -705,6 +705,14 @@ function forum_cron() {
                 $eventdata->fullmessagehtml  = $posthtml;
                 $eventdata->notification = 1;
 
+                // If forum_replytouser is not set then send mail using the noreplyaddress.
+                if (empty($CFG->forum_replytouser)) {
+                    // Clone userfrom as it is referenced by $users.
+                    $cloneduserfrom = clone($userfrom);
+                    $cloneduserfrom->email = $CFG->noreplyaddress;
+                    $eventdata->userfrom = $cloneduserfrom;
+                }
+
                 $smallmessagestrings = new stdClass();
                 $smallmessagestrings->user = fullname($userfrom);
                 $smallmessagestrings->forumname = "$shortname: ".format_string($forum->name,true).": ".$discussion->name;
@@ -715,11 +723,6 @@ function forum_cron() {
                 $eventdata->contexturl = "{$CFG->wwwroot}/mod/forum/discuss.php?d={$discussion->id}#p{$post->id}";
                 $eventdata->contexturlname = $discussion->name;
 
-                // If forum_replytouser is not set then send mail using the noreplyaddress.
-                if (empty($CFG->forum_replytouser)) {
-                    $eventdata->userfrom->email = $CFG->noreplyaddress;
-                }
-
                 $mailresult = message_send($eventdata);
                 if (!$mailresult){
                     mtrace("Error: mod/forum/lib.php forum_cron(): Could not send out mail for id $post->id to user $userto->id".