Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Handle deprecated cache tag management #2544

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Classes/Controller/NewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
use GeorgRinger\News\Utility\TypoScript;
use GeorgRinger\NumberedPagination\NumberedPagination;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Cache\CacheTag;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Pagination\SimplePagination;
use TYPO3\CMS\Core\Pagination\SlidingWindowPagination;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
Expand Down Expand Up @@ -89,7 +91,11 @@ protected function initializeAction(): void
/** @var $typoScriptFrontendController \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
$typoScriptFrontendController = $GLOBALS['TSFE'];
if (!$cacheTagsSet) {
$typoScriptFrontendController->addCacheTags(['tx_news']);
if ((new Typo3Version())->getMajorVersion() >= 13) {
$this->request->getAttribute('frontend.cache.collector')->addCacheTags(new CacheTag('tx_news'));
} else {
$typoScriptFrontendController->addCacheTags(['tx_news']);
}
$cacheTagsSet = true;
}
}
Expand Down
21 changes: 19 additions & 2 deletions Classes/Utility/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
use GeorgRinger\News\Domain\Model\News;
use GeorgRinger\News\Event\ModifyCacheTagsFromDemandEvent;
use GeorgRinger\News\Event\ModifyCacheTagsFromNewsEvent;
use TYPO3\CMS\Core\Cache\CacheTag;
use TYPO3\CMS\Core\EventDispatcher\EventDispatcher;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\QueryResult;

Expand Down Expand Up @@ -72,7 +74,14 @@ public static function addCacheTagsByNewsRecords($newsRecords): void
}
}
if (count($cacheTags) > 0) {
$GLOBALS['TSFE']->addCacheTags($cacheTags);
if ((new Typo3Version())->getMajorVersion() >= 13) {
$cacheDataCollector = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.cache.collector');
foreach ($cacheTags as $cacheTag) {
$cacheDataCollector->addCacheTags(new CacheTag($cacheTag));
}
} else {
$GLOBALS['TSFE']->addCacheTags($cacheTags);
}
}
}

Expand All @@ -83,6 +92,7 @@ public static function addCacheTagsByNewsRecords($newsRecords): void
public static function addPageCacheTagsByDemandObject(NewsDemand $demand): void
{
$cacheTags = [];

if ($demand->getStoragePage()) {
// Add cache tags for each storage page
foreach (GeneralUtility::trimExplode(',', $demand->getStoragePage()) as $pageId) {
Expand All @@ -95,7 +105,14 @@ public static function addPageCacheTagsByDemandObject(NewsDemand $demand): void
GeneralUtility::makeInstance(EventDispatcher::class)->dispatch($event);
$cacheTags = $event->getCacheTags();
if (count($cacheTags) > 0) {
$GLOBALS['TSFE']->addCacheTags($cacheTags);
if ((new Typo3Version())->getMajorVersion() >= 13) {
$cacheDataCollector = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.cache.collector');
foreach ($cacheTags as $cacheTag) {
$cacheDataCollector->addCacheTags(new CacheTag($cacheTag));
}
} else {
$GLOBALS['TSFE']->addCacheTags($cacheTags);
}
}
}
}
Loading