Skip to content

Commit

Permalink
Fix bugs related to v13
Browse files Browse the repository at this point in the history
  • Loading branch information
lochmueller committed Oct 27, 2024
1 parent 71ee510 commit 98f9542
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
19 changes: 13 additions & 6 deletions Classes/Cache/Listener/NoIntScriptsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
2 changes: 0 additions & 2 deletions Classes/Cache/Listener/StaticCacheableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
4 changes: 2 additions & 2 deletions Classes/Middleware/FrontendCacheMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 15 additions & 8 deletions Classes/Middleware/GenerateMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@

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;
use Psr\Http\Message\ResponseInterface;
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;
use SFC\Staticfilecache\Service\CookieService;
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
{
Expand All @@ -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
) {}

/**
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions Resources/Private/Templates/Backend/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ <h2>Cache View <small>(Page ID {pageId})</small></h2>
</p>

<p>Filter:</p>
<f:form action="list" class="form-inline input-group">
<f:form.select name="filter" options="{all: 'All', cached: 'Cached', notCached: 'Not cached'}" class="form-control" value="{filter}" />
<f:form action="list">
<f:form.select name="filter" options="{all: 'All', cached: 'Cached', notCached: 'Not cached'}" class="form-control form-select form-select-sm" value="{filter}" style="width: 200px;" /> <br />
<f:form.submit value="Set!" class="btn btn-primary" />
</f:form>

Expand Down

0 comments on commit 98f9542

Please sign in to comment.