Right now, when one user is deleted from Moodle server this happens (delete_user() function):
- user->username is set to user->email + random string
- user->email is cleaned (empty string)
So we lost any original username information forever.
And that is good in the sense that leaves the username free to be reused by other user later. But it's definitively wrong when we try to import (csv, restore...) users and perform various checks to see if one user already existed. And that can lead to "revived" users that shouldn't be there.
So, in order to keep the deleted username free to be reused, we are going to start storing the md5 hash of the username into the email field, so utilities creating users will be able to compare that hash in order to detect if the user already existed or no.
Obviously that md5 only will be there for users deleted in the future and old deletions will continue having empty strings forever, so import utilities only will rely on that hash if not empty (this is one important point).
So, starting now, we are going to do this on user deletion:
- user->username is set to user->email + random string (no change here)
- user->email is set to md5(user->username)