MDL-64568 core_group: delete conversation and members on group deletion
authorMark Nelson <markn@moodle.com>
Thu, 28 Feb 2019 06:41:43 +0000 (14:41 +0800)
committerAdrian Greeve <abgreeve@gmail.com>
Wed, 13 Mar 2019 07:42:03 +0000 (15:42 +0800)
group/lib.php

index c2edce9..42e7fbe 100644 (file)
@@ -548,12 +548,20 @@ function groups_delete_group($grouporid) {
         }
     }
 
+    $context = context_course::instance($group->courseid);
+
     // delete group calendar events
     $DB->delete_records('event', array('groupid'=>$groupid));
     //first delete usage in groupings_groups
     $DB->delete_records('groupings_groups', array('groupid'=>$groupid));
     //delete members
     $DB->delete_records('groups_members', array('groupid'=>$groupid));
+
+    // Delete any members in a conversation related to this group.
+    if ($conversation = \core_message\api::get_conversation_by_area('core_group', 'groups', $groupid, $context->id)) {
+        \core_message\api::delete_all_conversation_data($conversation->id);
+    }
+
     //group itself last
     $DB->delete_records('groups', array('id'=>$groupid));