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

Upload users from CSV file fails if you have created custom profile fields.

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Not a bug
    • 2.0, 2.0.1, 2.1, 2.1.1, 2.2
    • None
    • Administration
    • None
    • Linux moodle-1 2.6.35-22-server #35-Ubuntu SMP Sat Oct 16 22:02:33 UTC 2010 x86_64 GNU/Linux
    • MySQL
    • MOODLE_20_STABLE, MOODLE_21_STABLE, MOODLE_22_STABLE
    • Hide

      The following diff fixes the issue for 2.2 code branch, which has moved the file from admin/uploadusers.php to admin/tool/uploaduser/index.php and I have successfully tested on our 2.2.1 (Build: 20120109)

      — index.php 2011-09-21 16:44:44.000000000 +0100
      +++ index.fix.php 2012-01-17 13:46:17.000000000 +0000
      @@ -95,7 +95,7 @@

      if ($prof_fields = $DB->get_records('user_info_field')) {
      foreach ($prof_fields as $prof_field)

      { - $PRF_FIELDS[] = 'profile_field_'.$prof_field->shortname; + $PRF_FIELDS[] = $prof_field->shortname; }

      }
      unset($prof_fields);

      The following diff might fix the issue for the 2.0 and 2.1 versions of the Moodle code - I say might as I notice I had posted a reverse diff which I have now corrected but not tested:

      diff -ui /export/1/cis/vle/moodle/admin/uploaduser.php Downloads/uploaduser.php
      — /export/1/cis/vle/moodle/admin/uploaduser.php 2011-09-02 13:05:07.523400025 +0100
      +++ Downloads/uploaduser.php 2011-09-02 12:11:31.893825964 +0100
      @@ -95,7 +95,7 @@

      if ($prof_fields = $DB->get_records('user_info_field')) {
      foreach ($prof_fields as $prof_field)

      { - $PRF_FIELDS[] = 'profile_field_'.$prof_field->shortname; + $PRF_FIELDS[] = $prof_field->shortname; }

      }
      unset($prof_fields);

      Show
      The following diff fixes the issue for 2.2 code branch, which has moved the file from admin/uploadusers.php to admin/tool/uploaduser/index.php and I have successfully tested on our 2.2.1 (Build: 20120109) — index.php 2011-09-21 16:44:44.000000000 +0100 +++ index.fix.php 2012-01-17 13:46:17.000000000 +0000 @@ -95,7 +95,7 @@ if ($prof_fields = $DB->get_records('user_info_field')) { foreach ($prof_fields as $prof_field) { - $PRF_FIELDS[] = 'profile_field_'.$prof_field->shortname; + $PRF_FIELDS[] = $prof_field->shortname; } } unset($prof_fields); The following diff might fix the issue for the 2.0 and 2.1 versions of the Moodle code - I say might as I notice I had posted a reverse diff which I have now corrected but not tested: diff -ui /export/1/cis/vle/moodle/admin/uploaduser.php Downloads/uploaduser.php — /export/1/cis/vle/moodle/admin/uploaduser.php 2011-09-02 13:05:07.523400025 +0100 +++ Downloads/uploaduser.php 2011-09-02 12:11:31.893825964 +0100 @@ -95,7 +95,7 @@ if ($prof_fields = $DB->get_records('user_info_field')) { foreach ($prof_fields as $prof_field) { - $PRF_FIELDS[] = 'profile_field_'.$prof_field->shortname; + $PRF_FIELDS[] = $prof_field->shortname; } } unset($prof_fields);
    • Easy
    • Hide

      1. Create a new "User Profile Field" with the shortname of nickname
      2. Create a CSV to upload including the shortname of the new field (nickname)
      3. Go to upload users and upload the file
      4. the upload fails with:
      "nickname" is not a valid field name

      Apply the following diff to admin/tools/uploaduser/index.php fixes the issue:

      — index.php 2011-09-21 16:44:44.000000000 +0100
      +++ index.fix.php 2012-01-17 13:46:17.000000000 +0000
      @@ -95,7 +95,7 @@

      if ($prof_fields = $DB->get_records('user_info_field')) {
      foreach ($prof_fields as $prof_field)

      { - $PRF_FIELDS[] = 'profile_field_'.$prof_field->shortname; + $PRF_FIELDS[] = $prof_field->shortname; }

      }
      unset($prof_fields);

      The Fix for the older versions requires the same line to change in the admin/uploaduser.php file.

      More information about this error from the 2.1 builds:

      Stack trace:
      line 429 of /lib/setuplib.php: moodle_exception thrown
      line 207 of /admin/uploaduserlib.php: call to print_error()
      line 121 of /admin/uploaduser.php: call to uu_validate_user_upload_columns()

      Show
      1. Create a new "User Profile Field" with the shortname of nickname 2. Create a CSV to upload including the shortname of the new field (nickname) 3. Go to upload users and upload the file 4. the upload fails with: "nickname" is not a valid field name Apply the following diff to admin/tools/uploaduser/index.php fixes the issue: — index.php 2011-09-21 16:44:44.000000000 +0100 +++ index.fix.php 2012-01-17 13:46:17.000000000 +0000 @@ -95,7 +95,7 @@ if ($prof_fields = $DB->get_records('user_info_field')) { foreach ($prof_fields as $prof_field) { - $PRF_FIELDS[] = 'profile_field_'.$prof_field->shortname; + $PRF_FIELDS[] = $prof_field->shortname; } } unset($prof_fields); The Fix for the older versions requires the same line to change in the admin/uploaduser.php file. More information about this error from the 2.1 builds: Stack trace: line 429 of /lib/setuplib.php: moodle_exception thrown line 207 of /admin/uploaduserlib.php: call to print_error() line 121 of /admin/uploaduser.php: call to uu_validate_user_upload_columns()

    Description

      Okay - I have no upgraded to 2.2 and the problem still exists, and the process described below still shows the problem - which is due to php code adding an unnecessary string to the front of the field.

      If you create any "User Profile Fields" and then include the profile field in your uploaded file the upload fails.

      This is due to the user profile field having the 'profile_field_' appended to the $prof_field->shortname thus the field in the database is never found as the user profile fields are no longer prepended with 'profile_field_'

      This bug has been raised before as:

      Moodle MDL-26474

      But was not fixed the 'profile_field_' is still there causing the issue.

      Thanks

      Fred

      Attachments

        Issue Links

          Activity

            People

              rajeshtaneja Rajesh Taneja
              fcbsd Fred Crowson
              Andrew Lyons, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Stevani Andolo
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: