All pastes #542948 Raw Edit

Untitled

public text v1 · immutable
·published 2007-06-05 23:49 UTC
rendered paste body
Index: includes/menu.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/menu.inc,v
retrieving revision 1.176
diff -u -p -r1.176 menu.inc
--- includes/menu.inc   5 Jun 2007 12:13:20 -0000       1.176
+++ includes/menu.inc   5 Jun 2007 23:45:58 -0000
@@ -1227,6 +1227,10 @@ function _menu_navigation_links_rebuild(
     array_multisort($sort, SORT_NUMERIC, $menu_links);
 
     foreach ($menu_links as $item) {
+      $existing_mlid = db_result(db_query("SELECT mlid FROM {menu_links} WHERE menu_name = '%s' AND link_path = '%s' AND module = 'system'", $menu_name, $item['link_path']));
+      if ($existing_mlid) {
+        $item['mlid'] = $existing_mlid;
+      }
       menu_link_save($item);
     }
   }
@@ -1316,13 +1320,6 @@ function menu_link_save(&$item) {
   if (isset($item['mlid'])) {
     $existing_item = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE mlid = %d", $item['mlid']));
   }
-  else {
-    $existing_item = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE menu_name = '%s' AND link_path = '%s'", $menu_name, $item['link_path']));
-  }
-
-  if ($existing_item) {
-    $item['mlid'] = $existing_item['mlid'];
-  }
 
   // Find the parent - it must be in the same menu.
   if (isset($item['plid'])) {
@@ -1343,21 +1340,22 @@ function menu_link_save(&$item) {
   else {
     $item['plid'] = $parent['mlid'];
   }
-  db_query("INSERT INTO {menu_links} (
-    menu_name, plid, link_path,
-    hidden, external, has_children,
-    expanded, weight,
-    module, link_title, options) VALUES (
-    '%s', %d, '%s',
-    %d, %d, %d,
-    %d, %d,
-    '%s', '%s', '%s')",
-    $item['menu_name'], $item['plid'], $item['link_path'],
-    $item['hidden'], $item['_external'], $item['has_children'],
-    $item['expanded'], $item['weight'],
-    $item['module'],  $item['link_title'], serialize($item['options']));
-  $item['mlid'] = db_last_insert_id('menu_links', 'mlid');
-
+  if (!$existing_item) {
+    db_query("INSERT INTO {menu_links} (
+       menu_name, plid, link_path,
+      hidden, external, has_children,
+      expanded, weight,
+      module, link_title, options) VALUES (
+      '%s', %d, '%s',
+      %d, %d, %d,
+      %d, %d,
+      '%s', '%s', '%s')",
+      $item['menu_name'], $item['plid'], $item['link_path'],
+      $item['hidden'], $item['_external'], $item['has_children'],
+      $item['expanded'], $item['weight'],
+      $item['module'],  $item['link_title'], serialize($item['options']));
+    $item['mlid'] = db_last_insert_id('menu_links', 'mlid');
+  }
 
   if (!$item['plid']) {
     $item['p1'] = $item['mlid'];