MDL-64167 core_message: fix for sending bulk messages from site admin

This ensures the following:
- An admin/manager can send a message to all users, including themself,
without any errors.
This commit is contained in:
Jake Dallimore 2018-11-23 10:25:46 +08:00
parent 599703e83d
commit ad5de40c49

View File

@ -82,11 +82,14 @@ class manager {
$localisedeventdata = clone $eventdata;
// Get user records for all members of the conversation.
// We must fetch distinct users, because it's possible for a user to message themselves via bulk user actions.
// In such cases, there will be 2 records referring to the same user.
$sql = "SELECT u.*
FROM {message_conversation_members} mcm
JOIN {user} u
ON (mcm.conversationid = :convid AND u.id = mcm.userid)
ORDER BY u.id desc";
FROM {user} u
WHERE u.id IN (
SELECT mcm.userid FROM {message_conversation_members} mcm
WHERE mcm.conversationid = :convid
)";
$members = $DB->get_records_sql($sql, ['convid' => $eventdata->convid]);
if (empty($members)) {
throw new \moodle_exception("Conversation has no members or does not exist.");