Moodle

"profile_field_menu" fields fail during upload of users from csv

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.9.2
  • Fix Version/s: None
  • Component/s: Administration
  • Labels:
  • Affected Branches:
    MOODLE_19_STABLE

Description

When uploading users from a csv file a menu-type custom user profile does not get the values inserted.

For example I have a user profile field with a shortname of studionumber that is a menu type field. The options are:

1234
2341
3421

In the csv I have:

firstname, lastname, username, email, profile_field_studionumber
testfirst, testlast, testuser, testuser@localhost.com, 2341

When I upload the user, the user gets added, but the custom menu field does not take the supplied value.

I get this error:

Column 'data' cannot be null

INSERT INTO mdl_user_info_data ( USERID, FIELDID, DATA ) VALUES ( 23, 3, null )

  • line 1554 of lib\dmllib.php: call to debugging()
  • line 102 of user\profile\lib.php: call to insert_record()
  • line 355 of user\profile\lib.php: call to profile_field_base->edit_save_data()
  • line 548 of admin\uploaduser.php: call to profile_save_data()

The problem is this:

profile_field_base->edit_save_data() calls profile_field_menu->edit_save_data_preprocess(). This function expects the key of the options array (which is what it is when it is called from editadvanced.php and other forms). However, since the csv file likely (and sensibly) contains a value and not a key edit_save_data_preprocess gets the value as a parameter instead of the key and returns NULL as a result.

I tried a quick hack as a solution and have attached the svn diff of the potential fix (it works, but may not be the most elegant solution).

Hope this helps.

  1. fix_select_moodle2.diff
    03/Nov/11 11:05 PM
    3 kB
    Brendan Rollinson
  2. profile_field_menu.patch
    23/Jul/09 11:19 PM
    1 kB
    Hubert Chathi
  3. profile_field_menu2.patch
    23/Jul/09 11:19 PM
    1 kB
    Hubert Chathi
  4. uploadusers.patch
    02/Oct/08 8:11 AM
    2 kB
    Sam Chaffee

Issue Links

Activity

Hide
Petr Škoda (skodak) added a comment -

Hmm, I think we should better convert the strings to key in uploadusers code before sending to other parts of moodle instead of making the code in /user/* more complex

Show
Petr Škoda (skodak) added a comment - Hmm, I think we should better convert the strings to key in uploadusers code before sending to other parts of moodle instead of making the code in /user/* more complex
Hide
Hubert Chathi added a comment -

Another option is to change edit_save_data_process to allow both the numeric values, or the actual field values. Attached is a patch (profile_field_menu.patch) to do that. Alternatively, you could just set the $this->options array to be keyed by the value, rather than an integer, and not have to worry about handling both cases. The profile_field_menu2.patch does this.

A third option is to have the CSV upload use a completely different set of functions to set the values.

Show
Hubert Chathi added a comment - Another option is to change edit_save_data_process to allow both the numeric values, or the actual field values. Attached is a patch (profile_field_menu.patch) to do that. Alternatively, you could just set the $this->options array to be keyed by the value, rather than an integer, and not have to worry about handling both cases. The profile_field_menu2.patch does this. A third option is to have the CSV upload use a completely different set of functions to set the values.
Hide
Hubert Chathi added a comment -

We have been using profile_field_menu2.patch for many of our clients for quite some time, and it works fine. Note that this issue also affects CSV export (menu of choices fields get exported as a numerical index), and the patch fixes this as well.

Show
Hubert Chathi added a comment - We have been using profile_field_menu2.patch for many of our clients for quite some time, and it works fine. Note that this issue also affects CSV export (menu of choices fields get exported as a numerical index), and the patch fixes this as well.
Hide
Lehane Boonzaaier added a comment -

We have encountered this in Moodle 2.0.3 and have tested it in Moodle 2.1 and found that this bug has not been fixed in this version as well, so it affects this branch of Moodle 2 as well.
Is there a fix or patch available for Moodle 2.x? If not, could this be fixed/patched and released later in one of the next weekly builds? We need this functionality to work for reporting purposes and it is important to our clients that we fix this for them.

Show
Lehane Boonzaaier added a comment - We have encountered this in Moodle 2.0.3 and have tested it in Moodle 2.1 and found that this bug has not been fixed in this version as well, so it affects this branch of Moodle 2 as well. Is there a fix or patch available for Moodle 2.x? If not, could this be fixed/patched and released later in one of the next weekly builds? We need this functionality to work for reporting purposes and it is important to our clients that we fix this for them.
Hide
Brendan Rollinson added a comment -

This is a patch t hat seems to fix the issue in Moodle 2. This is similar to the second patch posted, but also fixes an issue I'd encountered where fatal error were generated for profile fields not included in the import file.

Show
Brendan Rollinson added a comment - This is a patch t hat seems to fix the issue in Moodle 2. This is similar to the second patch posted, but also fixes an issue I'd encountered where fatal error were generated for profile fields not included in the import file.

Dates

  • Created:
    Updated: