MDL-47162 core_message: Updating all uses of messaging to add courseid
authorEric Merrill <merrill@oakland.edu>
Mon, 31 Oct 2016 18:13:13 +0000 (14:13 -0400)
committerEric Merrill <merrill@oakland.edu>
Mon, 31 Oct 2016 18:13:13 +0000 (14:13 -0400)
18 files changed:
admin/tool/messageinbound/classes/manager.php
admin/tool/monitor/classes/notification_task.php
backup/util/helper/backup_cron_helper.class.php
badges/cron.php
course/lib.php
enrol/flatfile/lib.php
enrol/imsenterprise/lib.php
enrol/paypal/classes/util.php
enrol/paypal/ipn.php
error/index.php
lib/classes/antivirus/scanner.php
lib/classes/update/checker.php
lib/enrollib.php
lib/portfoliolib.php
message/tests/externallib_test.php
message/tests/search_test_received.php
message/tests/search_test_sent.php
mod/forum/lib.php

index 254f7a8..0e26c58 100644 (file)
@@ -930,6 +930,7 @@ class manager {
         $userfrom->customheaders[] = 'In-Reply-To: ' . $messageid;
 
         // The message will be sent from the intended user.
+        $eventdata->courseid            = SITEID;
         $eventdata->userfrom            = \core_user::get_support_user();
         $eventdata->userto              = $USER;
         $eventdata->subject             = $this->get_reply_subject($this->currentmessagedata->envelope->subject);
@@ -971,6 +972,7 @@ class manager {
         $messagedata->error = $error;
 
         $eventdata = new \core\message\message();
+        $eventdata->courseid            = SITEID;
         $eventdata->component           = 'tool_messageinbound';
         $eventdata->name                = 'messageprocessingerror';
         $eventdata->userfrom            = $userfrom;
@@ -1030,6 +1032,7 @@ class manager {
         $messagedata->subject = $this->currentmessagedata->envelope->subject;
 
         $eventdata = new \core\message\message();
+        $eventdata->courseid            = SITEID;
         $eventdata->component           = 'tool_messageinbound';
         $eventdata->name                = 'messageprocessingsuccess';
         $eventdata->userfrom            = $userfrom;
index 05b266e..a65ef04 100644 (file)
@@ -84,6 +84,7 @@ class notification_task extends \core\task\adhoc_task {
         $template = $this->replace_placeholders($template, $subscription, $eventobj, $context);
         $htmlmessage = format_text($template, $subscription->templateformat, array('context' => $context));
         $msgdata = new \core\message\message();
+        $msgdata->courseid          = empty($subscription->courseid) ? SITEID : $subscription->courseid;
         $msgdata->component         = 'tool_monitor'; // Your component name.
         $msgdata->name              = 'notification'; // This is the message name from messages.php.
         $msgdata->userfrom          = \core_user::get_noreply_user();
index 30bd327..fc62cfc 100644 (file)
@@ -265,6 +265,7 @@ abstract class backup_cron_automated_helper {
 
             //Send the message
             $eventdata = new \core\message\message();
+            $eventdata->courseid          = SITEID;
             $eventdata->modulename        = 'moodle';
             $eventdata->userfrom          = $admin;
             $eventdata->userto            = $admin;
index 32a235d..fc51a8d 100644 (file)
@@ -141,6 +141,7 @@ function badge_assemble_notification(stdClass $badge) {
 
         // Create a message object.
         $eventdata = new \core\message\message();
+        $eventdata->courseid          = SITEID;
         $eventdata->component         = 'moodle';
         $eventdata->name              = 'badgecreatornotice';
         $eventdata->userfrom          = $userfrom;
index 76d8c87..5536326 100644 (file)
@@ -2636,7 +2636,7 @@ class course_request {
         $a = new stdClass();
         $a->name = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
         $a->url = $CFG->wwwroot.'/course/view.php?id=' . $course->id;
-        $this->notify($user, $USER, 'courserequestapproved', get_string('courseapprovedsubject'), get_string('courseapprovedemail2', 'moodle', $a));
+        $this->notify($user, $USER, 'courserequestapproved', get_string('courseapprovedsubject'), get_string('courseapprovedemail2', 'moodle', $a), $course->id);
 
         return $course->id;
     }
@@ -2672,9 +2672,11 @@ class course_request {
      * @param string $name
      * @param string $subject
      * @param string $message
+     * @param int|null $courseid
      */
-    protected function notify($touser, $fromuser, $name='courserequested', $subject, $message) {
+    protected function notify($touser, $fromuser, $name='courserequested', $subject, $message, $courseid = null) {
         $eventdata = new \core\message\message();
+        $eventdata->courseid          = empty($courseid) ? SITEID : $courseid;
         $eventdata->component         = 'moodle';
         $eventdata->name              = $name;
         $eventdata->userfrom          = $fromuser;
index cee8a49..4bff2a9 100644 (file)
@@ -187,6 +187,7 @@ class enrol_flatfile_plugin extends enrol_plugin {
         if ($processed and $mailadmins) {
             if ($log = $buffer->get_buffer()) {
                 $eventdata = new \core\message\message();
+                $eventdata->courseid          = SITEID;
                 $eventdata->modulename        = 'moodle';
                 $eventdata->component         = 'enrol_flatfile';
                 $eventdata->name              = 'flatfile_enrolment';
@@ -341,6 +342,7 @@ class enrol_flatfile_plugin extends enrol_plugin {
 
         if (!unlink($filelocation)) {
             $eventdata = new \core\message\message();
+            $eventdata->courseid          = SITEID;
             $eventdata->modulename        = 'moodle';
             $eventdata->component         = 'enrol_flatfile';
             $eventdata->name              = 'flatfile_enrolment';
@@ -464,6 +466,7 @@ class enrol_flatfile_plugin extends enrol_plugin {
                 $subject = get_string('enrolmentnew', 'enrol', format_string($course->shortname, true, array('context' => $context)));
 
                 $eventdata = new \core\message\message();
+                $eventdata->courseid          = $course->id;
                 $eventdata->modulename        = 'moodle';
                 $eventdata->component         = 'enrol_flatfile';
                 $eventdata->name              = 'flatfile_enrolment';
@@ -495,6 +498,7 @@ class enrol_flatfile_plugin extends enrol_plugin {
                 $subject = get_string('enrolmentnew', 'enrol', format_string($course->shortname, true, array('context' => $context)));
 
                 $eventdata = new \core\message\message();
+                $eventdata->courseid          = $course->id;
                 $eventdata->modulename        = 'moodle';
                 $eventdata->component         = 'enrol_flatfile';
                 $eventdata->name              = 'flatfile_enrolment';
index 79bf25b..573606f 100644 (file)
@@ -223,6 +223,7 @@ class enrol_imsenterprise_plugin extends enrol_plugin {
             }
 
             $eventdata = new \core\message\message();
+            $eventdata->courseid          = SITEID;
             $eventdata->modulename        = 'moodle';
             $eventdata->component         = 'enrol_imsenterprise';
             $eventdata->name              = 'imsenterprise_enrolment';
index 8fb9e72..6f91abd 100644 (file)
@@ -52,6 +52,7 @@ final class util {
         }
 
         $eventdata = new \core\message\message();
+        $eventdata->courseid          = empty($data->courseid) ? SITEID : $data->courseid;
         $eventdata->modulename        = 'moodle';
         $eventdata->component         = 'enrol_paypal';
         $eventdata->name              = 'paypal_enrolment';
index 2309a06..ccbcd0b 100644 (file)
@@ -153,6 +153,7 @@ if (strlen($result) > 0) {
 
         if ($data->payment_status == "Pending" and $data->pending_reason != "echeck") {
             $eventdata = new \core\message\message();
+            $eventdata->courseid          = empty($data->courseid) ? SITEID : $data->courseid;
             $eventdata->modulename        = 'moodle';
             $eventdata->component         = 'enrol_paypal';
             $eventdata->name              = 'paypal_enrolment';
@@ -260,6 +261,7 @@ if (strlen($result) > 0) {
             $a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id";
 
             $eventdata = new \core\message\message();
+            $eventdata->courseid          = $course->id;
             $eventdata->modulename        = 'moodle';
             $eventdata->component         = 'enrol_paypal';
             $eventdata->name              = 'paypal_enrolment';
@@ -279,6 +281,7 @@ if (strlen($result) > 0) {
             $a->user = fullname($user);
 
             $eventdata = new \core\message\message();
+            $eventdata->courseid          = $course->id;
             $eventdata->modulename        = 'moodle';
             $eventdata->component         = 'enrol_paypal';
             $eventdata->name              = 'paypal_enrolment';
@@ -298,6 +301,7 @@ if (strlen($result) > 0) {
             $admins = get_admins();
             foreach ($admins as $admin) {
                 $eventdata = new \core\message\message();
+                $eventdata->courseid          = $course->id;
                 $eventdata->modulename        = 'moodle';
                 $eventdata->component         = 'enrol_paypal';
                 $eventdata->name              = 'paypal_enrolment';
index 721f141..2e3280d 100644 (file)
@@ -11,7 +11,8 @@
         }
 
         // Send the message and redirect.
-        $eventdata = new stdClass();
+        $eventdata = new \core\message\message();
+        $eventdata->courseid         = SITEID;
         $eventdata->component        = 'moodle';
         $eventdata->name             = 'errors';
         $eventdata->userfrom          = $USER;
index d8d0884..a93e56d 100644 (file)
@@ -123,6 +123,7 @@ abstract class scanner {
         $admins = get_admins();
         foreach ($admins as $admin) {
             $eventdata = new \core\message\message();
+            $eventdata->courseid          = SITEID;
             $eventdata->component         = 'moodle';
             $eventdata->name              = 'errors';
             $eventdata->userfrom          = get_admin();
index 46563e2..ba19c15 100644 (file)
@@ -799,6 +799,7 @@ class checker {
 
         foreach ($admins as $admin) {
             $message = new \core\message\message();
+            $message->courseid          = SITEID;
             $message->component         = 'moodle';
             $message->name              = 'availableupdate';
             $message->userfrom          = get_admin();
index 561963f..4849b07 100644 (file)
@@ -2656,6 +2656,7 @@ abstract class enrol_plugin {
         $body = get_string('expirymessageenrolledbody', 'enrol_'.$name, $a);
 
         $message = new \core\message\message();
+        $message->courseid          = $ue->courseid;
         $message->notification      = 1;
         $message->component         = 'enrol_'.$name;
         $message->name              = 'expiry_notification';
@@ -2717,6 +2718,7 @@ abstract class enrol_plugin {
         $body = get_string('expirymessageenrollerbody', 'enrol_'.$name, $a);
 
         $message = new \core\message\message();
+        $message->courseid          = $course->id;
         $message->notification      = 1;
         $message->component         = 'enrol_'.$name;
         $message->name              = 'expiry_notification';
index 1118851..edadee7 100644 (file)
@@ -1110,6 +1110,7 @@ function portfolio_insane_notify_admins($insane, $instances=false) {
 
     foreach ($admins as $admin) {
         $eventdata = new \core\message\message();
+        $eventdata->courseid = SITEID;
         $eventdata->modulename = 'portfolio';
         $eventdata->component = 'portfolio';
         $eventdata->name = 'notices';
index 027a7fe..c77e6b7 100644 (file)
@@ -507,7 +507,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
         message_send($eventdata);
 
         $message = new \core\message\message();
-        $message->courseid        = $course->id;
+        $message->courseid          = $course->id;
         $message->notification      = 1;
         $message->component         = 'enrol_manual';
         $message->name              = 'expiry_notification';
index 7b41803..191850e 100644 (file)
@@ -72,7 +72,8 @@ class message_received_search_testcase extends advanced_testcase {
         $this->preventResetByRollback();
         $sink = $this->redirectMessages();
 
-        $message = new StdClass();
+        $message = new \core\message\message();
+        $message->courseid = SITEID;
         $message->userfrom = $user1;
         $message->userto = $user2;
         $message->subject = "Test Subject";
@@ -129,7 +130,8 @@ class message_received_search_testcase extends advanced_testcase {
         $this->preventResetByRollback();
         $sink = $this->redirectMessages();
 
-        $message = new StdClass();
+        $message = new \core\message\message();
+        $message->courseid = SITEID;
         $message->userfrom = $user1;
         $message->userto = $user2;
         $message->subject = "Test Subject";
@@ -175,7 +177,8 @@ class message_received_search_testcase extends advanced_testcase {
         $this->preventResetByRollback();
         $sink = $this->redirectMessages();
 
-        $message = new StdClass();
+        $message = new \core\message\message();
+        $message->courseid = SITEID;
         $message->userfrom = $user1;
         $message->userto = $user2;
         $message->subject = "Test Subject";
index 9938ae1..7e9c887 100644 (file)
@@ -72,7 +72,8 @@ class message_sent_search_testcase extends advanced_testcase {
         $this->preventResetByRollback();
         $sink = $this->redirectMessages();
 
-        $message = new StdClass();
+        $message = new \core\message\message();
+        $message->courseid = SITEID;
         $message->userfrom = $user1;
         $message->userto = $user2;
         $message->subject = "Test Subject";
@@ -129,7 +130,8 @@ class message_sent_search_testcase extends advanced_testcase {
         $this->preventResetByRollback();
         $sink = $this->redirectMessages();
 
-        $message = new StdClass();
+        $message = new \core\message\message();
+        $message->courseid = SITEID;
         $message->userfrom = $user1;
         $message->userto = $user2;
         $message->subject = "Test Subject";
@@ -175,7 +177,8 @@ class message_sent_search_testcase extends advanced_testcase {
         $this->preventResetByRollback();
         $sink = $this->redirectMessages();
 
-        $message = new StdClass();
+        $message = new \core\message\message();
+        $message->courseid = SITEID;
         $message->userfrom = $user1;
         $message->userto = $user2;
         $message->subject = "Test Subject";
index 623dcb3..8e7cd89 100644 (file)
@@ -1186,6 +1186,7 @@ function forum_cron() {
                 }
 
                 $eventdata = new \core\message\message();
+                $eventdata->courseid            = SITEID;
                 $eventdata->component           = 'mod_forum';
                 $eventdata->name                = 'digests';
                 $eventdata->userfrom            = core_user::get_noreply_user();