MDL-63401 core: Do not delete the user context
authorAndrew Nicols <andrew@nicols.co.uk>
Fri, 28 Sep 2018 06:39:17 +0000 (14:39 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Mon, 8 Oct 2018 12:49:17 +0000 (20:49 +0800)
As long as we have a user record, we should not delete the context which
relates to it.

lib/moodlelib.php

index 2e921e7..d955a17 100644 (file)
@@ -4182,8 +4182,8 @@ function delete_user(stdClass $user) {
     // Don't trigger update event, as user is being deleted.
     user_update_user($updateuser, false, false);
 
-    // Now do a final accesslib cleanup - removes all role assignments in user context and context itself.
-    context_helper::delete_instance(CONTEXT_USER, $user->id);
+    // Delete all content associated with the user context, but not the context itself.
+    $usercontext->delete_content();
 
     // Any plugin that needs to cleanup should register this event.
     // Trigger event.