Skip to content

Commit 58b913b

Browse files
committed
[TASK] v13 cache
1 parent 96a884d commit 58b913b

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-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

+10
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
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;
19+
use TYPO3\CMS\Core\Information\Typo3Version;
1820
use TYPO3\CMS\Core\Site\Entity\Site;
1921
use TYPO3\CMS\Core\Utility\GeneralUtility;
2022
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
@@ -317,6 +319,10 @@ public function processTest(array $tsfe, array $configuration, array $expected)
317319
$request = GeneralUtility::makeInstance(ServerRequest::class);
318320
$request = $request->withAttribute('site', $site);
319321
$request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE);
322+
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() > 12) {
323+
$cacheDataCollector = new CacheDataCollector();
324+
$request = $request->withAttribute('frontend.cache.collector', $cacheDataCollector);
325+
}
320326
$GLOBALS['TYPO3_REQUEST'] = $request;
321327

322328
$GLOBALS['TSFE'] = $this->getTypoScriptFrontendController($site, $tsfe['id']);
@@ -371,6 +377,10 @@ public function menuIdTagsAreAddedToPageCache(array $tsfe, array $configuration,
371377
$request = GeneralUtility::makeInstance(ServerRequest::class);
372378
$request = $request->withAttribute('site', $site);
373379
$request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE);
380+
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() > 12) {
381+
$cacheDataCollector = new CacheDataCollector();
382+
$request = $request->withAttribute('frontend.cache.collector', $cacheDataCollector);
383+
}
374384
$GLOBALS['TYPO3_REQUEST'] = $request;
375385

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

Tests/Functional/DataProcessing/TreeMenuProcessorTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
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;
19+
use TYPO3\CMS\Core\Information\Typo3Version;
1820
use TYPO3\CMS\Core\Site\Entity\Site;
1921
use TYPO3\CMS\Core\Utility\GeneralUtility;
2022
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
@@ -401,6 +403,10 @@ public function processTest(array $tsfe, array $configuration, array $expected):
401403
$request = GeneralUtility::makeInstance(ServerRequest::class);
402404
$request = $request->withAttribute('site', $site);
403405
$request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE);
406+
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() > 12) {
407+
$cacheDataCollector = new CacheDataCollector();
408+
$request = $request->withAttribute('frontend.cache.collector', $cacheDataCollector);
409+
}
404410
$GLOBALS['TYPO3_REQUEST'] = $request;
405411

406412
$GLOBALS['TSFE'] = $this->getTypoScriptFrontendController($site, $tsfe['id']);
@@ -466,6 +472,10 @@ public function menuIdTagsAreAddedToPageCache(array $tsfe, int $entryPoints, arr
466472
$request = GeneralUtility::makeInstance(ServerRequest::class);
467473
$request = $request->withAttribute('site', $site);
468474
$request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE);
475+
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() > 12) {
476+
$cacheDataCollector = new CacheDataCollector();
477+
$request = $request->withAttribute('frontend.cache.collector', $cacheDataCollector);
478+
}
469479
$GLOBALS['TYPO3_REQUEST'] = $request;
470480

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

0 commit comments

Comments
 (0)