Download & Extend

Problem with reverting revisions

Project:Auto Menu
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

Everytime I revert a revision I get an extra menu, does anyone know a way how to detect reverting revisions in hook_nodeapi? Or is there an easy way to detect if a menu item already exists?

Comments

#1

Work-around, can someone have a look, if OK I'll make a patch

function automenu_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'insert':
    case 'update':
      $parent_menu = explode(":", variable_get('parentmenu' . $node->language . '_' . $node->type, '0'));
      if ($parent_menu[0] != '0') {
        if (($node->menu['link_title'] == '' || $node->menu['delete']) && $node->status == 1) {
          if (!menu_get_item('node/' . $node->nid)) {                                                    // <-- Look here
            $new_menu = array(
              'link_path' => 'node/' . $node->nid,
              'link_title' => $node->title,
              'plid' => $parent_menu[1],
              //'customized' => true, // ?
            );
            if (!menu_link_save($new_menu)) {
              drupal_set_message(t('There was an error saving the auto-menu link.'), 'error');
            }
            else {
              drupal_set_message(t('The page was automatically added to: !menu.', array('!menu' => $parent_menu[0])));
            }
          }
        }
      }
      break;
  }
}