in the "taxonomy_menu_node_presave($node)" function, the terms_old variable is not properly set. it should be the previous term set in the node, but actually, it's the new one, just because the $node var in the function is allready the new node.

A good way to fix it, it's just to load again the node from the database, with a simple node_load(). So the function could be :

/**
 * Implementation of hook_node_presave().
 */
function taxonomy_menu_node_presave($node) {
  $terms_old = &drupal_static('taxonomy_menu_terms_old');
  //get the terms from the database before the changes are made.
  //these will be used to update the menu item's name if needed
  //we go directly to the db to bypass any caches
  $node_old = node_load($node->nid);
  $terms_old = _taxonomy_menu_get_node_terms($node_old);
}

Fix this function will fix menu not disappear in the menu_taxonomy tree after node update. If the term has no node, it actually stays in the menu, resulting of an empty taxonomy page (issue http://drupal.org/node/1403332).

Comments

VivienLetang’s picture

Here is the patch.

johnv’s picture

Status: Needs review » Reviewed & tested by the community

This patch works for me.
When a node was moved from term A to term B, the node count of term B is updated, but node count of term A stayed the same.

VivienLetang’s picture

Title: taxonomy_menu_node_presave($node) - terms_old error » Node count not correct when moving node in hierarchy from A to B (count of A is not updated).
Status: Needs work » Reviewed & tested by the community

So it's a new issue i think. The first was "Fix this function will fix menu not disappear in the menu_taxonomy tree after node update." and the new one is that the count is not updated.

Don't really know where this count should be updated, but i will look at this this week.

Thanks

johnv’s picture

VivienLetang,
in -dev version, you'll find the option 'count nodes of taxonomy term'. This shows e.g. "term1 (4)" for a term with 4 nodes.

barrett’s picture

Status: Reviewed & tested by the community » Needs work

I get an exception running the module's tests after applying the patch in comment 1 to the latest 7.x-1.x code base.

Undefined property: stdClass::$nid Notice taxonomy_menu.module 411 taxonomy_menu_node_presave()

barrett’s picture

Status: Needs work » Needs review
StatusFileSize
new653 bytes

The attached patch modifies the one posted in comment 1 to test that a $nid is set before trying to load a node with the matching nid. This corrects the exception reported when running the tests discussed in comment 5.

dstol’s picture

Status: Reviewed & tested by the community » Fixed
VivienLetang’s picture

thx and nice work ;)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

johnv’s picture

Marked the D6-version of this request #999858: parent menu items do not get synchronized as a duplicate.

johnv’s picture

Issue summary: View changes

fix code tag