diff includes/menu.inc @ 11:589fb7c02327 6.5

Drupal 6.5
author Franck Deroche <webmaster@defr.org>
date Tue, 23 Dec 2008 14:32:19 +0100
parents fff6d4c8c043
children 8b6c45761e01
line wrap: on
line diff
--- a/includes/menu.inc	Tue Dec 23 14:32:08 2008 +0100
+++ b/includes/menu.inc	Tue Dec 23 14:32:19 2008 +0100
@@ -1,5 +1,5 @@
 <?php
-// $Id: menu.inc,v 1.255.2.17 2008/07/09 15:23:50 goba Exp $
+// $Id: menu.inc,v 1.255.2.21 2008/10/08 12:33:55 goba Exp $
 
 /**
  * @file
@@ -335,7 +335,9 @@
   if (_menu_site_is_offline()) {
     return MENU_SITE_OFFLINE;
   }
-  if (variable_get('menu_rebuild_needed', FALSE)) {
+  // Rebuild if we know it's needed, or if the menu masks are missing which
+  // occurs rarely, likely due to a race condition of multiple rebuilds.
+  if (variable_get('menu_rebuild_needed', FALSE) || !variable_get('menu_masks', array())) {
     menu_rebuild();
   }
   if ($router_item = menu_get_item($path)) {
@@ -362,7 +364,7 @@
  * @return
  *   Returns TRUE for success, FALSE if an object cannot be loaded.
  *   Names of object loading functions are placed in $item['load_functions'].
- *   Loaded objects are placed in $map[]; keys are the same as keys in the 
+ *   Loaded objects are placed in $map[]; keys are the same as keys in the
  *   $item['load_functions'] array.
  *   $item['access'] is set to FALSE if an object cannot be loaded.
  */
@@ -471,10 +473,10 @@
  * @return
  *   No return value.
  *   $item['title'] is localized according to $item['title_callback'].
- *   If an item's callback is check_plain(), $item['options']['html'] becomes 
+ *   If an item's callback is check_plain(), $item['options']['html'] becomes
  *   TRUE.
  *   $item['description'] is translated using t().
- *   When doing link translation and the $item['options']['attributes']['title'] 
+ *   When doing link translation and the $item['options']['attributes']['title']
  *   (link title attribute) matches the description, it is translated as well.
  */
 function _menu_item_localize(&$item, $map, $link_translate = FALSE) {
@@ -657,14 +659,14 @@
       _menu_item_localize($item, $map, TRUE);
     }
   }
-  
+
   // Allow other customizations - e.g. adding a page-specific query string to the
   // options array. For performance reasons we only invoke this hook if the link
   // has the 'alter' flag set in the options array.
   if (!empty($item['options']['alter'])) {
     drupal_alter('translated_menu_link', $item, $map);
   }
-  
+
   return $map;
 }
 
@@ -1159,6 +1161,10 @@
 function menu_get_active_help() {
   $output = '';
   $router_path = menu_tab_root_path();
+  // We will always have a path unless we are on a 403 or 404.
+  if (!$router_path) {
+    return '';
+  }
 
   $arg = drupal_help_arg(arg(NULL));
   $empty_arg = drupal_help_arg();
@@ -1557,7 +1563,7 @@
  */
 function menu_get_active_breadcrumb() {
   $breadcrumb = array();
-  
+
   // No breadcrumb for the front page.
   if (drupal_is_front_page()) {
     return $breadcrumb;
@@ -1735,8 +1741,11 @@
       $existing_item = db_fetch_array(db_query("SELECT mlid, menu_name, plid, customized, has_children, updated FROM {menu_links} WHERE link_path = '%s' AND module = '%s'", $item['link_path'], 'system'));
       if ($existing_item) {
         $item['mlid'] = $existing_item['mlid'];
-        $item['menu_name'] = $existing_item['menu_name'];
-        $item['plid'] = $existing_item['plid'];
+        // A change in hook_menu may move the link to a different menu
+        if (empty($item['menu_name']) || ($item['menu_name'] == $existing_item['menu_name'])) {
+          $item['menu_name'] = $existing_item['menu_name'];
+          $item['plid'] = $existing_item['plid'];
+        }
         $item['has_children'] = $existing_item['has_children'];
         $item['updated'] = $existing_item['updated'];
       }
@@ -1828,6 +1837,9 @@
  *   - mlid        Set to an existing value, or 0 or NULL to insert a new link.
  *   - plid        The mlid of the parent.
  *   - router_path The path of the relevant router item.
+ * @return
+ *   The mlid of the saved menu link, or FALSE if the menu link could not be 
+ *   saved.
  */
 function menu_link_save(&$item) {
   $menu = menu_router_build();
@@ -2060,7 +2072,10 @@
       break;
     case 'update':
       db_query("UPDATE {menu_links} SET link_title = '%s' WHERE link_path = '%s' AND customized = 0 AND module = '%s'", $link_title, $link_path, $module);
-      menu_cache_clear();
+      $result = db_query("SELECT menu_name FROM {menu_links} WHERE link_path = '%s' AND customized = 0 AND module = '%s'", $link_path, $module);
+      while ($item = db_fetch_array($result)) {
+        menu_cache_clear($item['menu_name']);
+      }
       break;
     case 'delete':
       menu_link_delete(NULL, $link_path);