Let N
be a node associated with terms given by tids t1
and t2
. The internal taxonomy array for N
may look like: array (t1, t2)
. Associating N
with a third term given by tid t3
is a simple process of loading the node, adding t3
to the internal taxonomy array, and saving the node. Therefore, you would expect that the process of disassociating N
from all terms might be: load the node, set it's internal taxonomy array to the empty array, and save the node. Unfortunately, this seemingly sane methodology is flawed due to a poor assumption made in file `taxonomy.module'. Consider the following snippet:
/**
* Implementation of hook_nodeapi().
*/
function taxonomy_nodeapi($node, $op, $arg = 0) {
switch ($op) {
...
case 'update':
if (!empty($node->taxonomy)) {
taxonomy_node_save($node, $node->taxonomy);
}
break;
...
}
}
The culprit lies on line 1212: if (!empty($node->taxonomy)) {
. So we only save/modify the terms if the array is not empty, hence if the array is empty nothing happens. My proposed fix would be to replace line 1212 with:
if (isset($node->taxonomy)) {
which will cause the taxonomy module to invoke taxonomy_node_save()
even when the internal taxonomy array is empty.
Tom
Comment | File | Size | Author |
---|---|---|---|
#2 | drupal_taxonomy_node_save_update-1138672-2.patch | 449 bytes | hefox |
Comments
Comment #1
tomcant CreditAttribution: tomcant commentedRealised this is still an issue for 6.20. Updated.
Comment #2
hefox CreditAttribution: hefox commentedsuch a simple bug o.O Saw it while browsing the code, suprissed it hasn't been addressed or that more people haven't encountered it.
Note: I first did $node->taxonomy($node, isset($node->taxonomy) ? $node->taxonomy : array()); and removed the if () part, but decided was most likely that if the taxonomy field was unset, than the node type didn't have terms to begin with and this would add an unneeded delete during update.