*/
$messageproviders = array (
+ // Ordinary single forum posts.
+ 'posts' => array(
+ ),
-/// Ordinary single forum posts
- 'posts' => array (
- )
-
+ // Forum digest messages.
+ 'digests' => array(
+ ),
);
-
-
-
$string['showsubscribers'] = 'Show/edit current subscribers';
$string['singleforum'] = 'A single simple discussion';
$string['smallmessage'] = '{$a->user} posted in {$a->forumname}';
+$string['smallmessagedigest'] = 'Forum digest containing {$a} messages';
$string['startedby'] = 'Started by';
$string['subject'] = 'Subject';
$string['subscribe'] = 'Subscribe to this forum';
$postsarray = $discussionposts[$discussionid];
sort($postsarray);
+ $sentcount = 0;
foreach ($postsarray as $postid) {
$post = $posts[$postid];
$userto->markposts[$post->id] = $post->id;
}
}
+ $sentcount++;
}
$footerlinks = array();
if ($canunsubscribe) {
$posthtml = '';
}
- $attachment = $attachname='';
- // Directly email forum digests rather than sending them via messaging, use the
- // site shortname as 'from name', the noreply address will be used by email_to_user.
- $mailresult = email_to_user($userto, $site->shortname, $postsubject, $posttext, $posthtml, $attachment, $attachname);
+ $eventdata = new \core\message\message();
+ $eventdata->component = 'mod_forum';
+ $eventdata->name = 'digests';
+ $eventdata->userfrom = core_user::get_noreply_user();
+ $eventdata->userto = $userto;
+ $eventdata->subject = $postsubject;
+ $eventdata->fullmessage = $posttext;
+ $eventdata->fullmessageformat = FORMAT_PLAIN;
+ $eventdata->fullmessagehtml = $posthtml;
+ $eventdata->notification = 1;
+ $eventdata->smallmessage = get_string('smallmessagedigest', 'forum', $sentcount);
+ $mailresult = message_send($eventdata);
if (!$mailresult) {
mtrace("ERROR: mod/forum/cron.php: Could not send out digest mail to user $userto->id ".
* specified number of times.
*
* @param integer $expected The number of times that the post should have been sent
- * @return array An array of the messages caught by the message sink
+ * @param integer $individualcount The number of individual messages sent
+ * @param integer $digestcount The number of digest messages sent
*/
- protected function helper_run_cron_check_count($expected, $messagecount, $mailcount) {
+ protected function helper_run_cron_check_count($expected, $individualcount, $digestcount) {
if ($expected === 0) {
$this->expectOutputRegex('/(Email digests successfully sent to .* users.){0}/');
} else {
// Now check the results in the message sink.
$messages = $this->helper->messagesink->get_messages();
- // There should be the expected number of messages.
- $this->assertEquals($messagecount, count($messages));
- // Now check the results in the mail sink.
- $messages = $this->helper->mailsink->get_messages();
- // There should be the expected number of messages.
- $this->assertEquals($mailcount, count($messages));
+ $counts = (object) array('digest' => 0, 'individual' => 0);
+ foreach ($messages as $message) {
+ if (strpos($message->subject, 'forum digest') !== false) {
+ $counts->digest++;
+ } else {
+ $counts->individual++;
+ }
+ }
- return $messages;
+ $this->assertEquals($digestcount, $counts->digest);
+ $this->assertEquals($individualcount, $counts->individual);
}
public function test_set_maildigest() {
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2015120800; // The current module version (Date: YYYYMMDDXX)
+$plugin->version = 2015120801; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2015111000; // Requires this Moodle version
$plugin->component = 'mod_forum'; // Full name of the plugin (used for diagnostics)