Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-16779

Can't enroll existing users to new courses using admin/Upload users feature.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 1.9
    • 1.6.7, 1.7.5, 1.8.6
    • Administration
    • 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))

      { 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));

      [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));

            skodak Petr Skoda
            mits Mitsuhiro Yoshida
            Sam Hemelryk Sam Hemelryk
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.