Hi,
taxnomy_nodeapi calls taxonomy_node_save on insert and update. This function, in turn, saves the taxonomy of the node. Unfortunately it first deletes all terms for the current node, and then inserts them again if they have been loaded before. taxonomy_nodeapi doesn't respond to 'load'. Therefore, unless you've done something like $node->taxonomy = taxonomy_node_get_terms($node) the terms are lost.
See: http://drupaldocs.org/api/head/function/taxonomy_node_save
Solution: move the call to taxonomy_node_delete($nid) inside the if (is_array($terms)). When the terms haven't been loaded they won't be saved either.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | taxonomy-save.patch | 471 bytes | wiz-1 |
Comments
Comment #1
wiz-1 commentedOops, forgot the patch
Comment #2
junyor commentedDon't forget to change the status to patch when you upload a patch. :)
Comment #3
wiz-1 commentedAll right, but moshe weitzman told me not to do this right away:
I assume that you have thoroughly tested the patch before changing status ;)
Comment #4
junyor commentedFair enough. But then you should ask for people to test it. ;)
Comment #5
moshe weitzman commentedA patch for this issue is welcome. I think though that this fix is part of the upcoming folksonomy changes by Morbus ... the fix proposed here might have problems if the user wants to remove all terms on an existing node. not sure.
If you have authored and tested a patch yourself, it is OK to set to patch status. I just object to people moving the testing burden to the CVS reviewers.
Comment #6
morbus iffWell, I plan on redoing the delete code at some point, it is not in my folksonomy patch.
Comment #7
morbus iff+1 from me. I've run across this a few times too.
Comment #8
morbus iffComment #9
morbus iffActually, -1. I have some concerns.
One of my case scenarios was:
* node has a bunch of terms.
* user edits node, deletes all terms.
* ->taxonomy becomes blank. does the delete occur?
The delete DOES occur, but ONLY because ->taxonomy becomes an empty array. It's may be too easy for a third party module to forget to pass an empty array, which would cause the is_array() check to fail, which would cause the delete() never to happen. And, well, this patch would break my upcoming folksonomy patch :)
My understanding is that this hiccup (->taxonomy isn't loaded, delete happens erroneously) would only occur on third party modules or import scripts, and doesn't happen anywhere in core. As such, a low priority, but one that should still be eventually addressed.
Comment #10
killes@www.drop.org commentedFunctions calling node_save should make sure to first load taxo terms. The taxonomy module needs soem love though the code started smelling some time ago. Luckily Morbus might be doing that.
Comment #11
wiz-1 commentedI'm not sure I can agree with the last followup. It is plainly wrong that the code node_load($nid); node_save($nid); will delete all taxonomy terms of the node, especially as this is not documented anywhere AFAIK. This problem may not be triggered by any core modules, but for people like me who develop their own modules it's a bug or at least an annoyance...