From d8aa5ec7a073b28e501d7cb173e2913520d05329 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Wed, 16 Nov 2011 13:01:55 +0800 Subject: [PATCH] MDL-30260 message: added /message/upgrade.txt, checked calls to message_send() are supplying user.emailstop and improved message_send() to handle message requests that don't --- error/index.php | 3 +++ lib/accesslib.php | 2 +- lib/messagelib.php | 11 +++++++++-- message/upgrade.txt | 9 +++++++++ mod/forum/lib.php | 3 ++- mod/quiz/locallib.php | 2 +- 6 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 message/upgrade.txt diff --git a/error/index.php b/error/index.php index 3728870d604..0e57570747d 100644 --- a/error/index.php +++ b/error/index.php @@ -19,6 +19,9 @@ $supportuser->email = $CFG->supportemail ? $CFG->supportemail : $admin->email; $supportuser->firstname = $CFG->supportname ? $CFG->supportname : $admin->firstname; $supportuser->lastname = $CFG->supportname ? '' : $admin->lastname; + // emailstop could be hard coded "false" to ensure error reports are sent + // but then admin's would have to alter their messaging preferences to temporarily stop them + $supportuser->emailstop = $admin->emailstop; $supportuser->maildisplay = true; /// Send the message and redirect diff --git a/lib/accesslib.php b/lib/accesslib.php index 44793792c72..4218a7822d2 100644 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -3733,7 +3733,7 @@ function get_role_users($roleid, context $context, $parent = false, $fields = '' if (empty($fields)) { $fields = 'u.id, u.confirmed, u.username, u.firstname, u.lastname, '. - 'u.maildisplay, u.mailformat, u.maildigest, u.email, u.city, '. + 'u.maildisplay, u.mailformat, u.maildigest, u.email, u.emailstop, u.city, '. 'u.country, u.picture, u.idnumber, u.department, u.institution, '. 'u.lang, u.timezone, u.lastaccess, u.mnethostid, r.name AS rolename, r.sortorder'; } diff --git a/lib/messagelib.php b/lib/messagelib.php index 5fb858853ef..12d35727a5b 100644 --- a/lib/messagelib.php +++ b/lib/messagelib.php @@ -139,12 +139,19 @@ function message_send($eventdata) { debugging('Attempt to force message delivery to user who has "'.$processor->name.'" output unconfigured', DEBUG_NORMAL); } + // Warn developers that necessary data is missing regardless of how the processors are configured + if (!isset($eventdata->userto->emailstop)) { + debugging('userto->emailstop is not set. Retrieving it from the user table'); + $eventdata->userto->emailstop = $DB->get_field('user', 'emailstop', array('id'=>$eventdata->userto->id)); + } + // Populate the list of processors we will be using if ($permitted == 'forced' && $userisconfigured) { - // We force messages for this processor, so use this processor unconditionally if user has configured it + // An admin is forcing users to use this message processor. Use this processor unconditionally. $processorlist[] = $processor->name; } else if ($permitted == 'permitted' && $userisconfigured && !$eventdata->userto->emailstop) { - // User settings are permitted, see if user set any, otherwise use site default ones + // User has not disabled notifications + // See if user set any notification preferences, otherwise use site default ones $userpreferencename = 'message_provider_'.$preferencebase.'_'.$userstate; if ($userpreference = get_user_preferences($userpreferencename, null, $eventdata->userto->id)) { if (in_array($processor->name, explode(',', $userpreference))) { diff --git a/message/upgrade.txt b/message/upgrade.txt new file mode 100644 index 00000000000..a45939cb804 --- /dev/null +++ b/message/upgrade.txt @@ -0,0 +1,9 @@ +This files describes API changes in /message/ messaging system, +information provided here is intended especially for developers. + +=== 2.2 === + +required changes: +* lib/messagelib.php message_send($eventdata) + $eventdata->userto should contain a property called "emailstop", $eventdata->userto->emailstop + If it is absent it will be retrieved from the user table causing an additional database query diff --git a/mod/forum/lib.php b/mod/forum/lib.php index cc5ef170ef7..b8510bf1afa 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -2855,6 +2855,7 @@ function forum_subscribed_users($course, $forum, $groupid=0, $context = null, $f u.maildigest, u.imagealt, u.email, + u.emailstop, u.city, u.country, u.lastaccess, @@ -8357,4 +8358,4 @@ function forum_get_posts_by_user($user, array $courses, $musthaveaccess = false, } return $return; -} \ No newline at end of file +} diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index 98ddd21d2aa..70cb84c044a 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -1174,7 +1174,7 @@ function quiz_send_notification_messages($course, $quiz, $attempt, $context, $cm } // check for notifications required - $notifyfields = 'u.id, u.username, u.firstname, u.lastname, u.idnumber, u.email, ' . + $notifyfields = 'u.id, u.username, u.firstname, u.lastname, u.idnumber, u.email, u.emailstop, ' . 'u.lang, u.timezone, u.mailformat, u.maildisplay'; $groups = groups_get_all_groups($course->id, $submitter->id); if (is_array($groups) && count($groups) > 0) {