Skip to content

Commit b4d241a

Browse files
committed
Fix v14 related stuff
1 parent a89ed04 commit b4d241a

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

Classes/Cache/RemoteFileBackend.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
*/
2121
class RemoteFileBackend extends AbstractBackend implements TaggableBackendInterface, TransientBackendInterface
2222
{
23+
public const DATETIME_EXPIRYTIME_UNLIMITED_INTERNAL = '9999-12-31T23:59:59+0000';
24+
public const UNLIMITED_LIFETIME_INTERNAL = 0;
25+
2326
/**
2427
* Relative folder name.
2528
*/
@@ -93,7 +96,7 @@ public function set($entryIdentifier, $data, array $tags = [], $lifetime = null)
9396
}
9497

9598
GeneralUtility::writeFile($absoluteCacheDir . $fileName . self::FILE_EXTENSION_TAG, '|' . implode('|', $tags) . '|');
96-
GeneralUtility::writeFile($absoluteCacheDir . $fileName . self::FILE_EXTENSION_LIFETIME, (string) $this->calculateExpiryTime($lifetime)->getTimestamp());
99+
GeneralUtility::writeFile($absoluteCacheDir . $fileName . self::FILE_EXTENSION_LIFETIME, (string) $this->calculateExpiryTimeInternal($lifetime)->getTimestamp());
97100
GeneralUtility::writeFile($absoluteCacheDir . $fileName . self::FILE_EXTENSION_IDENTIFIER, $entryIdentifier);
98101
}
99102

@@ -262,12 +265,15 @@ protected function getFileName(string $entryIdentifier): string
262265
try {
263266
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 14) {
264267
/** @var ResourceFactory $resourceFactory */
268+
// @phpstan-ignore-next-line
265269
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
266270
} else {
267271
/** @var StorageRepository $resourceFactory */
272+
// @phpstan-ignore-next-line
268273
$resourceFactory = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class);
269274
}
270275

276+
// @phpstan-ignore-next-line
271277
$storage = $resourceFactory->getDefaultStorage();
272278
$baseName = (string) $storage->sanitizeFileName($baseName);
273279
} catch (\Exception $exception) {
@@ -287,4 +293,20 @@ public function flushByTags(array $tags): void
287293
$this->flushByTag($tag);
288294
}
289295
}
296+
297+
/**
298+
* @see https://github.com/TYPO3/typo3/blob/13.4/typo3/sysext/core/Classes/Cache/Backend/AbstractBackend.php#L138 (method do not exists in v14 anymore)
299+
*/
300+
protected function calculateExpiryTimeInternal($lifetime = null)
301+
{
302+
if ($lifetime === self::UNLIMITED_LIFETIME_INTERNAL || $lifetime === null && $this->defaultLifetime === self::UNLIMITED_LIFETIME_INTERNAL) {
303+
$expiryTime = new \DateTime(self::DATETIME_EXPIRYTIME_UNLIMITED_INTERNAL, new \DateTimeZone('UTC'));
304+
} else {
305+
if ($lifetime === null) {
306+
$lifetime = $this->defaultLifetime;
307+
}
308+
$expiryTime = new \DateTime('now +' . $lifetime . ' seconds', new \DateTimeZone('UTC'));
309+
}
310+
return $expiryTime;
311+
}
290312
}

Classes/Cache/StaticFileBackend.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,6 @@ protected function processQueueRefill(CacheRepository $cacheRepository, QueueRep
237237
*/
238238
public function flushByTags(array $tags): void
239239
{
240-
$this->throwExceptionIfFrontendDoesNotExist();
241-
242240
if (empty($tags)) {
243241
return;
244242
}
@@ -275,8 +273,6 @@ public function flushByTags(array $tags): void
275273
*/
276274
public function flushByTag($tag): void
277275
{
278-
$this->throwExceptionIfFrontendDoesNotExist();
279-
280276
$this->logger->debug('SFC flushByTags', [$tag]);
281277
$identifiers = $this->findIdentifiersByTagIncludingExpired($tag);
282278

@@ -400,7 +396,6 @@ protected function findIdentifiersByTagsIncludingExpired(array $tags): array
400396
*/
401397
public function findIdentifiersByTags(array $tags)
402398
{
403-
$this->throwExceptionIfFrontendDoesNotExist();
404399
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
405400
->getQueryBuilderForTable($this->tagsTable);
406401
$result = $queryBuilder->select($this->cacheTable . '.identifier')

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ includes:
22
- phpstan-baseline.neon
33

44
parameters:
5-
level: 4
5+
level: 5
66
reportUnmatchedIgnoredErrors: false
77
paths:
88
- Classes

0 commit comments

Comments
 (0)