Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This is a bit is an issue user_import does not save taxonomy field references I get the following error
Notice: Undefined index: tid in taxonomy_field_presave() (line 1889 of /modules/taxonomy/taxonomy.module).
Whilst I can see 1889 I cant find where in the user_upload module the pre-save is invoked.
It's rather urgent for me and any pointer in getting this resolved would be appreciated.
Thanks
Comments
Comment #1
eminencehealthcare CreditAttribution: eminencehealthcare commentedSame problem here. It would be really useful to have the user import module be able to fill term reference fields (not just text fields)
Comment #2
caesius CreditAttribution: caesius commentedI've been able to figure out essentially what the problem is.
On line 48 of the file supported/field.inc:
$user_fields = user_load($account->uid);
For the taxonomy fields, instead of an empty array the user_load function gives back this data:
It then adds the data entered for the user info as the "value:"
When it tries to save the taxonomy field in the function taxonomy_field_presave, the term ID is undefined, which will generate this notice:
Running on core version 7.21 and module version 1.0-beta5.
Comment #3
caesius CreditAttribution: caesius commentedThis patch is barely tested, but it did work for the very simple test I performed with it. Will need to to more rigorous testing, including seeing if the term autocreation works correctly.
Comment #4
caesius CreditAttribution: caesius commentedDisregard the previous patch; it generates errors when either a term doesn't exist or nothing has been entered for the field.
Updated patch fixes these issues. Ideally, however, there should be a way to enter multiple taxonomy terms into a single field. One way would be to enclose the field in quotes, require that the terms be separated by commas e.g. "Orange,Banana,Peach", and treat that as its own CSV. However, commas are allowed in taxonomy term names (as is seemingly all other punctuation), so this would not be a foolproof solution.
Comment #5
caesius CreditAttribution: caesius commentedGot it. The solution is to format terms which have the delimiter character as "first term,\"second, term\""
New patch now has complete taxonomy importing capabilities. Some notes:
1. As mentioned above, when importing multiple taxonomy terms the column must be enclosed with double quotes and each term must be separated with the delimiter character within the quotes, e.g. "Orange,Banana,Peach"
2. When the delimiter character is used inside a term, escaped double quotes must surround the term within the outer quotes, e.g. "\"This term, has a comma\""
3. The delimiter character selected in the settings is what must be used for the taxonomy term field as well. For example, if the pipe | character is used, a CSV might look like this:
username|email|"term one|\"term | two\""
4. This patch also fixes an apparently unreported bug whereby tab delimiters do not work.
Comment #6
eminencehealthcare CreditAttribution: eminencehealthcare commentedThis patch does not work for me when using a term reference field of any kind.
I see it has been committed to the latest dev version and that also does not seem to work.
I am getting two errors:
This one appears in my cron log under user import module:
And this one shows on the user account page:
Comment #7
caesius CreditAttribution: caesius commentedActually the only thing in my patch that has been applied is the additional tab options, nothing else. The patch no longer applies to the latest dev version anyway, and I accidentally left in a call to flog_it for file logging (which was probably what was giving you problems). Here is an updated dev patch (which I admittedly haven't tested).
Comment #8
chaloum CreditAttribution: chaloum commentedJust tried this It still not importing information that referes to term references, a bit sad
Comment #9
eminencehealthcare CreditAttribution: eminencehealthcare commentedMe too Chaloaum. I recommend using the feeds module. It wasn't as easy to set up and as convenient as this module is but it did the job.
Comment #10
cprouvot CreditAttribution: cprouvot commentedI create a path for use taxonomy field if you put the tid in your CSV file.
Comment #11
cprouvot CreditAttribution: cprouvot commentedThe patch above
Comment #12
Tritof CreditAttribution: Tritof commentedI tried the patch #11 above, it doesn"t work, error message:
Notice: Undefined index: tid in taxonomy_field_presave() (line 1894 of .../website/modules/taxonomy/taxonomy.module).
So it is about this line:
down there:
Comment #13
szt CreditAttribution: szt commentedAttached the patch for the latest 7.x-2.x dev.
Works well :)
(PHP 5 >= 5.3.0)
Comment #14
szt CreditAttribution: szt commentedDoesn't work with multiple terms...
This line has a small typo btw:
stripslashes not stripcslashes
The real problem is that $values must be an array of terms, but after this line it has only one term (with ";" delimiter and with "||" multiple value delimiter).
Comment #15
szt CreditAttribution: szt commentedWith this simpler patch the multiple terms works well.
The csv file contains this:
So I set the ";" and "||" delimiters properly at admin/people/user_import/add/[IMPORT_ID].
Comment #16
szt CreditAttribution: szt commentedComment #17
radziaziz CreditAttribution: radziaziz commentedI can confirm patch #15 works with 7.x-2.2. Thanks alot, you saved my day!
Comment #18
szt CreditAttribution: szt commentedComment #21
Robert Castelo CreditAttribution: Robert Castelo commentedPatch #15 committed to 7.x-2.x-dev branch.
Will roll a new release once I've gone through the other ready for review issues.