diff --git a/UPGRADE.md b/UPGRADE.md index 7248625..67cd064 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -8,6 +8,7 @@ Just click the "update" button or execute the migration command to finish the bu #### Update from Version 3.0.0 to Version 3.1.0 - **[NEW FEATURE]**: Allow [pimcore redirect modification](https://github.com/dachcom-digital/pimcore-i18n/issues/33). +- **[BUGFIX]**: Disable context switch event if [pimcore full page cache](https://github.com/dachcom-digital/pimcore-i18n/issues/18) is enabled #### Update from Version 2.x to Version 3.0.0 - **[NEW FEATURE]**: Pimcore 6.0.0 ready diff --git a/docs/70_ContextSwitch.md b/docs/70_ContextSwitch.md index 3a88cdc..2720cda 100644 --- a/docs/70_ContextSwitch.md +++ b/docs/70_ContextSwitch.md @@ -8,6 +8,9 @@ If you have a complex e-commerce environment for example, you may want to check - ContextSwitch only works in **same domain levels**. Since there is no way for simple cross-domain session ids, the zone switch will be sort of useless most of the time. - The ContextSwitchEvent **ignores** ajax request. If your requesting data via ajax in a different language / country, no event will be triggered! +## Limitation +This event is disabled if the pimcore full page cache feature is enable to prevent session interventions. + *** ## Implementation diff --git a/src/I18nBundle/EventListener/ContextSwitchDetectorListener.php b/src/I18nBundle/EventListener/ContextSwitchDetectorListener.php index 959bde0..d6fe67c 100644 --- a/src/I18nBundle/EventListener/ContextSwitchDetectorListener.php +++ b/src/I18nBundle/EventListener/ContextSwitchDetectorListener.php @@ -69,25 +69,33 @@ class ContextSwitchDetectorListener implements EventSubscriberInterface */ protected $requestValidatorHelper; + /** + * @var array + */ + protected $pimcoreConfig; + /** * @param EventDispatcherInterface $eventDispatcher * @param DocumentResolver $documentResolver * @param ZoneManager $zoneManager * @param DocumentHelper $documentHelper * @param RequestValidatorHelper $requestValidatorHelper + * @param array $pimcoreConfig */ public function __construct( EventDispatcherInterface $eventDispatcher, DocumentResolver $documentResolver, ZoneManager $zoneManager, DocumentHelper $documentHelper, - RequestValidatorHelper $requestValidatorHelper + RequestValidatorHelper $requestValidatorHelper, + $pimcoreConfig ) { $this->eventDispatcher = $eventDispatcher; $this->documentResolver = $documentResolver; $this->zoneManager = $zoneManager; $this->documentHelper = $documentHelper; $this->requestValidatorHelper = $requestValidatorHelper; + $this->pimcoreConfig = $pimcoreConfig; } /** @@ -111,6 +119,10 @@ public static function getSubscribedEvents() */ public function onKernelRequest(GetResponseEvent $event) { + if ($this->pimcoreConfig['cache']['enabled'] === true) { + return; + } + if ($event->isMasterRequest() === false) { return; } diff --git a/src/I18nBundle/Resources/config/services/event.yml b/src/I18nBundle/Resources/config/services/event.yml index a389e62..f37ef80 100644 --- a/src/I18nBundle/Resources/config/services/event.yml +++ b/src/I18nBundle/Resources/config/services/event.yml @@ -19,6 +19,8 @@ services: I18nBundle\EventListener\ContextSwitchDetectorListener: tags: - { name: kernel.event_subscriber } + arguments: + $pimcoreConfig: '%pimcore.config%' # event: checks if hardlink page has a front-page map I18nBundle\EventListener\FrontPageMapperListener: diff --git a/tests/_etc/config/bundle/symfony/config_full_page_cache.yml b/tests/_etc/config/bundle/symfony/config_full_page_cache.yml new file mode 100755 index 0000000..452ff53 --- /dev/null +++ b/tests/_etc/config/bundle/symfony/config_full_page_cache.yml @@ -0,0 +1,9 @@ +i18n: + mode: language + locale_adapter: system + default_locale: 'en' + translations: ~ + +pimcore: + cache: + enabled: true diff --git a/tests/_support/Helper/Browser/PhpBrowser.php b/tests/_support/Helper/Browser/PhpBrowser.php index 0cb0fd8..921b15c 100644 --- a/tests/_support/Helper/Browser/PhpBrowser.php +++ b/tests/_support/Helper/Browser/PhpBrowser.php @@ -4,12 +4,12 @@ use Codeception\Module; use Codeception\Lib; -use Codeception\Util\Uri; use Codeception\Exception\ModuleException; use DachcomBundle\Test\Helper\PimcoreCore; use DachcomBundle\Test\Helper\PimcoreUser; use Pimcore\Model\User; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface; +use Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector; use Symfony\Component\HttpKernel\Profiler\Profile; @@ -228,6 +228,49 @@ public function dontSeeCanonicalLinkInResponse() $this->assertNull($link); } + /** + * Actor Function to see pimcore output cached disabled header + * + * @param $disabledReasonMessage + */ + public function seePimcoreOutputCacheDisabledHeader($disabledReasonMessage) + { + $disabledReason = $this->pimcoreCore->client->getInternalResponse()->getHeader('X-Pimcore-Output-Cache-Disable-Reason'); + + $this->assertEquals($disabledReasonMessage, $disabledReason); + } + + /** + * Actor Function to not to see pimcore output cached disabled header + */ + public function dontSeePimcoreOutputCacheDisabledHeader() + { + $disabledReason = $this->pimcoreCore->client->getInternalResponse()->getHeader('X-Pimcore-Output-Cache-Disable-Reason'); + + $this->assertNull($disabledReason); + } + + /** + * Actor Function to not to see pimcore output cached disabled header + */ + public function seePimcoreOutputCacheDate() + { + $cacheDateHeader = $this->pimcoreCore->client->getInternalResponse()->getHeader('x-pimcore-cache-date'); + + $this->assertNotNull($cacheDateHeader); + } + + /** + * Actor Function to assert empty i18n session bag + */ + public function seeEmptyI18nSessionBag() + { + /** @var NamespacedAttributeBag $sessionBag */ + $sessionBag = $this->pimcoreCore->client->getRequest()->getSession()->getBag('i18n_session'); + + $this->assertCount(0, $sessionBag->all()); + } + /** * Actor Function to check if last _fragment request has given properties in request attributes. * diff --git a/tests/functional.full_page_cache.suite.dist.yml b/tests/functional.full_page_cache.suite.dist.yml new file mode 100644 index 0000000..f0890ba --- /dev/null +++ b/tests/functional.full_page_cache.suite.dist.yml @@ -0,0 +1,13 @@ +actor: FunctionalTester +modules: + enabled: + - \DachcomBundle\Test\Helper\PimcoreCore: + connect_db: true + rebootable_client: true + configuration_file: 'config_full_page_cache.yml' + - \DachcomBundle\Test\Helper\PimcoreBundleCore: + run_installer: true + - \DachcomBundle\Test\Helper\Browser\PhpBrowser: + depends: \DachcomBundle\Test\Helper\PimcoreCore + - \DachcomBundle\Test\Helper\PimcoreBackend + - \DachcomBundle\Test\Helper\PimcoreUser diff --git a/tests/functional.full_page_cache/FullPageCacheCest.php b/tests/functional.full_page_cache/FullPageCacheCest.php new file mode 100644 index 0000000..e5e46b5 --- /dev/null +++ b/tests/functional.full_page_cache/FullPageCacheCest.php @@ -0,0 +1,25 @@ +haveASite('test-domain1.test'); + $I->haveAPageDocumentForSite($site1, 'en', 'en'); + $I->haveAPageDocumentForSite($site1, 'de', 'de'); + + $I->amOnPageWithLocale('http://test-domain1.test/de', 'de'); + + $I->dontSeePimcoreOutputCacheDisabledHeader(); + $I->seePimcoreOutputCacheDate(); + $I->seeEmptyI18nSessionBag(); + } + +} \ No newline at end of file diff --git a/tests/functional.full_page_cache/_bootstrap.php b/tests/functional.full_page_cache/_bootstrap.php new file mode 100644 index 0000000..94bf66c --- /dev/null +++ b/tests/functional.full_page_cache/_bootstrap.php @@ -0,0 +1,2 @@ +