From 62dcbc91fdebd0a60fe2c217a2f96f5d57142c8a Mon Sep 17 00:00:00 2001
From: Elvis Pranskevichus <el@prans.net>
Date: Thu, 15 Oct 2009 18:38:09 -0400
Subject: [PATCH] Fix a number of bugs that led to a horrible menu corruption

Taxonomy Menu tries to keep the menu in sync, and when the 'Hide Empty
terms' feature is set, it tracks all node changes and updates the menu
links.  The deletion hook, however, was horribly broken.  The menu_link
entry was being deleted, but the taxonomy_menu entry was not, which led
to a confusion if the menu link existed or not.  This triggered
duplicate menu item creation on all further node updates that had that
term in their taxonomy.

Frankly speaking, this whole 'update link/delete link/recreate link'
business on EACH node operation is quite dubious.  Fixing that is the
subject of further patches, though.
---
 taxonomy_menu.module |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/taxonomy_menu.module b/taxonomy_menu.module
index c4cff0e..a73e19f 100755
--- a/taxonomy_menu.module
+++ b/taxonomy_menu.module
@@ -387,9 +387,17 @@ function _taxonomy_menu_nodeadpi_helper($op, $terms = array()) {
 
         case 'delete':
           $args = array(
+            'term' => $term,
             'tid' => $term->tid,
+            'vid' => $term->vid,
+            'menu_name' => $menu_name,
             'mlid' => _taxonomy_menu_get_mlid($term->tid, $term->vid),
           );
+          /* Turn the op to 'update' here since we really do want to update the item
+           * and not delete/recreate it, since the latter will break hierarchy and
+           * customizations.
+           */
+          $op = 'update';
       }
       taxonomy_menu_handler($op, $args);
     }
@@ -616,10 +624,11 @@ function taxonomy_menu_path_default($vid, $tid) {
  *  )
  *
  */
-function taxonomy_menu_taxonomy_menu_delete($args = array()) {
-  menu_link_delete($args['mlid']);
-  _taxonomy_menu_delete_item($args['vid'], $args['tid']);
-  return $args;
+function taxonomy_menu_taxonomy_menu_delete(&$item) {
+  menu_link_delete($item['mlid']);
+  _taxonomy_menu_delete_item($item['vid'], $item['tid']);
+  unset($item['mlid']);
+  return $item;
 }
 
 /**
-- 
1.6.5.rc2

