MDL-61984 mod_chat: Do not assume context passed is one of chat
authorFrédéric Massart <fred@branchup.tech>
Tue, 24 Apr 2018 02:38:27 +0000 (10:38 +0800)
committerFrédéric Massart <fred@branchup.tech>
Tue, 24 Apr 2018 02:38:27 +0000 (10:38 +0800)
mod/chat/classes/privacy/provider.php

index 4d72767..4cdc875 100644 (file)
@@ -167,7 +167,12 @@ class provider implements
             return;
         }
 
-        $chatid = get_coursemodule_from_id('chat', $context->instanceid, 0, false, MUST_EXIST)->instance;
+        $cm = get_coursemodule_from_id('chat', $context->instanceid);
+        if (!$cm) {
+            return;
+        }
+
+        $chatid = $cm->instance;
         $DB->delete_records_select('chat_messages', 'chatid = :chatid', ['chatid' => $chatid]);
         $DB->delete_records_select('chat_messages_current', 'chatid = :chatid', ['chatid' => $chatid]);
         $DB->delete_records_select('chat_users', 'chatid = :chatid', ['chatid' => $chatid]);