Few days ago I posted the bug 4576 and, thanks to Inaki, the bug is already solved.
The problem was that by importing new users from text file it was possible to enroll two users with the same email address.
Inaki provided a good and fast solution and, on the basis of his solution, my proposal is to add a specific error message for the admin who is importing the list of students.
This is the line of code of the current Moodle version allowing the error:
if (get_record("user","username",$username) || !($user->id = insert_record("user", $user))) {
if (!$user = get_record("user", "username", "changeme")) { // half finished user from another time
//Record not added - probably because user is already registered
//In this case, output userid from previous registration
//This can be used to obtain a list of userids for existing users
if ($user = get_record("user","username",$username)) {
notify("$user->id ".get_string('usernotaddedregistered', 'error', $username));
} else {
notify(get_string('usernotaddederror', 'error', $username));
}
}
} else if ($user->username != "changeme") {
notify("$struser: $user->id = $user->username");
$numusers++;
}
This is the good solution provided by Inaki (he correctly focused his attention to the first line only):
if (get_record("user","username",$username) || get_record("user","email",$user->email) || !($user->id = insert_record("user", $user))) {
if (!$user = get_record("user", "username", "changeme")) { // half finished user from another time
//Record not added - probably because user is already registered
//In this case, output userid from previous registration
//This can be used to obtain a list of userids for existing users
if ($user = get_record("user","username",$username)) {
notify("$user->id ".get_string('usernotaddedregistered', 'error', $username));
} else {
notify(get_string('usernotaddederror', 'error', $username));
}
}
} else if ($user->username != "changeme") {
notify("$struser: $user->id = $user->username");
$numusers++;
}
This is the more complete solution I am proposing now.
if (get_record("user","username",$username) || get_record("user","email",$user->email) || !($user->id = insert_record("user", $user))) {
if (!$user = get_record("user", "username", "changeme")) { // half finished user from another time
//Record not added - probably because user is already registered
//In this case, output userid from previous registration
//This can be used to obtain a list of userids for existing users
if ($user = get_record("user","username",$username)) {
notify("$user->id ".get_string('usernotaddedregistered', 'error', $username));
} else {
if ($user = get_record("user","email",$user->email)) {
notify("$user->id ".get_string('usernotaddedduplicateemail', 'error', $username));
}
else {
notify(get_string('usernotaddederror', 'error', $username));
}
}
}
} else if ($user->username != "changeme") {
notify("$struser: $user->id = $user->username");
$numusers++;
}
As you can see my solution foresee a new string in /moodle/lang/en/error.php
Attached is the updated error.php file and my general update to the file /moodle/admin/uploaduser.php.
What do you think about?
May I ask to update the daily release?
Thank you in advance.
Please keep this in the bug tracker ...
I beg your pardon
I can't understand.
What do I have to keep in the bug tracker? It is already keeped. You added it!
What do I have to do?
I can't understand.
What do I have to keep in the bug tracker? It is already keeped. You added it!
What do I have to do?