Closed (fixed)
Project:
Feeds
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
4 Nov 2009 at 17:57 UTC
Updated:
22 Dec 2009 at 22:20 UTC
Jump to comment: Most recent file
Port the taxonomy mapper from Feed Element Mapper.
Port tests for it.
| Comment | File | Size | Author |
|---|---|---|---|
| #33 | 623424-33_taxonomy_mapper.patch | 10.23 KB | alex_b |
| #31 | 623424-31_taxonomy_mapper.patch | 3.53 KB | alex_b |
| #30 | 623424-30_taxonomy_mapper.patch | 3.27 KB | alex_b |
| #26 | 623424_feeds_taxonomy_mapper-d6-v04.patch | 3.46 KB | kars-t |
| #25 | 623424_feeds_taxonomy_mapper-d6-v03.patch | 3.29 KB | kars-t |
Comments
Comment #1
alex_b commentedPatch by Eugen Mayer from #618254-6: Port FeedAPI Mappers.
Comment #2
alex_b commentedGreat start
Overall:
- Throw an exception if vocabulary does not exist.
- I am not sure whether we want to require that the target vocabulary is tags. It's clearly a different behavior than what FEMP has right now. Either way - this does make the code simpler because we don't have to create the terms if they don't exist, correct?
Formatting issues:
- follow Drupal coding standards http://drupal.org/coding-standards - there are a series of problems
- add a $Id$ to the top of the file
- use cvsdo to add the file and roll a patch
- for TODO use @todo
- Start a comment with a capital letter and end it with a .
- make sure comments don't spill over 80 characters
- no $camelCase for variable names
Comment #3
alex_b commentedI'd love if we could get #623452: Port basic test infrastructure for mapper done before committing the taxonomy mapper.
Comment #4
geerlingguy commentedI would love to see some sort of taxonomy mapping on feed imports. Articles for stlouisreview.com are imported using FeedAPI, and when an article is imported, it is automatically assigned a main section term for sorting the article from one vocabulary, then is assigned free tags using another freetagging vocabulary.
That's what, I'm guessing this issue is about? Namely, when importing feed items into nodes, taxonomy terms can be mapped from the feed items to the node?
Comment #5
eugenmayer commentedyes geerlinguy
Its allready done and working, see the patch in #1.
Alex i will fix the coding styles and stuff.
About the "tags requirement", i guess you got it wrong. A Tax. / Vacab does not need to be a "tags" one, to work with the feed api.
The only point where tags and "non tags" vocabs are different in that mapper is:
- If the vocab is not a "tags" one, and the feed-entry has a term, which does not yet exist as a term in drupal it will NOT be created and NOT be attached to the feed-entry-node
- When its a tag, the term is auto-created and attached
But this is only for the terms which are not yet present in the drupal-vocab. All the others will work like you expect it.
Comment #6
geerlingguy commentedAh, good! Cool!
Comment #7
vitis commentedsubscribing
Comment #8
geerlingguy commentedJust wondering - has this patch been applied to HEAD yet? If not, can I safely apply the patch to my production site? I'd like to get this functionality working a.s.a.p., but can live without it for a while.
[Edit: For those interested in testing - grab the file in reply number 1 above, rename it taxonomy.inc, then place it inside the 'mappers' folder in your feeds module folder.]
Comment #9
david lesieur commentedI have not looked at the code but have tried #1. I'm able to specify vocabularies as targets in a node processor, but no term gets created and even when the terms already exists, no term-node association gets created.
Comment #10
nickbits commented@geerlingguy tried doing that but I do not seem to see any difference. I assume there should be a new option in the mapping section. Can you confirm where the change is seen?
Cheers,
Nick
Comment #11
geerlingguy commentedIf you go to site building > feeds > list, then edit the feed you're using, you can go to the 'Node processor' and then select a Source and Target - and for whatever node type you're using, you should see the taxonomies associated with that node type in the list, like "Taxonomy: Tags."
Comment #12
nickbits commentedHi,
I have just tried that and it doesn't seem to work for me. I have a taxonomy, just for testing it is associated with every node type. I have created a new feed type, but when I go to Node processor I do not see any TAXONOMY related name listed.
I can see category in the source but nothing in the destination/target. This may well be me doing something wrong. I can however see the taxonomy in any other page contant I have created.
Nick
Comment #13
nickbits commentedOkay, got it now, I ahd renamed it ,inc.php instead of just .inc.
Comment #14
geerlingguy commentedI'm able to verify: no terms are getting matched, even though the .inc file seems to allow me to at least make the initial mapping.
Comment #15
kars-t commentedAs I currently need this function I did a complete rewrite.
I did check the code with the coder module and rewrote anything to comply to the coding standards. Hopefully I did not forget something ;)
We now do have an error message if the vocabulary gone missing for any reason.
I unset any tags so we can do a clean refresh.
A "tags" vocab is added quiet easily. See taxonomy.module from line 654 to 686.
The adding of terms in a none tags vocab is quiet easy too. See taxonomy.module 688 to 704. By taxonomy_get_term_by_name_vid all terms of the current vocab that match are selected and added to the terms array of the node. I try to add any terms that are found. This is just for the strange case a vocab contains a the same tag more than once. Drupal can do this so I just add this. If the vocab is not for multiple tags we quit after we found the first tag.
This means if we want a feed to bring in any tags use a "tags" vocab. If you want to filter the tags a feed can use import into a "normal" vocab and maybe activate multiple tags. By this you can make sure only existing tags from a vocab will be used.
So far so good but there is a problem. taxonomy.module in line 693 needs a vid for the node. This of course is not the vocab id but the version id of the node! If nothing is set we can't update any tags because they always refer to vid 0.
I will look into this as I believe this is a problem of feeds in common. But I can't find the invocation of the hook right now. So I set this issue to "needs work". But initial import should work fine and maybe somebody can already test and review it.
@alex_b If you read this please tell me if I am missing something or if the $node->vid is not properly set. Feel free to contact me by email if this is better than using this issue as its basically off topic. :)
Comment #16
kars-t commentedThis now depends on #634886: Add vid to node proccess functions or the vid has to be added in this mapper.
Comment #17
eugenmayer commentedKarsT are you seriuos? Are you really making a complete rewrite, missing 50% of special cases and really think, this is the best approach? I mean, why not adjust or bugfix the code we had? Beside you reuse my code and talk about a completely rewrite..whatever. This is how you piss of people the big way.
Beside the mapper works perfectly, people have the wrong understanding what a "tag" taxonomy is, and what a normal taxonomy is (by theory). So thats why for some terms are not created... because its not a "tags" taxonomy.
The mapper works and is live for some weeks now.
This is NOT tested with content_taxomomy, but this is a completely different thing. You have to use the taxonomy module and the the vocab you want to use in the mapper, that this is assigned to the content_type XYZ. So before it works in the mapper, you must be able to add terms in the vocab when you edit / add this content type.
When it does, you will see the taxonomies for the mapping.
@geerlingguy: Can you please provide more informations:
- What kind of vocab?
- Are there Tags in the Feed, what is the format of those?(are there terms passed to the mapping, so are terms actually correctly extracted)
!This module does not extract the terms!. So ther terms must be in an array in the feed-item, if they are not, they are not matched
!This module does not analyze the content of the feed and creates tags! This is not the extractor module!
This modules adds terms which ARE assosiated(so existing ones) with the feed to the node.
Alex would you clear things out here so its clear on which code base we will work, so i know i need to fix anything here. I was away for a week and could not follow this due that.
Comment #18
kars-t commentedHi Eugen I never ment to piss you of. I send you a PM about this. :)
Comment #19
geerlingguy commentedThanks for the detailed post - the terms in the feed are all pre-existing terms in my 'Section' vocabulary. It's not a 'Tags' type vocabulary, but is 'Multiple select' and 'Required.'
In the feed, they are inside the 'category' tag (separate from the 'content' tag) inside a feed item:
<category term="local news" start="2009-11-16T12:36:08" end="2010-02-24"><![CDATA[local news]]></category>Are you saying (it seems so, but I think I'm confused) that this mapper will only work with 'tag' type vocabs—i.e. vocabularies with the 'Tags' checkbox checked on the Edit vocabulary page?
Comment #20
eugenmayer commentedWell cleared things up with Kars-T. Sorry for maybe heating stuff up a little, maybe its just my overall frustration about the contribution-procedure in Drupal in general.
Kars-T`s implementation fixes 2 bugs introduced in my version and its better to read. I hope he adds the patch for removing the "unset()" part, due it will produce problems with extractor.
So the first version should be removed or ignored in this thread, further patches (or rewrites :) ) should be done by a patch against 623424_feeds_taxonomy_mapper-d6-v01.patch or the newer one.
In general will need some unit-tests, as the taxonomy implementation and "API" is quite hard to cope with, so we need to get through all cases:
1. All new terms ( not a single exists ) and vocab is NOT a "tags" one -> dont create and dont assign terms
2. All new terms ( not a single exists ) and vocab is a "tags" one -> create and assgin all terms
3. All existing terms and vocab is a NOT "tags" one -> assgin all terms ( no creation)
4. All existing terms and vocab is a "tags" one -> assgin all terms ( no creation)
5. No terms at all and vocab is a NOT "tags" one -> no terms are assigned. What about the current ones
6. No terms at all and vocab is a "tags" one -> no terms are assigned. What about the current ones
7. New terms and existing terms and vocab is NOT a "tags" one-> assign the existing terms, drop the new terms
8. New terms and existing terms and vocab is a "tags" one-> assign the existing terms AND assign / create the new terms
For everbody looking at the code or writing test please be awared, that the way "tags" and normal terms are processed by the taxonomy api is different. Tags are processed as a comma-seperated list and splitted up later in the deeper code-space of taxonomy while NOT "tags" are processed as an array or object of terms.
Comment #21
eugenmayer commented@geerlingguy: there are 2 bugs in my code, so actually it should not work. I have refactored the code and there are to vars which have not been renamed..plus one special case does not get handled. So please use the version created by Kars-T with the patch he will provide.
Comment #22
kars-t commentedNew version of the patch to include the suggestions Eugen made :)
I did remove the taxonomy reset because Eugen pointed out that it would destroy any terms that where added by other mapping modules for example a scraper.
And the variabable "$vid" was renamed to "vocab_id" so its clear its _not_ the "version_id" of a node.
Comment #23
geerlingguy commentedCool - I'll test Kars-T's latest patch to see if that sorts the terms.
Comment #24
bcobin commentedsubscribing
Comment #25
kars-t commentedNew version with the paths relative to the feeds directory. I really hope I didn't mess this up again. I had fights over this with the testing bot for days till I figured it out ;)
Comment #26
kars-t commentedI just had the case that I wanted to import a single field from a feed into a taxonomy e.g. Author Name so I can easily aggregate over them. But this won't succeed as my parser gave a string to the function and we only accept arrays.
I did change the checks a bit.
Two things:
I don't know if I should add some sanatiy checks like trim and a max lenght?
And what if the parser gives an object? Should this be handled as well?
Comment #27
alex_b commented#27:
1 Sanity checks only necessary if they prevent breakage.
2 You don't need to expect objects.
Comment #28
mcaudy commentedsubscribing
Comment #29
alex_b commentedFYI - thanks to mongolito404 #623452: Port basic test infrastructure for mapper landed. There's nothing in the way between taxonomy mapper and tests anymore ...
[edit: setting to NW because of missing tests]
Comment #30
alex_b commentedFix patch format.
Comment #31
alex_b commentedGave this another hard look and tested it various ways. This is RTBC with exception of the tests now.
2 minor changes:
- Remove check for vid and watchdog message. It is very unlikely that the vid does not exist as Feeds invokes hook_feeds_node_processor_targets_alter() right before invoking the callback (read FeedsProcessor::map()). If we *did* want to do the check, the right way to react to a negative would be to throw an exception. But as I said, I think it's fine to assume that $vocab_id is valid.
- Improved description.
Comment #32
alex_b commentedWriting some tests now.
Comment #33
alex_b commentedI added tests now. Posting this patch for the record, will commit later.
[Edit: I had to change the $targets key from the vocabulary id to "taxonomy:[vid]" because there could be other modules providing a numeric mapping target.]
Comment #34
alex_b commentedCommitted. Thank you everybody.
http://drupal.org/cvs?commit=298208
Comment #35
alex_b commentedComment #36
geerlingguy commentedSweet!
Comment #37
kars-t commentedGreat thanks an lot! :D
Comment #38
summit commentedSubscribing, waiting for alpha9 with mapper. Great progression, thanks!
Greetings, Martijn