MDL-67312 core_user: clean subs events on user deletion
authorSimey Lameze <simey@moodle.com>
Thu, 21 Nov 2019 10:36:05 +0000 (18:36 +0800)
committerSara Arjona <sara@moodle.com>
Mon, 20 Jan 2020 07:09:16 +0000 (08:09 +0100)
lib/moodlelib.php

index 1b69c4a..f0ced44 100644 (file)
@@ -4250,7 +4250,10 @@ function delete_user(stdClass $user) {
 
     // Now do a brute force cleanup.
 
-    // Remove user's calendar subscriptions.
+    // Delete all user events and subscription events.
+    $DB->delete_records_select('event', 'userid = :userid AND subscriptionid IS NOT NULL', ['userid' => $user->id]);
+
+    // Now, delete all calendar subscription from the user.
     $DB->delete_records('event_subscriptions', ['userid' => $user->id]);
 
     // Remove from all cohorts.