Skip to content

Commit 3cfafac

Browse files
committed
[TASK] v13 cache
1 parent 96a884d commit 3cfafac

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

Build/phpstan11.neon

+4
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ parameters:
1616
-
1717
message: '#.*unknown class TYPO3\\CMS\\Core\\TypoScript\\FrontendTypoScript.#'
1818
path: %currentWorkingDirectory%/Classes/CacheHelper.php
19+
-
20+
message: '#Instantiated class TYPO3\\CMS\\Core\\Cache\\CacheDataCollector not found.#'
21+
-
22+
message: '#Instantiated class TYPO3\\CMS\\Core\\Cache\\CacheTag not found.#'

Build/phpstan12.neon

+4
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ parameters:
1616
-
1717
message: '#Call to an undefined method TYPO3\\CMS\\Core\\TypoScript\\FrontendTypoScript::getConfigArray\(\).#'
1818
path: %currentWorkingDirectory%/Classes/CacheHelper.php
19+
-
20+
message: '#Instantiated class TYPO3\\CMS\\Core\\Cache\\CacheDataCollector not found.#'
21+
-
22+
message: '#Instantiated class TYPO3\\CMS\\Core\\Cache\\CacheTag not found.#'

Classes/CacheHelper.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313

1414
use Psr\Http\Message\ServerRequestInterface;
15+
use TYPO3\CMS\Core\Cache\CacheTag;
1516
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
1617
use TYPO3\CMS\Core\Context\Context;
1718
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
@@ -86,7 +87,13 @@ protected function buildTagsAndAddThemToPageCache(array $pages): array
8687
$tags = array_map(function ($pageId) {
8788
return 'menuId_' . $pageId;
8889
}, $usedPageIds);
89-
$this->getFrontendController()->addCacheTags($tags);
90+
91+
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 13) {
92+
$this->getFrontendController()->addCacheTags($tags);
93+
} else {
94+
$cacheDataCollector = $this->getServerRequest()->getAttribute('frontend.cache.collector');
95+
$cacheDataCollector->addCacheTags(...array_map(fn (string $tag) => new CacheTag($tag), $tags));
96+
}
9097
return $tags;
9198
}
9299

Tests/Functional/DataProcessing/ListMenuProcessorTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
use B13\Menus\DataProcessing\ListMenu;
16+
use TYPO3\CMS\Core\Cache\CacheDataCollector;
1617
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
1718
use TYPO3\CMS\Core\Http\ServerRequest;
1819
use TYPO3\CMS\Core\Site\Entity\Site;
@@ -317,6 +318,8 @@ public function processTest(array $tsfe, array $configuration, array $expected)
317318
$request = GeneralUtility::makeInstance(ServerRequest::class);
318319
$request = $request->withAttribute('site', $site);
319320
$request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE);
321+
$cacheDataCollector = new CacheDataCollector();
322+
$request = $request->withAttribute('frontend.cache.collector', $cacheDataCollector);
320323
$GLOBALS['TYPO3_REQUEST'] = $request;
321324

322325
$GLOBALS['TSFE'] = $this->getTypoScriptFrontendController($site, $tsfe['id']);
@@ -371,6 +374,8 @@ public function menuIdTagsAreAddedToPageCache(array $tsfe, array $configuration,
371374
$request = GeneralUtility::makeInstance(ServerRequest::class);
372375
$request = $request->withAttribute('site', $site);
373376
$request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE);
377+
$cacheDataCollector = new CacheDataCollector();
378+
$request = $request->withAttribute('frontend.cache.collector', $cacheDataCollector);
374379
$GLOBALS['TYPO3_REQUEST'] = $request;
375380

376381
$GLOBALS['TSFE'] = $this->getTypoScriptFrontendController($site, $tsfe['id']);

Tests/Functional/DataProcessing/TreeMenuProcessorTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
use B13\Menus\DataProcessing\TreeMenu;
16+
use TYPO3\CMS\Core\Cache\CacheDataCollector;
1617
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
1718
use TYPO3\CMS\Core\Http\ServerRequest;
1819
use TYPO3\CMS\Core\Site\Entity\Site;
@@ -401,6 +402,8 @@ public function processTest(array $tsfe, array $configuration, array $expected):
401402
$request = GeneralUtility::makeInstance(ServerRequest::class);
402403
$request = $request->withAttribute('site', $site);
403404
$request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE);
405+
$cacheDataCollector = new CacheDataCollector();
406+
$request = $request->withAttribute('frontend.cache.collector', $cacheDataCollector);
404407
$GLOBALS['TYPO3_REQUEST'] = $request;
405408

406409
$GLOBALS['TSFE'] = $this->getTypoScriptFrontendController($site, $tsfe['id']);
@@ -466,6 +469,8 @@ public function menuIdTagsAreAddedToPageCache(array $tsfe, int $entryPoints, arr
466469
$request = GeneralUtility::makeInstance(ServerRequest::class);
467470
$request = $request->withAttribute('site', $site);
468471
$request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE);
472+
$cacheDataCollector = new CacheDataCollector();
473+
$request = $request->withAttribute('frontend.cache.collector', $cacheDataCollector);
469474
$GLOBALS['TYPO3_REQUEST'] = $request;
470475

471476
$GLOBALS['TSFE'] = $this->getTypoScriptFrontendController($site, $tsfe['id']);

0 commit comments

Comments
 (0)