Index: includes/menu.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/menu.inc,v
retrieving revision 1.107
diff -u -F^f -r1.107 menu.inc
--- includes/menu.inc	14 Feb 2006 19:19:34 -0000	1.107
+++ includes/menu.inc	8 Mar 2006 21:41:18 -0000
@@ -584,29 +584,23 @@ function menu_rebuild() {
   if (module_exist('menu')) {
     $menu = menu_get_menu();
 
+    // Fill a queue of new menu items which are modifiable.
     $new_items = array();
     foreach ($menu['items'] as $mid => $item) {
       if ($mid < 0 && ($item['type'] & MENU_MODIFIABLE_BY_ADMIN)) {
-        if (isset($new_items[$item['pid']])) {
-          $new_pid = $new_items[$item['pid']]['mid'];
-        }
-        else {
-          $new_pid = $item['pid'];
-        }
-
-        $new_items[$mid] = array(
-          'pid' => $new_pid,
-          'path' => $item['path'],
-          'title' => $item['title'],
-          'description' => isset($item['description']) ? $item['description'] : '',
-          'weight' => $item['weight'],
-          'type' => $item['type'],
-        );
+        $new_items[$mid] = $item;
       }
     }
 
-    if (count($new_items)) {
-      foreach ($new_items as $item) {
+    reset($new_items);
+    while (list($old_mid, $item) = each($new_items)) {
+      if ($item['pid'] < 0 && isset($new_items[$item['pid']])) {
+        // The item's parent has a temporary ID and is still in the queue. Put
+        // the item at the back of the queue so it may be saved after the
+        // parent item has recieved a new ID.
+        $new_items[$old_mid] = $item;
+      }
+      else {
         // The new menu ID gets passed back by reference as $item['mid']
         menu_save_item($item);
 
