]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12020 can not bulk delete users with the same email - new username collision
authorskodak <skodak>
Sun, 4 Nov 2007 13:51:26 +0000 (13:51 +0000)
committerskodak <skodak>
Sun, 4 Nov 2007 13:51:26 +0000 (13:51 +0000)
lib/moodlelib.php

index 74f5a1cc183ca2c3b52a2cfd26ca8c3d05ca2025..ffd91461501ad2bd9c1a90126d400a158640c9d1 100644 (file)
@@ -2867,11 +2867,17 @@ function delete_user($user) {
     // now do a final accesslib cleanup - removes all role assingments in user context and context itself
     delete_context(CONTEXT_USER, $user->id);
 
+    // workaround for bulk deletes of users with the same email address
+    $delname = addslashes("$user->email.".time());
+    while (record_exists('user', 'username', $delname)) { // no need to use mnethostid here
+        $delname++;
+    }
+
     // mark internal user record as "deleted"
     $updateuser = new object();
     $updateuser->id           = $user->id;
     $updateuser->deleted      = 1;
-    $updateuser->username     = addslashes("$user->email.".time());  // Remember it just in case
+    $updateuser->username     = $delname;         // Remember it just in case
     $updateuser->email        = '';               // Clear this field to free it up
     $updateuser->idnumber     = '';               // Clear this field to free it up
     $updateuser->timemodified = time();