MDL-44954 messages: Fixed save notifications with the notification flag
authorJuan Leyva <juanleyvadelgado@gmail.com>
Fri, 4 Apr 2014 15:53:25 +0000 (17:53 +0200)
committerJuan Leyva <juanleyvadelgado@gmail.com>
Mon, 7 Apr 2014 10:19:52 +0000 (12:19 +0200)
lib/messagelib.php
lib/phpunit/tests/advanced_test.php
lib/tests/messagelib_test.php
message/lib.php

index 5ec0425..02c6cfc 100644 (file)
@@ -68,6 +68,11 @@ function message_send($eventdata) {
     //TODO: we need to solve problems with database transactions here somehow, for now we just prevent transactions - sorry
     $DB->transactions_forbidden();
 
+    // By default a message is a notification. Only personal/private messages aren't notifications.
+    if (!isset($eventdata->notification)) {
+        $eventdata->notification = 1;
+    }
+
     if (is_number($eventdata->userto)) {
         $eventdata->userto = core_user::get_user($eventdata->userto);
     }
@@ -109,12 +114,7 @@ function message_send($eventdata) {
     $savemessage->fullmessageformat = $eventdata->fullmessageformat;
     $savemessage->fullmessagehtml   = $eventdata->fullmessagehtml;
     $savemessage->smallmessage      = $eventdata->smallmessage;
-
-    if (!empty($eventdata->notification)) {
-        $savemessage->notification = $eventdata->notification;
-    } else {
-        $savemessage->notification = 0;
-    }
+    $savemessage->notification      = $eventdata->notification;
 
     if (!empty($eventdata->contexturl)) {
         $savemessage->contexturl = $eventdata->contexturl;
index 749f3ec..8811bcf 100644 (file)
@@ -405,6 +405,7 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
         $message1->fullmessageformat = FORMAT_MARKDOWN;
         $message1->fullmessagehtml   = '<p>message body</p>';
         $message1->smallmessage      = 'small message';
+        $message1->notification      = 0;
 
         $message2 = new stdClass();
         $message2->component         = 'moodle';
@@ -416,6 +417,7 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
         $message2->fullmessageformat = FORMAT_MARKDOWN;
         $message2->fullmessagehtml   = '<p>message body</p>';
         $message2->smallmessage      = 'small message';
+        $message2->notification      = 0;
 
         // There should be debugging message without redirection.
         message_send($message1);
@@ -478,6 +480,7 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
         $message3->fullmessageformat = FORMAT_MARKDOWN;
         $message3->fullmessagehtml   = '<p>message body</p>';
         $message3->smallmessage      = 'small message';
+        $message3->notification      = 0;
 
         try {
             message_send($message3);
@@ -523,6 +526,7 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
         $message->fullmessageformat = FORMAT_MARKDOWN;
         $message->fullmessagehtml   = '<p>message body</p>';
         $message->smallmessage      = 'small message';
+        $message->notification      = 0;
 
         message_send($message);
         $this->assertEquals(2, $sink->count());
index c279e28..6f4bd27 100644 (file)
@@ -48,6 +48,7 @@ class core_messagelib_testcase extends advanced_testcase {
         $message->fullmessageformat = FORMAT_MARKDOWN;
         $message->fullmessagehtml   = '<p>message body</p>';
         $message->smallmessage      = 'small message';
+        $message->notification      = 0;
 
         // Check message is not sent.
         $sink = $this->redirectEmails();
@@ -218,6 +219,7 @@ class core_messagelib_testcase extends advanced_testcase {
         $message->smallmessage      = 'small message';
         $message->attachment        = $file;
         $message->attachname        = 'emailtest.txt';
+        $message->notification      = 0;
 
         // Make sure we are redirecting emails.
         $sink = $this->redirectEmails();
index 0a940ed..5efe920 100644 (file)
@@ -2187,6 +2187,7 @@ function message_post_message($userfrom, $userto, $message, $format) {
     }
 
     $eventdata->timecreated     = time();
+    $eventdata->notification    = 0;
     return message_send($eventdata);
 }