Hello,
Thanks for the module. It has given me a good head start on another module that I am making.

I did however discover a bug in your code that needs to be addressed.

		for ($depth = 1; $depth < 10; $depth++) {
			$new_mlids = array();
			$next_depth = $depth + 1;
			foreach ($menu as &$mi) {
				// Save the items at this depth
				if ($mi['depth'] === $depth) {
					$mi['old_mlid'] = $mi['mlid'];
					$mi['menu_name'] = $menu_name;
					unset($mi['mlid']);
					menu_link_save($mi);
					$new_mlids[$mi['old_mlid']] = $mi['mlid'];
				}
				elseif ($mi['depth'] === $next_depth) {
					// Update plids on next level of items
					$mi['plid'] = $new_mlids[$mi['plid']];
				}
			}

This piece of code from line 46 assumes that the menu items are ordered by depth. Your db query on line 34 does not do this, instead they are returned in the order that they were created in the db. This messes up the cloned menu structure unless the menu items just happened to be created in the correct order.

My suggestion is to change the db_query on line 34 to this:

$rez = db_query('SELECT mlid FROM {menu_links} WHERE menu_name = "%s" ORDER BY depth', array($form_state['values']['parent']));

Hope this helps.

Comments

Garrett Albright’s picture

Status: Active » Needs review

Okay, I just submitted an update which implements this. Once the robots have packaged it, please give it a try if you can.

perandre’s picture

The dev version (May 09) did not work, but the lates in CVS worked fine. Great work! Sorry to see it abandoned.

malc0mn’s picture

Assigned: Unassigned » malc0mn
Status: Needs review » Fixed

perandre: the current version is a full rewrite of the original module in which this issue is also properly addressed. Menu items are saved to the DB in the same order as the menu is built up, just as the Drupal core Menu module handles this.

perandre’s picture

Well done! Looking forward to test.

Status: Fixed » Closed (fixed)

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