Skip to content

Fix undefined $_SESSION warning when rebuilding menu cache - #16990

Open
Ibochkarev wants to merge 1 commit into
modxcms:3.xfrom
Ibochkarev:fix/undefined-session-modmenu
Open

Fix undefined $_SESSION warning when rebuilding menu cache#16990
Ibochkarev wants to merge 1 commit into
modxcms:3.xfrom
Ibochkarev:fix/undefined-session-modmenu

Conversation

@Ibochkarev

@Ibochkarev Ibochkarev commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

What changed and why

modMenu::rebuildCache() and other manager-language lookups passed bare $_SESSION into getOption(). Without an active session (CLI, early bootstrap, save/remove cache work) PHP 8+ logs Undefined global variable $_SESSION.

Changes:

  • modX::getManagerLanguage() resolves language as $_SESSION ?? [] → config manager_languagecultureKeyen.
  • modMenu::save / remove call clearCache() (clean on the menu partition) and skip session-keyed rebuild. Menu processors still call refresh(['menu' => []]) once, so OnCacheUpdate fires once.
  • Rebuild/read paths use getManagerLanguage(): rebuildCache, manager header, lexicon, connector/manager request, country list, transport provider.
  • getSubMenus drops identical dead lexicon branches.
  • Login keeps Accept-Language. Session read uses $_SESSION ?? [].

How to test

  1. Run php -l on the touched PHP files.
  2. Run composer phpunit -- --filter 'modMenuTest|testGetManagerLanguage' (expect exit 0: 4 tests, 8 assertions).
  3. Save or remove a manager menu item without an HTTP session. Confirm the log has no Undefined global variable $_SESSION from modMenu.php.
  4. Set session manager_language, clear the menu cache, open the manager. Confirm the top menu renders in that language.

Related issue(s)/PR(s)

No GitHub issue. Production log:

PHPwarning: Undefined global variable $_SESSION at core/src/Revolution/modMenu.php:69.

Compatibility notes

Applies to PHP 8+ installs. No config changes. With an active manager session, language resolution matches the old getOption('manager_language', $_SESSION, …) chain.

Breaking change assessment

No public API removals. Adds modX::getManagerLanguage(). Menu mutate hooks clear the full menu partition instead of rewriting one language-keyed entry. Processors still fire OnCacheUpdate once. Safe for patch-level consumers.

Test coverage

  • _build/test/Tests/Model/modXTest.php: getManagerLanguage without session and with session preference
  • _build/test/Tests/Model/modMenuTest.php: rebuildCache without $_SESSION warning; clearCache removes menu partition keys
  • Registered in _build/test/phpunit.xml

Contributors

AI tool use

Cursor (Composer) handled implementation and reviews: code-simplifier, code-reviewer, thermo-nuclear code-quality review, security-review.

Resolve manager language through modX::getManagerLanguage and clear the menu cache partition on save/remove instead of writing a session-keyed shard without a session.
@Ibochkarev Ibochkarev added the bug The issue in the code or project, which should be addressed. label Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug The issue in the code or project, which should be addressed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant