MDL-45818 core_message: use system context if user no longer exists

This commit is contained in:
Mark Nelson
2014-08-29 16:20:08 -07:00
parent e6f1c141bf
commit 763e5d6c83
+8 -1
View File
@@ -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