fix(core): re-init session and culture in switchContext - #73
Open
Ibochkarev wants to merge 2 commits into
Open
Conversation
Add null check for $this->context before accessing it in switchContext to prevent errors when context is not initialized. Call _initCulture(null) after successful context switch so culture/session are re-initialized for the new context (fixes routing plugins like XRouting). Refs modxcms#14962
After a successful context switch, call _initSession/_initCulture so context cultureKey and session options apply without public wrappers. Guard null context and cover with regression tests (modxcms#14962).
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.
Что сделано
После успешного
switchContext()MODX вызывает_initSession(null), затем_initCulture(null), поэтомуcultureKey/ locale нового контекста (и опции сессии, когда сессия ещё не активна) вступают в силу.Также возвращает
false, когда$this->contextnull, вместо fatal на->key.Не экспонирует публичные
initCulture()/initSession()— это было отвергнуто в ревью; переключение сессии mid-request по-прежнему не рекомендуется, а_initSessionостаётся no-op, когда сессия уже инициализирована.Зачем нужно
Context-routing плагины вызывают
switchContext()после оригинального пути init. Без re-init лексикон/locale (а иногда и session enablement через настройки контекста) остаются на предыдущем контексте (modxcms#14962).Как проверить
cultureKey(напримерen/de).$modx->switchContext('other', true)→$modx->cultureKeyи лексикон матчат целевой.phpunit --filter modXSwitchContextCultureTestСвязанные
Refs modxcms#14962
Оригинал: modxcms#16854