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.
One of my Vocabularies contains numeric string-vaules, e.g. '2010', '2020'.
If I import a csv-file containing nodes with numeric terms, the terms get translated to their term name, but to their term ID.
See the test results in below diagram:
Vocabulary Feeds importer Result
tid | Name Name | Term Name | Term
10 | 2010 first |2010 first |
11 | 2020 second|11 second| 2020
12 | X010 third |X010 third | X010
Comment | File | Size | Author |
---|---|---|---|
#60 | feeds_taxonomy_by_tid.patch | 679 bytes | Frando |
#56 | feeds_1019688_51-taxonomy-mapper-options.patch | 10.43 KB | johnv |
#53 | feeds-allow-numeric-terms-1019688-53.patch | 1.08 KB | David Hernández |
#51 | feeds_1019688_51-taxonomy-mapper-options.patch | 10.43 KB | johnv |
#48 | feeds-taxonomy-mapper-options-1019688-48.patch | 10.42 KB | sin |
Comments
Comment #1
Andrey Zakharov CreditAttribution: Andrey Zakharov commentedas temporary solution comment out code in mappers/taxonomy.inc: 92:
Comment #2
johnvThe following 'patch' splits the taxonomy mapper in two: 'Term name' and 'Term ID'.
This avoids the mapping error with numeric term values, and gives better control by the user.
and in the function itself:
Comment #3
7wonders CreditAttribution: 7wonders commentedI confirm the above works. My question would be is it possible to dynamically do this with all the fields of a given taxonomy so that all fields for the term are exposed to be mapped to (image etc) ?
Comment #4
XiaN Vizjereij CreditAttribution: XiaN Vizjereij commentedSubscribe
Comment #5
johnv@7wonders,
do you want to map to ANY field in the content type? then check this issue: #1111412: How to use unique target to update imported nodes?
Comment #6
7wonders CreditAttribution: 7wonders commentedThanks for the suggestion johnv but no, not really what im after. I know that its possible to import to taxonomy and then import to nodes referencing those terms (with d7 this means that you can then have a wealth of fields in the term etc). But what I was after is skipping the importing to the taxonomy part first and doing straight off the node import. At present the taxonomy field of the node is exposed to be imported into (and this patch allows for term name or term id) but not the other associated fields.
Comment #8
johnvAh, I understand. I think you need 2 importers. But you can make a super import file, and run it twice: once for the terms, and once for the nodes.
Comment #9
eiriksmsubscribing
Comment #10
Anonymous (not verified) CreditAttribution: Anonymous commentedGreat module :) I'm using alpha4
I have taxonomy terms as years, 2000,1999,1998 etc and in my database, the term '2000' has a tid of 30.
If I do a csv node import with '2000' linked to my term reference field I don't get any result. However, if I do a node import with '30' I get my '2000' taxonomy term correctly referenced in the newly created node.
#1 proved a quick fix for the data I was working on :)
Comment #11
Summit CreditAttribution: Summit commentedSubscribing,
I was wondering what went wrong, trying for hours then found this issue.
#1 worked for me!
Would be great if solution would be committed please.
greetings, Martijn
Comment #12
Steven.Pescador CreditAttribution: Steven.Pescador commentedHi all,
Stumbled upon this thread when faced with a similar problem today. Some of the term names in one of my vocabularies are numeric ie. 004 - which during import, are being assumed related to term id rather than term name care of this condition ---- elseif (is_numeric($term)) { $tid = $term; }
I'm aware I could use the term id in my csv, but what if my client is using this csv for updates and only knows the term names..? (would rather not confuse them as well) Do I have any other options apart from kitten killing..?
Apologies if you think this tangent isn't related, seemed to be a scenario that I thought more than just myself would face..?
Thanks for your time.
**Edit**
Seems my trail of rookiness left on the threads of Drupal has now grown larger...
Applied patch #2 and my import of numeric taxonomy terms worked flawlessly. (with no need of knowing the term id obviously).
Note to self - read each comment more thoroughly. Thanks johnv, much appreciated.
Comment #13
ts145nera CreditAttribution: ts145nera commentedsubscribe, #2 work for me
Thank You
Comment #14
ts145nera CreditAttribution: ts145nera commentedI export the #2 in patch.
Please review
Comment #15
tyler-durden CreditAttribution: tyler-durden commentedI'm assuming this will not work for 6.x versions? If not, would it be too much work to port over?
Comment #16
johnvtyler-durden, it shouldn't be to hard. Just open your php-file and try to copy-and-paste as much as possible.
Comment #17
tyler-durden CreditAttribution: tyler-durden commentedThanks for the tip, I looked at it and it seems easy but after I figured out my original problem so I don't need to use the ID # anymore.
Comment #18
TechNikh CreditAttribution: TechNikh commentedhad same issue. Glad I saw this post
Comment #19
TechNikh CreditAttribution: TechNikh commentedI comment out code in mappers/taxonomy.inc: 92:
but if the number is zero (0) it didn't get imported
Comment #20
7wonders CreditAttribution: 7wonders commentedThis patch is working great and together with the term_hierarchy extension to feeds tamper I can now import hierarchy straight into nodes. Nice!
Comment #21
7wonders CreditAttribution: 7wonders commentedScrap my last comment, there are still some issues with importing hierarchy if having to use this patch.
Comment #22
itamair CreditAttribution: itamair commentedthere was a littel error in the #2 code (second callback function should be:'callback' => 'taxonomy_feeds_set_target_tid') and the patch #14 didn't apply for me.
So I found my fixes.
The final taxonomy.inc that works for me is here attached. I guess should be implemented in the module core ... as it's yet.
Comment #23
johnvThis is a proper patch for itamair's version #22.
Comment #24
philipz CreditAttribution: philipz commentedBasing on #23 I've made a patch to add term mapping by it's GUID. This requires taxonomy terms to be imported by Feeds with GUID assigned to them.
Comment #25
johnv@philipz, your patch seems to be built on top of #22. Can you create a new patch which includes #22?
This is common practice, so that the last patch is always the most recent en the 'richest'.
Comment #26
philipz CreditAttribution: philipz commented@johnv you're right. Here's the patch combined from #23 and #24.
Comment #27
BWPanda CreditAttribution: BWPanda commentedPatch from #26 works for me!
Comment #28
nmc CreditAttribution: nmc commentedPatch #26 worked for me as well. Thanks!
Comment #29
reszli#26 works! thanks!
Comment #30
Masala CreditAttribution: Masala commented#26 patch is applied on dev version perfectly!
Comment #31
GaëlGI have last dev version and it failed too. Anyway, it can be applied manually.
Comment #32
GaëlG#26 :
$target = str_replace(':guid', '', $target);
should be at the beginning of the function, no? So that field_info_field() works.Comment #33
iMiksuWhen this fix gets committed?
Comment #34
philipz CreditAttribution: philipz commented#32 This might be true :) and checking for ":tid" in the $target should be added as well.
Comment #35
geek-merlincool work, but needs work so...
Comment #36
twistor CreditAttribution: twistor commentedThis should use the new configuration api for mappers, rather than declare a bunch of targets.
Also, the current mapping behavior should be left alone and deprecated.
For references see:
#1588938: Allow selection of filter for each text field imported
#1697150: Add separator to floats and decimals.
Comment #37
davident CreditAttribution: davident commentedAs a temporary fix against the latest dev:
In mappers/taxonomy.inc Line 91
Comment #38
philipz CreditAttribution: philipz commented#36 twistor can you please explain a bit more? I checked refereced issues/patches but unfortunately this doesn't tell me much.
Comment #39
sin CreditAttribution: sin commentedHere is my variant. It adds some options using new configuration api for mappers:
-Term name or ID (old behaviour with is_numeric($term))
-Term name (call taxonomy_term_check_term(), may create terms)
-Term ID (just use $term as tid without additional checks or term creation)
-GUID (use taxonomy_term_lookup_term_by_guid() by philipz, just search, do not create terms)
I tested only GUID variant for importing commerce taxonomy and products from XML via feeds_xpathparser. The patch from #1825682: Notice error correction was used too.
This string from philipz's patch was a mystery for me:
$target = str_replace(':guid', '', $target);
But somehow it works :)
Twistor, please be more specific about "current mapping behavior should be left alone and deprecated", the GUID taxonomy matching feature is absolutely needed for some of our current projects and I might work more on this.
Comment #40
sin CreditAttribution: sin commentedI guess we need new title :)
Comment #41
sin CreditAttribution: sin commentedWe might also need to add a key to guid column of feeds_item table.
Comment #42
twistor CreditAttribution: twistor commentedOk, #39 gets most of the way there. There are some copy/replace errors. This also needs tests.
I'm going to wrap this up tonight.
Comment #43
twistor CreditAttribution: twistor commentedAlright, here's a go at this.
Thanks to everyone for getting this started.
Comment #44
twistor CreditAttribution: twistor commentedArg, here's the code.
Comment #45
twistor CreditAttribution: twistor commentedConsistent function naming.
Update:
This changes the existing behavior. I am contradicting myself from above, but after some consideration I don't think many people were using map by tid, and this is still technically an alpha project, so better to just cut loose. This will still be compatible with the vast majority of existing installations.
Comment #46
twistor CreditAttribution: twistor commentedTagging
Comment #47
sin CreditAttribution: sin commentedIt would work for me. Autocreate option is good!
Found a typo in taxonomy_feeds_set_target() -- $cace vs $cache.
Comment #48
sin CreditAttribution: sin commentedFixed typo, tested with GUID option -- works for me, thanks!
Comment #49
ryumkin CreditAttribution: ryumkin commentedSubscribe
Comment #50
sin CreditAttribution: sin commentedRelated patch to Commerce Feeds #1840198: Add mapping by product GUID.
It has some code from here: select by feeds_item.guid too.
Comment #51
johnvPatch #48 gives the following error when importing something without taxonomies:
An AJAX HTTP error occurred. HTTP Result Code: 200 Debugging information follows. Path: /batch?id=977&op=do StatusText: OK ResponseText: Fatal error: Unsupported operand types in feeds\mappers\taxonomy.inc on line 94
Attached patch fixes that:
Comment #52
kovaski CreditAttribution: kovaski commentedSubscribe
Comment #53
David Hernández CreditAttribution: David Hernández commentedHi there,
I'm having the same issue and I didn't find the issue until I wrote a patch for it. My patch is way less complex and only changes a few lines instead of changing all the functionality of the mapper. What I did is changing the mapper. Before checkinf if it's numeric or a string, I check if the term exists. If so, I import it, if not, I check if it's a number or a string to do the current mapping.
The patch should work and the people will not need to select if they are importing term Data or term ID. But they will have a problem importing Term IDs if they also have taxonomy terms with numeric data.
I will leave my patch here just in case someone thinks it's useful.
Regards,
David.
Comment #54
m.stentaPatch in #51 works beautifully. Marking RTBC to indicate it's been reviewed. :-)
Comment #56
johnv@David, no offence, but your patch does the same as #1, and -as you state- still gives errors with numeric/mixed vocabularies.
I'm re-uploading #51, as test-bot apparantly takes the last posted patch, and approved by m.stenta.
Comment #57
westie CreditAttribution: westie commentedCan I make a suggestion from the UI / UX perspective. I think like how some items have a "target configuration", terms should have options for:
EDIT: ignore didnt look at latest patches
Comment #58
David Hernández CreditAttribution: David Hernández commented@Johnv, no ofense taken. I don't like my solution either, I leave it here because it's a quickly solution that can work for some people. At the end, my solution was to use a list field with all the options.
Comment #59
twistor CreditAttribution: twistor commentedAdded tests. Committed to 7.x-2.x. Thanks everybody.
Comment #60
Frando CreditAttribution: Frando commentedHere's a minimal / hackish patch to 6.x-1.x that just does a lookup on tid if the passed value is numeric.
I actually wanted to implement the patch as in #56, but then stumbled: Is it possible to implement configuration per mapping target in 6.x? There seems to be no form callback.
Comment #61
asutton CreditAttribution: asutton commentedI think I am having a related, but slightly different, issue importing taxonomy terms.
I am using feeds tamper to concatenate two fields (street name and street suffix, ie: 'Main' and 'St') and then save them as taxonomy terms (adding new terms if they do not exist)
The reason I think my issue is related is that when the street name is all letters, ie: Main St, it works perfectly. Hoewever, when the street name contains numbers, ie: 30th St, it adds a new term even if it already exists. So after importing about 15,000 content items, I had several thousand duplicate taxonomy terms, all with 'number' street names.
When I attempted to apply the patch above in #56 it appears the patch has already been applied. I am using Feeds 7.x-2.0-alpha8 and Feeds Tamper 7.x-1.0-beta4.
I have decided to not create taxonomy terms from imported street names, which makes things like making menus from taxonomy terms more difficult, but at least it is working. I wanted to submit this as a FYI as I think there is still an issue regarding importing taxonomy terms with numbers, with the patch above applied. Or perhaps this is a Feeds Tamper issue...
Comment #62
asutton CreditAttribution: asutton commentedNow I am having a similar issue without the use of taxonomy terms.
I am simply trying to use a contextual filter to query my views blocks via the url. When the filter value starts with a letter, it works. But when it starts with a number, it returns no content.
ie: Main St --- good!
7th St --- bad!
Any ideas why this would be? The data was originally imported with feeds into a text field.
I am really stumped so any help is greatly appreciated. Thanks.
Comment #63
asutton CreditAttribution: asutton commentedScratch the previous post. My problem is that for some reason the streets that start with a number have three spaces in front of it. When I add the spaces to the url, it works. Still not sure where spaces came from....
Comment #64
geek-merlinPlease everrrrybody do NOT hijack this issue, but post a new one.
Status of this:
* Committed to 7.x in #59
* 6.x patch for review in #60
Comment #65
geek-merlinEDIT: erroneous comment.
Comment #66
geek-merlinSorry for the noise.
Comment #67
geek-merlinCrosslinking #2139229: Taxonomy mapper creates empty and untrimmed terms which might be of interest for folks here.
Comment #68
twistor CreditAttribution: twistor as a volunteer commented