about error 4576

about error 4576

por Daniele Cordella -
Número de respostas: 2
Foto de Core developers Foto de Particularly helpful Moodlers Foto de Plugin developers
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.
Em resposta a 'Daniele Cordella'

Re: about error 4576

por Martin Dougiamas -
Foto de Core developers Foto de Documentation writers Foto de Moodle HQ Foto de Particularly helpful Moodlers Foto de Plugin developers Foto de Testers
Please keep this in the bug tracker ...