Duplicate Menus After Upgrading to Drupal 6
rgraves - May 25, 2009 - 16:50
I have a site running Drupal 5. I upgraded to Drupal 6 and ran update.php. Now when I go to my site, I have multiple menus and menu items across my site. For example, there are 4 "Log out" links on my sidebar. We have lots of menus for different sections of our site, so this problem is huge.
Does anyone know why this has happened and how to prevent it? I have some custom menu modules (menu per role and menu subtree permissions) but they are not enabled yet. This problem occurred right after upgrading Drupal core.

=-=
similar threads = http://www.google.com/search?hl=en&ei=HDIbSsOkIInQMqKB6ZQP&sa=X&oi=spell...
I haven't had too much luck
I haven't had too much luck finding a suitable solution to fix this annoying problem. So here's what I thought I'd do:
Grab the menu_name field from the menu_custom table. I can easily tell which menus are duplicated based on that (they have -0, -1, -2) appended to them.
Delete all entries in the menu_custom table where the menu_name is equal to one of those duplicate menu names. Do the same for the menu_links table.
Will that work without causing any headaches? I'm not sure how the menu_router table fits in all this.
I haven't written much PHP in
I haven't written much PHP in ages, so here's what I knocked out in Python in a couple of minutes to get rid of all the duplicate links I found when upgrading from D5 to D6. I'm too lazy and dumb to delete these by hand without making a lot of mistakes.
import MySQLdb
conn = MySQLdb.connect(host='...', user='...', db='...', passwd='...')
curs = conn.cursor()
curs.execute('select mlid,link_path from menu_links')
# Get lists of all duplicate menu items
paths = {}
for row in curs:
paths.setdefault(row[1], []).append(row[0])
# Only look at paths with more than one mlid
pathlist = [(linkpath, mlids) for linkpath, mlids in paths.items() if len(mlids) > 1]
for path in pathlist:
# Sort the mlids, then delete all after the first one
for mlid in sorted(path[1])[1:]:
curs.execute('delete from menu_links where mlid=%s', (mlid,))
Don't forget to delete everything from cache_menu when you're done! And for Pete's sake, don't run code containing "delete from" that you got from some random stranger on the Internet without making a backup first. Like I said, I'm dumb. Don't nuke your database just because I said it would be a good idea.