Fix undefined $_SESSION warning when rebuilding menu cache - #16990
Open
Ibochkarev wants to merge 1 commit into
Open
Fix undefined $_SESSION warning when rebuilding menu cache#16990Ibochkarev wants to merge 1 commit into
Ibochkarev wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed and why
modMenu::rebuildCache()and other manager-language lookups passed bare$_SESSIONintogetOption(). Without an active session (CLI, early bootstrap, save/remove cache work) PHP 8+ logsUndefined global variable $_SESSION.Changes:
modX::getManagerLanguage()resolves language as$_SESSION ?? []→ configmanager_language→cultureKey→en.modMenu::save/removecallclearCache()(cleanon the menu partition) and skip session-keyed rebuild. Menu processors still callrefresh(['menu' => []])once, soOnCacheUpdatefires once.getManagerLanguage():rebuildCache, manager header, lexicon, connector/manager request, country list, transport provider.getSubMenusdrops identical dead lexicon branches.$_SESSION ?? [].How to test
php -lon the touched PHP files.composer phpunit -- --filter 'modMenuTest|testGetManagerLanguage'(expect exit 0: 4 tests, 8 assertions).Undefined global variable $_SESSIONfrommodMenu.php.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 $_SESSIONatcore/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 fireOnCacheUpdateonce. Safe for patch-level consumers.Test coverage
_build/test/Tests/Model/modXTest.php:getManagerLanguagewithout session and with session preference_build/test/Tests/Model/modMenuTest.php:rebuildCachewithout$_SESSIONwarning;clearCacheremoves menu partition keys_build/test/phpunit.xmlContributors
AI tool use
Cursor (Composer) handled implementation and reviews: code-simplifier, code-reviewer, thermo-nuclear code-quality review, security-review.