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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tomcant’s picture

Version: 6.19 » 6.20

Realised this is still an issue for 6.20. Updated.

hefox’s picture

Version: 6.20 » 6.x-dev
Status: Active » Needs review
FileSize
449 bytes

such 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.

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.