From 151fc538de0f3cb3c348c7c6501683ed66c86aa1 Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Tue, 7 May 2019 11:03:28 +0800 Subject: [PATCH] MDL-65313 core: fix deletion of group conversation favourites This now requires itemid, which cannot be null. This is safer. The context is still used an an additional filter. --- group/lib.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/group/lib.php b/group/lib.php index 78e4f0afba7..05bb290f3d3 100644 --- a/group/lib.php +++ b/group/lib.php @@ -575,9 +575,10 @@ function groups_delete_group($grouporid) { // Delete all favourite records for all users relating to this conversation. // Whilst not ideal, we can't use the component service as it doesn't exist here, so must do this manually. - $params = ['component' => 'core_message', 'itemtype' => 'message_conversations', 'contextid' => $conversation->contextid]; - $DB->delete_records_select('favourite', ' component = :component AND itemtype = :itemtype AND contextid = :contextid', - $params); + $params = ['component' => 'core_message', 'itemtype' => 'message_conversations', 'itemid' => $conversation->id, + 'contextid' => $conversation->contextid]; + $select = ' component = :component AND itemtype = :itemtype AND itemid = :itemid AND contextid = :contextid'; + $DB->delete_records_select('favourite', $select, $params); } //group itself last