To reproduce:
1. Start with a Drupal 5 site.
2. Go to admin/build/menu/settings and set the "Menu containing primary links" to be Navigation.
3. Upgrade to Drupal 6.

The result is that the Primary Links and Navigation menus get completely messed up:
1. "My account" and "My blog" wind up in the Navigation menu, but everything else ("Administer", "Logout", etc) winds up under Primary Links.
2. Menu items that were introduced in Drupal 6 (e.g., "Actions", "Permissions", "Reports") wind up in Navigation by themselves -- they do not appear as children of "Administer". Consequently, these menu items don't show up on the main administration page (admin).
3. The menu listing at admin/build/menu also has problems. The Secondary Links menu is now titled "Primary links" (or, alternatively, if in Drupal 5 you had set "Menu containing secondary links" to Navigation as well, then you wind up with two separate Primary Links menus, one of which is empty).

I would say this counts as "critical" given the amount of chaos which gets created and the fact that an average Drupal site admin would probably have no idea how to restore their menus to the way they're supposed to be. I have no idea how to fix it at the moment, but I'll try to look at it more if I get time over the weekend...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chx’s picture

Is this for real? Setting primary links to Navigation?? What's the point??

webchick’s picture

Possible use cases:

1. One might have one of those JS menu modules like Nice Menus or Admin Menu that collapse the navigation down so that it's not spiraling out of control. :)
2. One might've already re-ordered/added/disabled things as they want in the Navigation menu, and are using the "drill down" functionality that happens when both primary and secondary are set to the same menu.

Can you please upload a dump of your D5 menu table for testing purposes? So far this is the first report we've received of data munging due to the upgrade since before RC1.

David_Rothstein’s picture

I can upload a menu dump if you really want, but this is literally reproducible from a fresh Drupal 5 installation:
1. Install Drupal 5.
2. Create user/1.
3. Change "menu containing primary links" to Navigation.
4. Upgrade to Drupal 6.

That's it. (Of course, I originally discovered this while test-upgrading a more complicated site, but then I went back and tried to isolate the problem and the above steps were all that were necessary.)

And yeah, I think there are all sorts of use cases for setting primary links to Navigation..... taking advantage of the "drill down" feature (as webchick mentioned) is one... also, a lot of themes (for example, Garland) put the primary links on the top right corner of the screen, and for UI reasons the top right corner is often a good place to put things like "logout" and "my account" (at least in my opinion), so sometimes it's just a natural fit. Unfortunately, in this case ;)

Please let me know if I can do anything else to help.

webernet’s picture

I can reproduce most of the original issue by setting "Menu containing primary links" to Navigation, and then performing an update. The administration menu is spread between primary links and navigation, and there are no 'reset' links...

Maybe do something like the following in the update code?

if ("Menu containing primary links" == Navigation) {
  primary links = new empty menu;
  navigation = navigation; 
}

Same for secondary links.

David_Rothstein’s picture

Also, I did a bit more testing, and it looks like something similar to the third bug I listed above (the duplicate listing at admin/build/menu) happens for other cases too. If you set your primary links in Drupal 5 to be some custom menu (for example, let's say it's called "Custom"), then on the Drupal 6 admin screen your primary links menu will be titled "Custom" while your secondary links menu will be given the title "Primary links"...

NancyDru’s picture

Actually, I've heard of several people setting Primary Links to Navigation (secondary too). I was given that advice a long time ago when I was first starting out. I don't do it any more though.

Even without that, I saw problem #2 on my first upgrade (beta3?), but not since then.

pwolanin’s picture

I though a bug fix went in that might make this a little better - but this is indeed kind of a mess. Since we have (mostly) decoupled router items and links, and since being able to move items form under /admin and thus have them NOT show up on the administration apge was considered an inportant feature, I'm not sure how to resolve this without some substantial rewriting.

I think I'd agree with the basic approach suggested by webernet - either move everything back to navigation and leave primary links emoty, or perhaps put the amin links in navigation and then duplicate them in the primary links.

catch’s picture

I also think webernet's suggestion is good, although it'd need documenting. Duplication the admin links between primary links and navigation might work as well.

pwolanin’s picture

yes - I think basically the mechanism could look like this for these cases:

put everything form the D5 navigation menu into the primary (or secondary) links menu BUT set module='menu' NOT module='system'

then I think menu rebuild will put a clean, new, set of links derived from the router items into the navigation menu with module='system'

David_Rothstein’s picture

I just took a look at the code, and I could be way off base here, but I think maybe a lot of this problem can be traced to the following snippet from system_update_6021():

if ($primary = variable_get('menu_primary_menu', 0)) {
  $_SESSION['menu_menu_map'][$primary] = 'primary-links';
  $_SESSION['menu_item_map'][$primary] = FALSE;
  (etc...)
}

Here, "menu_primary_menu" <=> "menu containing primary links". It seems odd to me that this variable is being used here. In Drupal 5, menu_primary_menu is essentially a theme-related concept, right? I might have lots of menus on my site ("Navigation", "Primary Links", "Bob", "Jane"), and the only purpose of the menu_primary_menu variable is to determine which of these menus gets sent off to the theme system to use as the primary links. So it seems like it might be wrong to use this variable to build the Drupal 6 menus themselves. A similar concern exists for the secondary links...

Second, what happened to the menu_primary_menu variable in Drupal 6 -- is it even used? Look at menu_primary_links() and compare Drupal 5 to Drupal 6. It looks like Drupal 6 always assumes you want to use one particular menu as the primary links in your theme. Whereas Drupal 5 lets you send whichever menu you want to the theme system. Maybe some of the code from Drupal 5 could be put back here?

Anyway, that's my quick idea... (Quite possibly there are major consequences of the above that I haven't thought of -- I don't know much about the new menu system.)

David_Rothstein’s picture

Status: Active » Needs work
FileSize
9.02 KB

Gotta run out the door, but here is a patch that seems to fix things. Needs some serious review, though....

Basically, all I did was change the code so that the menu system stops treating menus named 'primary-links' and 'secondary-links' as special within the database and within the upgrade script. (Since primary/secondary links are a theme-related concept, the menu system really doesn't need to care about them.) Consequently, we can also restore the feature from Drupal 5 where the administrator is able to choose whatever menu they want to appear in the primary/secondary links section of the theme, and Drupal 6 now respects this choice during the upgrade.

Patch still needs some work:

  • Options from Drupal 5 need to be added back to the form at admin/build/menu/settings.
  • Doesn't currently do anything to clean things up for people upgrading from RC3...
  • Problems still occur if you assign "Administer" or "Create Content" to a non-Navigation menu in Drupal 5 and then upgrade to Drupal 6... this might be a slightly different bug (it happens both with or without this patch).
  • (less serious) Should it really be possible to delete the menu items representing each menu (see admin/build/menu-customize/navigation)? Especially for a system-generated one like "Navigation", it seems like you should be able to disable the menu item but not delete it.

Hope this helps!

webernet’s picture

As for the fourth bullet in #11 --> http://drupal.org/node/212557

chx’s picture

I am very much against this approach. I might look at the problem tomorrow but making a special case out of the primary and secondary links just because -- nope, I do not like this.

pwolanin’s picture

So, this gets us somewhat back to this issue/comment: http://drupal.org/node/160168#comment-582457

chx’s picture

FileSize
5.27 KB

grumble. someone plz up 6021. Note that this is a whole another approach and yet I severely dislike and yet I know this is how D5 worked so I have no better idea.

pwolanin’s picture

also, it may be a foolish suggestion, but we could htink about using better batch APi methods too: http://drupal.org/node/198980

chx’s picture

We probably should change as little as possible this late in the game.

dmitrig01’s picture

FileSize
6.69 KB

Slight change - PHP syntax error

Gerhard Killesreiter’s picture

The last patch contains some cruft, ie line ending changes and other formatting changes.

David_Rothstein’s picture

@chx, could you explain more what you meant in #13:

I am very much against this approach.... Making a special case out of the primary and secondary links just because -- nope, I do not like this.

Was that in reference to my patch or to something else? Because I agree with you completely... and that was the whole purpose of my patch in #11 ;) Right now, Drupal 6 makes all sorts of special accommodations for menus named "primary-links" and "secondary-links", and all my patch really does is remove these special accommodations (actually, looking back on it now, I may have removed more special accommodations than were necessary to actually fix the bug). Let me ask once again for people to test this patch, because when I tried it, it seemed to fix the bug perfectly.

Again, Drupal 5 treats primary/secondary links as a theme-related concept, so the site admin gets to put whatever menu they want in these regions. (I think it's similar to Block Regions, where the admin gets to put whichever blocks they want in e.g. the left sidebar.) The ultimate cause of this bug is that Drupal is trying to take whatever complicated structures people might have had in Drupal 5 and fit them into a system in Drupal 6 where you are forced to have menus whose names are "primary-links" and "secondary-links" that are linked to the theme regions. So I don't see how there is any reasonable way to fix this without going back to the Drupal 5 way.

In fact, seeing as how both my patch in #11 as well as @chx's patch in #15 both restore some of the Drupal 5 functionality, and the patch in #15 focuses on the admin form (which, as I said, I didn't get around to dealing with in my patch), maybe we just want to look at merging the two patches?

The real thing I'm having trouble understanding is why everyone's patches are titled "I hate this patch" ;) All these patches do is give the site admin some extra flexibility, which they already had in Drupal 5. From my point of view they all have great side effects, in that they help with the goal of separating data (the menu system) from theme presentation (primary/secondary links), a separation which Drupal 5 already had. What is so bad about that?

chx’s picture

I dislike doing this because it adds extra complexity and special cases to the menu, that's all. But lets see more drastic changes in D7. (I am thinking on removing primary and secondary links from Drupal to be replaced by appropriate theming of a block in the header region)

pwolanin’s picture

Status: Needs work » Needs review
FileSize
4.41 KB

patch is crufty indeed - also seems to accidentally comment out part of of the drag-n-drop functionality.

re-roll with most of the cruft removed, and with other fixes (including changing the description string, since the existing one doesn't make sense in light of the altered functionality)

no update path fix yet, so CNR means just check that this part of the functionality is right.

Note, per chx, that while it might make sense to rethinking the hard-coded primary & secondary menus, in light of the hopes of getting a release out real soon now (TM), we will hew to the path of the least code changes to achieve an acceptable fix.

pwolanin’s picture

ok, here's with a first, UNTESTED attempt to fix the update path. The code's a bit ugly, but seems to be the minimal change possible.

David_Rothstein’s picture

Ah, nice, sounds like a great plan for D7, @chx.

Attached is the same as #23 but with a typo fixed ("$secondry" should be "$secondary"). I tested it, and it does fix the worst part of the bug - excellent! But.... the list at admin/build/menu is still a complete garbled mess (see point number 3 in my original bug report above). It's probably going to take lots more messy update code to deal with that, I would think.

Here's another idea: What about using the approach in my patch for system_update_6021 (but not the rest of my patch)? So we still would keep the hard-coded primary and secondary menus, as you suggested, but only in the case of a new Drupal 6 installation. People upgrading from Drupal 5 can't possibly benefit from the addition of these two new (empty) menus, since they already have their primary/secondary links set the way they want them. Just an idea -- needs more thought... but in the end it may involve fewer code changes.

David_Rothstein’s picture

Oops, apparently I never attached it.

Gábor Hojtsy’s picture

Patch looks reasonable, but it would be easier to review without code style changes. I wonder why was this feature lost in the first place.

keith.smith’s picture

Status: Needs review » Needs work
+    '#description' => t('Select what should be displayed as the secondary links. If the same menu as is the source for the primary links (currently %primary) is chosen, the children of the active primary menu link (if any) will be shown instead of the top-level links that are shown if the source is a different menu.', array('%primary' => $menu_options[$primary])),

Something is odd here around "If the same menu as is the source..." Also, I've read this several times and still can't really quite put my finger on what it actually means.

cburschka’s picture

You're right, that is a pretty confusing description.

If the same menu as is the source for the primary links (currently %primary) is chosen, the children of the active primary menu link (if any) will be shown instead of the top-level links that are shown if the source is a different menu.

Translated to comprehensible English, as far as I understand it:

You can choose the same menu for secondary links as for primary links (currently %primary). If you do this, the children of the active primary menu link will be displayed as secondary links.

Better?

chx’s picture

Status: Needs work » Needs review
FileSize
9.58 KB

Hrm, not quite... this does not cover a lot of possibilities. Lets see this patch. The update, at the end of the day, actually got simpler.

chx’s picture

FileSize
9.58 KB

typofix.

cburschka’s picture

this does not cover a lot of possibilities

Sorry, but now I'm stumped. When I saw that monster sentence I thought I had an inkling of what it meant, but if it doesn't mean what I said, then what possibilities am I missing?

If you are referring to "instead of the top-level links that are shown if the source is a different menu", then that just describes what the secondary links menu does normally - which is pretty self-explanatory. It's setting primary and secondary links to be the same menu that is the unexpected neat feature, and that is what needs to be explained.

Gábor Hojtsy’s picture

@Arancaytar: chx was referring to the (update) code, not your text improvements. IMHO your text improvements are better, and definitely cover the task at hand there. Chx is working on the code :)

cburschka’s picture

Oh, okay. I read the new patch, but didn't pay close attention to what it changed from the previous one.

I guess the text improvement ought to wait until the rest of the patch is ready, since it changes only a single line.

catch’s picture

Should note that a slightly altered version of Arancaytar's text improvements are in #30. Overall the string changes look good to me, and I never realised that about secondary links...

I'm not sure if I'll have time to actually test this today, either way can I confirm this is what needs to be checked?

1. install D5, create primary + secondary links as new menus from scratch, upgrade
2. install D5, set navigation to primary links, upgrade
3. install D5, set primary and secondary links to the same menu, upgrade
4. clean D6 install I guess.

Anything missing from that?

cburschka’s picture

Should note that a slightly altered version of Arancaytar's text improvements are in #30.

Doesn't look that way - this is from #30:

-    '#description' => t('Select what should be displayed as the secondary links. If %primary is chosen, the children of the active primary menu link (if any) will be shown instead of the links in the %secondary menu.', array('%secondary' => $menu_options['secondary-links'],  '%primary' => $menu_options['primary-links'])),
+    '#description' => t('Select what should be displayed as the secondary links. If the same menu as is the source for the primary links (currently %primary) is chosen, the children of the active primary menu link (if any) will be shown instead of the top-level links that are shown if the source is a different menu.', array('%primary' => $menu_options[$primary])),
chx’s picture

I have not included string fixes those posts happened while i was fiddling with the code.

David_Rothstein’s picture

@catch, I would consider adding a couple things to your list of tests (based on where I saw different kinds of problems in previous testing):

1. install D5, create primary + secondary links as new menus from scratch, upgrade
2. install D5, set primary links to navigation, upgrade
3. install D5, set secondary links to navigation, upgrade
4. install D5, set both primary and secondary links to navigation, upgrade
5. install D5, set primary and secondary links to the same (non-navigation) menu, upgrade
6. install D5, set primary and/or secondary links to "No primary/secondary links", upgrade
7. clean D6 install I guess.

David_Rothstein’s picture

Status: Needs review » Needs work

I tested #30. Unfortunately it failed the first 4 tests in my above post (so I didn't bother with the others). The major problem was data loss: the default "Primary links" menu that ships with Drupal 5 disappeared (even when it had items defined within it). This seemed to happen whenever another menu was set as primary links at the time of the update.

Also, on tests 2 through 4, there was an additional problem: the Navigation menu is once again not appearing in the primary or secondary links after the upgrade (this time, the primary and secondary links were empty).

David_Rothstein’s picture

Status: Needs work » Needs review
FileSize
8.19 KB

OK, how about this: I decided to try combining #30 with some ideas from the update function in #11... the new patch is attached.

I ran through all the tests listed in #37 and this patch seems to work fine for all of them, so the bug should now be fixed.

The only minor side effect is that people upgrading from Drupal 5 don't get the nice descriptions of what primary and secondary links are added to their menus (whereas people installing Drupal 6 do get them). But that's hardly a show stopper, I would think. Especially since the descriptions can look weird in the D5 update case if your primary links menu has a custom title.

David_Rothstein’s picture

Oh, there's actually another minor side effect, which applies both to the patches in #30 and #39. It involves this function:

/**
 * Return an array containing the names of system-defined (default) menus.
 */
function menu_list_system_menus() {
  return array('navigation', 'primary-links', 'secondary-links');
}

For both patches, the last two menus aren't guaranteed to exist after an update from D5. I don't think this really matters at all, but it may be worth documenting.

pwolanin’s picture

@David_Rothstein - all three of those should exist as entries in {menu_custom} or the update code is broken. It's fine if there are zero items in {menu_links} in any of the menus.

David_Rothstein’s picture

Okay, in what way would you expect the update to break?

As I said, I tested this extensively and never saw any problems -- in all cases the D5 menus and their contents were copied to D6 with no data loss and with the correct settings for primary and secondary links in place. Everything worked absolutely fine after the update too. What problem should we be looking for?

I also grepped the codebase for all occurrences of "primary-links" and "secondary-links" menus, and there are very few. Nothing that could possibly cause a real problem if the menus don't exist, but please double check this. This is also true of the above function if you look at how other functions are using it (http://api.drupal.org/api/function/menu_list_system_menus/6/references).

As I said, this is an issue with both approaches (#30 and #39), so probably we need to straighten it out one way or the other. For example, this code from #30 is not designed to guarantee that a menu named "secondary-links" will always exist:

if ($item['mid'] != variable_get('menu_primary_menu', 0)) {
  $description = 'Secondary links are often used for pages like legal notices, contact details, and other secondary navigation items that play a lesser role than primary links';
  $item['menu_name'] = 'secondary-links';
}
else {
  variable_set('menu_secondary_links_source', $item['menu_name']);
}
David_Rothstein’s picture

Hm, I suppose, that if it is absolutely necessary, it would be easy enough to add a few lines of code at the end of the update process to force menus named 'primary-links' and 'secondary-links' to be created. You are guaranteed to have a very confusing menu admin screen if this is done, though.

NancyDru’s picture

Has anyone tested with Administer being moved out of Navigation into it's own menu? I ask because I just had some very weird happenings with that situation and a module being converted that had an improperly constructed menu.

David_Rothstein’s picture

@nancyw, I've seen that too, but it looks like it might be a separate bug which doesn't just occur on a D5 update: http://drupal.org/node/211979

David_Rothstein’s picture

FileSize
12.23 KB

OK, here is the patch from #39 with code added to ensure that menus named 'primary-links' and 'secondary-links' always get created during the update. A fair amount of work needed to be done to catch all the edge cases and try to present something not-too-confusing on the menu admin screen.

I've tested this in several cases and it works as well as #39 at fixing the bug, plus I've confirmed that (one way or another) you always wind up with menus named 'primary-links' and 'secondary-links' after the update, as requested.

Gábor Hojtsy’s picture

Anyone else to test this, so that we can get over this issue? :)

catch’s picture

Ok I'll do these one by one, and keep editing the post, just in case someone lovely wants to work backwards from seven.

1. install D5, create primary + secondary links as new menus from scratch, upgrade
- fine.

2. install D5, set primary links to navigation, upgrade
- ok I did this, but left my empty primary links menu untouched. I get empty primary links and secondary links after upgrade and a decent navigation menu. Secondary links appears.

2a. deleted primary links. Both empty menus appear, navigation is still set to primary links in settings. seems fine this one.

3. install D5, set secondary links to navigation, upgrade
- This way I get empty secondary links and primary links menus. Navigation still set as secondary links in settings. The top links in Garland are showing top level Navigation items - I guess because primary is empty?? Haven't looked into how Garland treats this. Anyway, no damage at least.

4. install D5, set both primary and secondary links to navigation, upgrade

5. install D5, set primary and secondary links to the same (non-navigation) menu, upgrade
6. install D5, set primary and/or secondary links to "No primary/secondary links", upgrade
7. clean D6 install I guess.

webernet’s picture

One minor issue with #46 -- The primary links menu no longer gets a description (menu had been renamed prior to update).

pwolanin’s picture

Status: Needs review » Needs work

[edit]

Will try to fix the problem noted by webernet and clean up the code a little more during further testing.

David_Rothstein’s picture

About the problem raised by @webernet, I did that intentionally. I can see the argument both ways, though.

My reasoning was that (a) it made the code simpler, and (b) a lot of people are likely to have renamed their Drupal 5 primary links menu, let's say to "Widgets" (since their website sells widgets, of course ;), so it might look a little weird if after the update their "Widgets" menu suddenly had a description that talked not about widgets, but instead.... the role of primary links in a Drupal website. So I figured it was better to leave the description blank unless we're absolutely sure what menu it's being inserted in.

@catch, fun testing, huh? For the third test, if I understand what you wrote correctly, I think that's the correct behavior: the secondary links should be showing the top level of the Navigation menu ("Administer", "My account", etc). The second level of the Navigation menu should only appear if both primary and secondary links are set to Navigation, right...?

pwolanin’s picture

Status: Needs work » Needs review
FileSize
13.57 KB

this patch puts in the description as suggested by webernet, and cleans up the code a little. It keeps the basically the approach worked out by David_Rothstein.

I rean a few update scenarios with MySQL, but I'm not known for my ability to hit all the edge cases when writing patches...

catch’s picture

4. install D5, set both primary and secondary links to navigation, upgrade

upgrade smooth. Settings shows secondary links as set to navigation. Primary Links menu (with new description) contains the navigation menu, but it also contains my old watchdog links etc.Also the Navigation menu exists independently of the Primary Links menu, and that contains all new drupal admin menu items (reports, actions) which are now outside the admin menu. I don't think this is a showstopper, so not going to mark as needs work based on this.

The original primary links menu still shows there as empty with no description - this is a good thing, I might've put something in there and/or changed it if it was a real site.

5. install D5, set primary and secondary links to the same (non-navigation) menu, upgrade
Yep good. No issues at all.

6. install D5, set primary and/or secondary links to "No primary/secondary links", upgrade
Set both of these and renamed primary links for good measure. Got spangly new Primary and Secondary links menus with the descriptions, and in settings it's a radio (which defaults to secondary links). Again, seems fine.

Alright, as far as I'm concerned the issues in 4. are minor, and iirc the upgrade path to remove stale links was introduced late in the cycle, and was non-trivial. Considering the menu is outside of it's normal settings at this point. Having navigation set to both primary and secondary links to me seems like a fairly odd edge case, especially doing so with the entire admin menu tree left in there - if you're working day-to-day with that, then surely you can handle deleting about five menu items and moving a couple over (and you could've also tested this patch in the past three days).

Leaving at needs review, someone who can think of real valid use cases for 4. will have to explain what desired behaviour is and/or patch/test this.

Gábor Hojtsy’s picture

Testing the latest patch.

Gábor Hojtsy’s picture

Catch: I also run through all test cases with #52, and I cannot see any errors popping up. Both primary and secondary links menus are properly created. Invalid menu items used (eg. node/12 when there was no such node) disappear as expected in Drupal 6, valid items remain. Settings of the primary/secondary links to each other or navigation or no menu stays after the upgrade. I have seen no menu item duplication is the primary/secondary menus when the navigation menu was set for their source with the latest patch (#52). Did you test these last scenarios with the latest patch in #52?

catch’s picture

Status: Needs review » Reviewed & tested by the community

OK I must've gone wrong somewhere - couldn't reproduce the errors I got with 4.

Now, if I set navigation to both primary and secondary links (leaving the empty primary menu as it is), then upgrade, I get a nice Navigation menu, no bogus items, everything that's supposed to be there, and empty primary and secondary links menus, with descriptions.

I think that's pretty damn good, so marking RTBC since all the other tests were fine anyway.

Gábor Hojtsy’s picture

Version: 6.x-dev » 7.x-dev

Wow, thanks, committed #52 to 6.x. (I also got notice from webernet on IRC, that he also tested and all looked fine to him as well). Still needs to be committed to 7.x.

pwolanin’s picture

bump - needs to be committed to HEAD

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

daddison’s picture

From #10:

Second, what happened to the menu_primary_menu variable in Drupal 6 -- is it even used?

I think the variable override in settings.php for primary links is now done like this:

'menu_primary_links_source' => 'menu_name',

where 'menu_name' comes from your menu_custom table.