MDL-45818 core_message: use system context if user no longer exists
This commit is contained in:
+8
-1
@@ -2375,11 +2375,18 @@ function message_mark_message_read($message, $timeread, $messageworkingempty=fal
|
||||
|
||||
$DB->delete_records('message', array('id' => $messageid));
|
||||
|
||||
// Get the context for the user who received the message.
|
||||
$context = context_user::instance($message->useridto, IGNORE_MISSING);
|
||||
// If the user no longer exists the context value will be false, in this case use the system context.
|
||||
if ($context === false) {
|
||||
$context = context_system::instance();
|
||||
}
|
||||
|
||||
// Trigger event for reading a message.
|
||||
$event = \core\event\message_viewed::create(array(
|
||||
'objectid' => $messagereadid,
|
||||
'userid' => $message->useridto, // Using the user who read the message as they are the ones performing the action.
|
||||
'context' => context_user::instance($message->useridto),
|
||||
'context' => $context,
|
||||
'relateduserid' => $message->useridfrom,
|
||||
'other' => array(
|
||||
'messageid' => $messageid
|
||||
|
||||
Reference in New Issue
Block a user