Skip to content

Commit

Permalink
MDL-47162 core_message: Updating all uses of messaging to add courseid
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmerrill committed Oct 31, 2016
1 parent a29bcf7 commit 880fc15
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 10 deletions.
3 changes: 3 additions & 0 deletions admin/tool/messageinbound/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ private function handle_verification_failure(
$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);
Expand Down Expand Up @@ -971,6 +972,7 @@ private function inform_user_of_error($error) {
$messagedata->error = $error;

$eventdata = new \core\message\message();
$eventdata->courseid = SITEID;
$eventdata->component = 'tool_messageinbound';
$eventdata->name = 'messageprocessingerror';
$eventdata->userfrom = $userfrom;
Expand Down Expand Up @@ -1030,6 +1032,7 @@ private function inform_user_of_success(\stdClass $messagedata, $handlerresult)
$messagedata->subject = $this->currentmessagedata->envelope->subject;

$eventdata = new \core\message\message();
$eventdata->courseid = SITEID;
$eventdata->component = 'tool_messageinbound';
$eventdata->name = 'messageprocessingsuccess';
$eventdata->userfrom = $userfrom;
Expand Down
1 change: 1 addition & 0 deletions admin/tool/monitor/classes/notification_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ protected function generate_message($subscriptionid, \stdClass $eventobj) {
$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();
Expand Down
1 change: 1 addition & 0 deletions backup/util/helper/backup_cron_helper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ public static function run_automated_backup($rundirective = self::RUN_ON_SCHEDUL

//Send the message
$eventdata = new \core\message\message();
$eventdata->courseid = SITEID;
$eventdata->modulename = 'moodle';
$eventdata->userfrom = $admin;
$eventdata->userto = $admin;
Expand Down
1 change: 1 addition & 0 deletions badges/cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2636,7 +2636,7 @@ public function approve() {
$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;
}
Expand Down Expand Up @@ -2672,9 +2672,11 @@ public function delete() {
* @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;
Expand Down
4 changes: 4 additions & 0 deletions enrol/flatfile/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public function sync(progress_trace $trace) {
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';
Expand Down Expand Up @@ -341,6 +342,7 @@ protected function process_file(progress_trace $trace) {

if (!unlink($filelocation)) {
$eventdata = new \core\message\message();
$eventdata->courseid = SITEID;
$eventdata->modulename = 'moodle';
$eventdata->component = 'enrol_flatfile';
$eventdata->name = 'flatfile_enrolment';
Expand Down Expand Up @@ -464,6 +466,7 @@ protected function process_records(progress_trace $trace, $action, $roleid, $use
$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';
Expand Down Expand Up @@ -495,6 +498,7 @@ protected function process_records(progress_trace $trace, $action, $roleid, $use
$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';
Expand Down
1 change: 1 addition & 0 deletions enrol/imsenterprise/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public function cron() {
}

$eventdata = new \core\message\message();
$eventdata->courseid = SITEID;
$eventdata->modulename = 'moodle';
$eventdata->component = 'enrol_imsenterprise';
$eventdata->name = 'imsenterprise_enrolment';
Expand Down
1 change: 1 addition & 0 deletions enrol/paypal/classes/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static function message_paypal_error_to_admin($subject, $data) {
}

$eventdata = new \core\message\message();
$eventdata->courseid = empty($data->courseid) ? SITEID : $data->courseid;
$eventdata->modulename = 'moodle';
$eventdata->component = 'enrol_paypal';
$eventdata->name = 'paypal_enrolment';
Expand Down
4 changes: 4 additions & 0 deletions enrol/paypal/ipn.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@

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';
Expand Down Expand Up @@ -260,6 +261,7 @@
$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';
Expand All @@ -279,6 +281,7 @@
$a->user = fullname($user);

$eventdata = new \core\message\message();
$eventdata->courseid = $course->id;
$eventdata->modulename = 'moodle';
$eventdata->component = 'enrol_paypal';
$eventdata->name = 'paypal_enrolment';
Expand All @@ -298,6 +301,7 @@
$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';
Expand Down
3 changes: 2 additions & 1 deletion error/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/classes/antivirus/scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public function message_admins($notice) {
$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();
Expand Down
1 change: 1 addition & 0 deletions lib/classes/update/checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ protected function cron_notify(array $notifications) {

foreach ($admins as $admin) {
$message = new \core\message\message();
$message->courseid = SITEID;
$message->component = 'moodle';
$message->name = 'availableupdate';
$message->userfrom = get_admin();
Expand Down
2 changes: 2 additions & 0 deletions lib/enrollib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2656,6 +2656,7 @@ protected function notify_expiry_enrolled($user, $ue, progress_trace $trace) {
$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';
Expand Down Expand Up @@ -2717,6 +2718,7 @@ protected function notify_expiry_enroller($eid, $users, progress_trace $trace) {
$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';
Expand Down
1 change: 1 addition & 0 deletions lib/portfoliolib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion message/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ public function test_get_messages() {
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';
Expand Down
9 changes: 6 additions & 3 deletions message/tests/search_test_received.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public function test_message_received_indexing() {
$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";
Expand Down Expand Up @@ -129,7 +130,8 @@ public function test_message_received_document() {
$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";
Expand Down Expand Up @@ -175,7 +177,8 @@ public function test_message_received_access() {
$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";
Expand Down
9 changes: 6 additions & 3 deletions message/tests/search_test_sent.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public function test_message_sent_indexing() {
$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";
Expand Down Expand Up @@ -129,7 +130,8 @@ public function test_message_sent_document() {
$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";
Expand Down Expand Up @@ -175,7 +177,8 @@ public function test_message_sent_access() {
$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";
Expand Down
1 change: 1 addition & 0 deletions mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 880fc15

Please sign in to comment.