-
Bug
-
Resolution: Fixed
-
Major
-
1.6.7, 1.7.5, 1.8.6
-
None
-
MOODLE_16_STABLE, MOODLE_17_STABLE, MOODLE_18_STABLE
-
MOODLE_19_STABLE
When I try to upload existing users to new course ,error messages are displayed as below.
-------------
User "user001" not added - already registered
-->Not enrolled in course "course001"
User "user002" not added - already registered
-->Not enrolled in course "course001"
-------------
It seems to be '$user->id' is not set when "Update existing accounts" not being set as "Yes".
To avoid "Not enrolled in course" error, we can fix admin/uploaduser.php as below.
File: admin/uploaduser.php
Line: 251
[before]
if ($olduser = get_record("user", "username", $username, "mnethostid", $user->mnethostid)) {
if ($updateaccounts) {
// Record is being updated
$user->id = $olduser->id;
if (update_record('user', $user))
} else {
//Record not added - 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
notify("$olduser->id ".get_string('usernotaddedregistered', 'error', $username));
[after]
if ($olduser = get_record("user", "username", $username, "mnethostid", $user->mnethostid)) {
$user->id = $olduser->id;
if ($updateaccounts) {
// Record is being updated
if (update_record('user', $user)) { notify("$user->id , $user->username ".get_string('useraccountupdated', 'admin')); $usersupdated++; }
else
{ notify(get_string('usernotupdatederror', 'error', $username)); $userserrors++; continue; } } else {
//Record not added - 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
notify("$olduser->id ".get_string('usernotaddedregistered', 'error', $username));