From 98f95429f604ea0add72bf937e21dc463a34565b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Lochm=C3=BCller?= Date: Sun, 27 Oct 2024 21:02:43 +0100 Subject: [PATCH] Fix bugs related to v13 --- .../Cache/Listener/NoIntScriptsListener.php | 19 ++++++++++----- .../Listener/StaticCacheableListener.php | 2 -- .../Middleware/FrontendCacheMiddleware.php | 4 ++-- Classes/Middleware/GenerateMiddleware.php | 23 ++++++++++++------- Resources/Private/Templates/Backend/List.html | 4 ++-- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Classes/Cache/Listener/NoIntScriptsListener.php b/Classes/Cache/Listener/NoIntScriptsListener.php index b1d95f475f7..148e69e3c18 100644 --- a/Classes/Cache/Listener/NoIntScriptsListener.php +++ b/Classes/Cache/Listener/NoIntScriptsListener.php @@ -27,17 +27,24 @@ public function __invoke(CacheRuleEvent $event): void protected function getInformation($configuration): array { $info = []; - if (isset($configuration['type'])) { - $info[] = 'type: ' . $configuration['type']; + + // Root properties + foreach ([ + 'target', + 'type', + ] as $value) { + if (isset($configuration[$value])) { + $info[] = $value . ': ' . $configuration[$value]; + } } - $check = [ - 'target', // @todo check for nonce + + // Conf properties + foreach ([ 'userFunc', 'includeLibs', 'extensionName', 'pluginName', - ]; - foreach ($check as $value) { + ] as $value) { if (isset($configuration['conf'][$value])) { $info[] = $value . ': ' . $configuration['conf'][$value]; } diff --git a/Classes/Cache/Listener/StaticCacheableListener.php b/Classes/Cache/Listener/StaticCacheableListener.php index 64336bc1fe9..68b320af98b 100644 --- a/Classes/Cache/Listener/StaticCacheableListener.php +++ b/Classes/Cache/Listener/StaticCacheableListener.php @@ -5,9 +5,7 @@ namespace SFC\Staticfilecache\Cache\Listener; use SFC\Staticfilecache\Event\CacheRuleEvent; -use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Information\Typo3Version; -use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; /** diff --git a/Classes/Middleware/FrontendCacheMiddleware.php b/Classes/Middleware/FrontendCacheMiddleware.php index 0656270c104..d5be35e155b 100644 --- a/Classes/Middleware/FrontendCacheMiddleware.php +++ b/Classes/Middleware/FrontendCacheMiddleware.php @@ -23,8 +23,8 @@ public function process( new CacheInstruction(), ); - // Disable the cache and give a reason - $cacheInstruction->disableCache('EXT:staticfilecache: Cache is disabled'); + // Disable the cache and give a reason. @todo Why? + // $cacheInstruction->disableCache('EXT:staticfilecache: Cache is disabled'); // Write back the cache instruction to the attribute $request = $request->withAttribute('frontend.cache.instruction', $cacheInstruction); diff --git a/Classes/Middleware/GenerateMiddleware.php b/Classes/Middleware/GenerateMiddleware.php index 744243c05d4..14fe0a93c3b 100644 --- a/Classes/Middleware/GenerateMiddleware.php +++ b/Classes/Middleware/GenerateMiddleware.php @@ -4,6 +4,7 @@ namespace SFC\Staticfilecache\Middleware; +use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; use TYPO3\CMS\Core\Context\Context; use Psr\EventDispatcher\EventDispatcherInterface; @@ -11,7 +12,6 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; -use SFC\Staticfilecache\Cache\UriFrontend; use SFC\Staticfilecache\Event\PreGenerateEvent; use SFC\Staticfilecache\Service\CacheService; use SFC\Staticfilecache\Service\ConfigurationService; @@ -19,9 +19,8 @@ use SFC\Staticfilecache\Service\DateTimeService; use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; -use TYPO3\CMS\Frontend\Event\AfterCachedPageIsPersistedEvent; -use TYPO3\CMS\Frontend\Event\ModifyCacheLifetimeForPageEvent; class GenerateMiddleware implements MiddlewareInterface { @@ -30,9 +29,9 @@ class GenerateMiddleware implements MiddlewareInterface public function __construct( readonly protected EventDispatcherInterface $eventDispatcher, - readonly protected CookieService $cookieService, - readonly protected Typo3Version $typo3Version, - readonly protected CacheService $cacheService + readonly protected CookieService $cookieService, + readonly protected Typo3Version $typo3Version, + readonly protected CacheService $cacheService ) {} /** @@ -94,8 +93,16 @@ protected function calculateLifetime(TypoScriptFrontendController $tsfe): int } if ($this->typo3Version->getMajorVersion() >= 13) { - /* @phpstan-ignore-next-line */ - $timeOutTime = $tsfe->get_cache_timeout($this->request); + /** @var \TYPO3\CMS\Core\Routing\PageArguments $routing */ + $routing = $this->request->getAttribute('routing'); + $timeOutTime = GeneralUtility::makeInstance(CacheLifetimeCalculator::class) + ->calculateLifetimeForPage( + $routing->getPageId(), + BackendUtility::getRecord('pages', $routing->getPageId()), + [], + 0, + GeneralUtility::makeInstance(Context::class) + ); } else { /* @phpstan-ignore-next-line */ $timeOutTime = $tsfe->get_cache_timeout(); diff --git a/Resources/Private/Templates/Backend/List.html b/Resources/Private/Templates/Backend/List.html index f468902e2fa..88a3342335a 100644 --- a/Resources/Private/Templates/Backend/List.html +++ b/Resources/Private/Templates/Backend/List.html @@ -13,8 +13,8 @@

Cache View (Page ID {pageId})

Filter:

- - + +