I mark this as major because it's a weird and hard-to-debug problem. It gave me an headache to figure out what happened.

Description of the bug: when the cache is flushed, you sometimes end up with a broken or disappeared management menu. This especially happens when I save a view. The management menu, which for me is displayed by the Admin Menu module, only has one link: "Add content".

Cause: an access callback from the Admin module, admin_landing_page_access(), stores in cache the access info, so that it's only calculated once by path and page load. But in the bootstrap phase, XML Sitemap Menu module makes a temporary user switch to anonymous account and calls menu_link_load(), which calls _menu_link_translate(), _menu_check_access() and finally admin_landing_page_access(). So the access info is calculated with the anonymous account, which has access to very few (or none) admin links. Thus the links do not appear.

Fix proposal:
1. Use drupal_static() system so that admin_landing_page_access()'s cache can be flushed by other modules.
2. Use drupal_static_reset() in XML Site Map Menu after the user switch has been reverted.

I open a related issue for Admin.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

GaëlG’s picture

Status: Active » Needs review
FileSize
524 bytes
Dave Reid’s picture

Should we prevent future issues by just doing just drupal_static_reset() on all of the statics?

GaëlG’s picture

I don't know. This might be a performance-killer, no?

Fabianx’s picture

Status: Needs review » Reviewed & tested by the community

I think this really should just do a global drupal_static_reset() before and after even - else switching user accounts is not secure. As long as this is only called after cache clears, it should be fine as cache rebuilds are slow anyway.

Even better is it to use a sub request, but that has other problems in itself.

On the other hand just fixing for admin menu is enough for this issue, so RTBC for that.

Dave Reid’s picture

Status: Reviewed & tested by the community » Needs work

It's easy just to change this to a global drupal_static_reset(), so let's do that. Rather than needing a small followup for a small fix.

Dave Reid’s picture

Status: Needs work » Needs review
FileSize
844 bytes

Version that calls drupal_static_reset() whenever a global user object is changed.

Status: Needs review » Needs work

The last submitted patch, 6: 2306823-static-reset-on-user-switch.patch, failed testing.

Dave Reid’s picture

Status: Needs work » Needs review
FileSize
844 bytes

Try this one again.

Dave Reid’s picture

That was the same thing, here's the revised version.

Status: Needs review » Needs work

The last submitted patch, 9: 2306823-static-reset-on-user-switch.patch, failed testing.

The last submitted patch, 8: 2306823-static-reset-on-user-switch.patch, failed testing.

grisendo’s picture

This is the related issue in Admin module: #2306821: Compatibility with XML Sitemap Menu

grisendo’s picture

The combination of patch #1 with the Admin patch from #2306821: Compatibility with XML Sitemap Menu works for me.

I tried all, but I saw a couple of things about patches from #6, #8 and #9:

  1. They don't "work" for me. After I save a View, for example (the main reason I loose those admin menu links), I don't loose then anymore... but I loose the administration theme, and see the Views edit page with the public default theme.
  2. They don't pass tests. Is not too much "heavy" (not only performance, but also conceptually, too much prone to undesired side-effects) to reset all statics?
grisendo’s picture