Skip to content

Commit c961fea

Browse files
committed
[BUGFIX] Resolve caching issues on TYPO3 v13
Because of breaking change in core (#102932) following exception was thrown: "Setup array has not been initialized. This happens in cached Frontend scope where full TypoScript is not needed by the system" Previous solution to change page cache identifier (hash base) was not applied anymore and had to be moved into event listener. https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.0/Breaking-102932-RemovedTypoScriptFrontendControllerHooks.html
1 parent fdf013c commit c961fea

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SourceBroker\T3api\EventListener;
6+
7+
use SourceBroker\T3api\Service\RouteService;
8+
use TYPO3\CMS\Frontend\Event\BeforePageCacheIdentifierIsHashedEvent;
9+
10+
/**
11+
* We add random value to page cache identifier parameters ("hash base") to protect against full page cache which causes at least two known issues in production environment:
12+
* 1. Extbase framework configuration is not loaded thus tables mapping is unknown and queries to not existing database tables may be done.
13+
* 2. Links generated using link handler are not build correctly.
14+
* 3. Error (Since TYPO3 v13): "Setup array has not been initialized. This happens in cached Frontend scope where full TypoScript is not needed by the system"
15+
*/
16+
class EnrichPageCacheIdentifierParametersEventListener
17+
{
18+
public function __invoke(BeforePageCacheIdentifierIsHashedEvent $beforePageCacheIdentifierIsHashedEvent): void
19+
{
20+
if (!RouteService::routeHasT3ApiResourceEnhancerQueryParam()) {
21+
return;
22+
}
23+
24+
$beforePageCacheIdentifierIsHashedEvent->setPageCacheIdentifierParameters([
25+
...$beforePageCacheIdentifierIsHashedEvent->getPageCacheIdentifierParameters(),
26+
't3api_hash_base_random' => microtime(),
27+
]);
28+
}
29+
}

Configuration/Services.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,9 @@ services:
134134
- name: event.listener
135135
identifier: 't3api/SetStoragePidForSnapshot'
136136
event: SourceBroker\T3api\Event\AfterCreateContextForOperationEvent
137+
138+
SourceBroker\T3api\EventListener\EnrichPageCacheIdentifierParametersEventListener:
139+
tags:
140+
- name: event.listener
141+
identifier: 't3api/EnrichPageCacheIdentifierParametersEventListener'
142+
event: TYPO3\CMS\Frontend\Event\BeforePageCacheIdentifierIsHashedEvent

ext_emconf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
'author' => 'Inscript Team',
99
'author_email' => '[email protected]',
1010
'state' => 'stable',
11-
'version' => '4.0.3',
11+
'version' => '4.1.1',
1212
'constraints' => [
1313
'depends' => [
1414
'php' => '8.1.0-8.3.99',

ext_localconf.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ static function () {
118118
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc']['t3api_clearcache'] =
119119
\SourceBroker\T3api\Service\SerializerService::class . '->clearCache';
120120

121-
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['createHashBase']['t3api'] =
122-
\SourceBroker\T3api\Hook\EnrichHashBase::class . '->init';
123-
124121
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['enhancers'][\SourceBroker\T3api\Routing\Enhancer\ResourceEnhancer::ENHANCER_NAME] = \SourceBroker\T3api\Routing\Enhancer\ResourceEnhancer::class;
125122

126123
// protects against "&cHash empty" error when `cacheHash.enforceValidation` is set to `true`

0 commit comments

Comments
 (0)