Should menu_node_node_update look like this :

function menu_node_node_update($node) {
  if (!empty($node->menu_node_links)) {
    foreach ($node->menu_node_links as $link) {
      menu_node_record_save($node, $link, 'update');
    }
  }
}

I changed it to call menu_node_record_save instead of _menu_node_invoke. What is happening in my case is that we have been editing existing menu items that used to point to taxonomy terms to point to nodes instead. With the code change above, the appropriate entry gets added to the menu_node table the next time the node is updated.

I also updated menu_node_menu_link_update to look like this:

function menu_node_menu_link_update($link) {
  $node = NULL;
  
  if(strstr($link['link_path'],'node/')){
    $nid = str_replace("node/","",$link['link_path']);
    $node = node_load($nid);
  }
  
  if ($node) {
    menu_node_record_save($node, $link);
  }
  else{
    //make sure record with mlid is removed as it no longer points to a node
    db_delete('menu_node')
      ->condition('mlid', $link['mlid'])
      ->execute();
  }
}

That way it is sure to remove links from the table if they no longer point to a node.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

agentrickard’s picture

This issue needs:

* Steps to replicate the error.
* A proper patch. (http://drupal.org/patch/create)

agentrickard’s picture

Status: Active » Postponed (maintainer needs more info)
ryan.wyse’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
980 bytes

I ran into a similar issue here. I had created dummy menu items that pointed to . Since these weren't nodes the module didn't create an entry in the menu_node table. Then when I went to update the menu items to point to their correct node locations this module didn't have any records to update, so it didn't do anything. To fix this I just added an else, so if there isn't a record to update the module attempts to create a new record.

Status: Needs review » Needs work

The last submitted patch, 0001-Added-hook_menu_insert-code-to-hook_menu_update-code.patch, failed testing.

gabriel.achille’s picture

Status: Needs work » Needs review
FileSize
973 bytes

patch re-packaged
I added a hook_update to synchronize database.

gabriel.achille’s picture

Title: Node Updates Not Synchronized Properly » Menu link Updates Not Synchronized Properly
FileSize
1.12 KB

Actually: previous patch didn't address the problem raised by ablondeau. ablondeau approch seems more completed. So this patch is based on his suggestion instead. However I did not include the first part (change in menu_node_node_update function) because it seems unnecessary.
For those who are already running dev version + patch #5 of the module: disable/enable the module to synchronize the menu_node table.

gabriel.achille’s picture

fix: previous patch didn't filter properly all possible internal menu paths (did not make distinction between "node/123" and "node/add/article"). Causing some sql exception (...)

bdimaggio’s picture

#7 took care of the problem for me. Thanks gabriel.achille!

agentrickard’s picture

Status: Needs review » Needs work

Better to fix menu_node_get_node() than add the ugly IF statement here. There is a reason to abstract that lookup.

gabriel.achille’s picture

Status: Needs work » Needs review
FileSize
849 bytes

Indeed my If statement was ugly.
I changed that.
However because one case in the "If" involved calling menu_node_record_delete I'm reluctant to include that menu_node_get_node... Now menu_node_menu_link_update is a kind of combination of code in menu_node_menu_link_insert and menu_node_menu_link_delete which make sense.
What do you think ?

agentrickard’s picture

Looks pretty good. Can we be sure that $link['link_path'] is canonical (e.g. node/6) and not an alias?

gabriel.achille’s picture

I'd say yes we can, we've already made this assumption in menu_node_menu_link_insert() which is very similar. And the api.drupal documentation for hook_menu_link_update says that the associative array $link is defining a menu link as passed into menu_link_save() ie with $link['link_path'] normalized (e.g. node/6).

agentrickard’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. Thanks.

This module really needs a new maintainer, though, as I never use it.

mexicoder’s picture

I realise the status of this module is seeking a new maintainer but wondered about possibility of a release incorporating the patch from #10?

gabriel.achille’s picture

I'm quiet confident with my last patch: i'm using it in 2 relatively big sites but agentrickard has been quiet busy recently.
@agentrickard: as we discuss earlier i'm ready to help! :)

mexicoder’s picture

Hi gabriel.achille yes I am using the patch and it all seems to be working fine and is stable. That's why I posted -would be great to have it moved into a full release when time allows.

agentrickard’s picture

@gabriel.achille

You have commit access and can roll releases. https://drupal.org/node/457420/maintainers

gabriel.achille’s picture

Thanks agentrickard!
Here is the patch i'm actually planing to commit: i added back the hook_update_N from earlier patches to synchronize the menu_node table. It's necessary to fix properly the possibly existing incorrect records...

gabriel.achille’s picture

Status: Reviewed & tested by the community » Fixed

commited !

mexicoder’s picture

Great thanks guys

agentrickard’s picture

I think the menu_node_disable() call in the update hook is not necessary, actually.

gabriel.achille’s picture

In my view, i would keep the call to menu_node_disable(): it is necessary to make sure we delete wrong records in menu_node table. Previous version of the module didn't delete records for example when editor was changing a menu link (admin/structure/menu/item/[mlid]/edit) from the path node/[nid] to a NON node path (like <front>) the record in menu_node table wasn't delete.

agentrickard’s picture

Cool.

Status: Fixed » Closed (fixed)

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