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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.6.7, 1.7.5, 1.8.6
    • Fix Version/s: 1.9
    • Component/s: Administration
    • Labels:
      None
    • Affected Branches:
      MOODLE_16_STABLE, MOODLE_17_STABLE, MOODLE_18_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE

      Description

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

        Attachments

          Activity

            People

            • Assignee:
              skodak Petr Skoda
              Reporter:
              mits Mitsuhiro Yoshida
              Tester:
              Sam Hemelryk
              Participants:
              Component watchers:
              Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                3/Mar/08