Skip to content

Commit afdf769

Browse files
committed
Migrate to TYPO3 v14
Support for TYPO3 v12 and v13 needs to be dropped, since we need can not ship a cache backend that supports v13 and v14 and the new implementation uses many request attributes that have been added in v14.
1 parent 471fafe commit afdf769

20 files changed

Lines changed: 209 additions & 470 deletions

File tree

.build/packages/cache_status/Classes/CacheHit.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
use Psr\Http\Server\MiddlewareInterface;
1010
use Psr\Http\Server\RequestHandlerInterface;
1111
use TYPO3\CMS\Core\Http\NullResponse;
12-
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
1312

14-
final class CacheHit implements MiddlewareInterface
13+
final readonly class CacheHit implements MiddlewareInterface
1514
{
1615
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
1716
{
@@ -21,21 +20,14 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
2120
return $response;
2221
}
2322

24-
$tsfe = $request->getAttribute('frontend.controller', $GLOBALS['TSFE'] ?? null);
25-
if (!$tsfe instanceof TypoScriptFrontendController) {
26-
return $response;
27-
}
28-
2923
return $response->withHeader(
3024
'X-TYPO3-Cache',
31-
$this->hitCache($tsfe) ? 'HIT' : 'MISS'
25+
$this->hitCache($request) ? 'HIT' : 'MISS'
3226
);
3327
}
3428

35-
private function hitCache(TypoScriptFrontendController $tsfe): bool
29+
private function hitCache(ServerRequestInterface $request): bool
3630
{
37-
return call_user_func(\Closure::bind(function() use ($tsfe) {
38-
return $tsfe->pageContentWasLoadedFromCache ?? $tsfe->cacheContentFlag ?? false;
39-
}, null, $tsfe));
31+
return $request->getAttribute('frontend.page.parts')?->hasPageContentBeenLoadedFromCache() ?? false;
4032
}
4133
}

.build/packages/cache_status/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
],
1717
"license": "GPL-2.0+",
1818
"require": {
19-
"typo3/cms-core": "^12.4.0 || ^13.0.0 || dev-main"
19+
"typo3/cms-core": "^12.4 || ^13.0 || ^14.2 || dev-main"
2020
},
2121
"autoload": {
2222
"psr-4": {

.build/packages/cache_status/ext_emconf.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

.build/v12/composer.json

Lines changed: 0 additions & 26 deletions
This file was deleted.

.build/v13/config/system/additional.php

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
"bnf/cache-status": "@dev",
1616
"bnf/nginx-cache": "@dev",
1717
"cweagans/composer-patches": "^1.7",
18-
"typo3/cms-adminpanel": "13.4.x-dev as 13.4.0",
19-
"typo3/cms-backend": "13.4.x-dev as 13.4.0",
20-
"typo3/cms-core": "13.4.x-dev as 13.4.0",
21-
"typo3/cms-extbase": "13.4.x-dev as 13.4.0",
22-
"typo3/cms-filelist": "13.4.x-dev as 13.4.0",
23-
"typo3/cms-fluid": "13.4.x-dev as 13.4.0",
24-
"typo3/cms-frontend": "13.4.x-dev as 13.4.0",
25-
"typo3/cms-install": "13.4.x-dev as 13.4.0"
18+
"typo3/cms-adminpanel": "14.3.x-dev as 14.2.0",
19+
"typo3/cms-backend": "14.3.x-dev as 14.2.0",
20+
"typo3/cms-core": "14.3.x-dev as 14.2.0",
21+
"typo3/cms-extbase": "14.3.x-dev as 14.2.0",
22+
"typo3/cms-filelist": "14.3.x-dev as 14.2.0",
23+
"typo3/cms-fluid": "14.3.x-dev as 14.2.0",
24+
"typo3/cms-frontend": "14.3.x-dev as 14.2.0",
25+
"typo3/cms-install": "14.3.x-dev as 14.2.0"
2626
},
2727
"config": {
2828
"allow-plugins": {
File renamed without changes.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
"require": {
1515
"bnf/cache-status": "@dev",
1616
"bnf/nginx-cache": "@dev",
17-
"typo3/cms-adminpanel": "^13.1",
18-
"typo3/cms-install": "^13.1",
19-
"typo3/minimal": "^13.1"
17+
"typo3/cms-adminpanel": "^14.2",
18+
"typo3/cms-install": "^14.2",
19+
"typo3/minimal": "^14.0"
2020
},
2121
"config": {
2222
"allow-plugins": {
File renamed without changes.

Classes/Cache/Backend/NginxCacheBackend.php

Lines changed: 43 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -21,63 +21,39 @@
2121
use TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend;
2222
use TYPO3\CMS\Core\Cache\Exception;
2323
use TYPO3\CMS\Core\Cache\Exception\InvalidDataException;
24+
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
2425
use TYPO3\CMS\Core\Core\Environment;
2526
use TYPO3\CMS\Core\Http\RequestFactory;
2627
use TYPO3\CMS\Core\Utility\GeneralUtility;
2728

28-
class NginxCacheBackend extends Typo3DatabaseBackend implements TransientBackendInterface
29+
final readonly class NginxCacheBackend implements TransientBackendInterface
2930
{
30-
/**
31-
* Saves data in a cache file.
32-
*
33-
* @param string $entryIdentifier An identifier for this specific cache entry
34-
* @param string $data The data to be stored
35-
* @param array $tags Tags to associate with this cache entry
36-
* @param int $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited liftime.
37-
* @return void
38-
* @throws Exception if no cache frontend has been set.
39-
* @throws InvalidDataException if the data to be stored is not a string.
40-
*/
41-
public function set($entryIdentifier, $data, array $tags = array(), $lifetime = null)
42-
{
43-
parent::set($entryIdentifier, $data, $tags, $lifetime);
31+
private Typo3DatabaseBackend $backend;
4432

45-
if ($lifetime === 0) {
46-
// unlimited is not supported by nginx
47-
$lifetime = 24 * 60 * 60;
48-
}
33+
public function __construct()
34+
{
35+
$this->backend = new Typo3DatabaseBackend();
36+
}
4937

50-
/* Note: We use an explicit opt-in strategy to define requests as cachable.
51-
* That means this functionality relies on the "fastcgi_cache_valid 0"
52-
* in nginx.conf as documented in README.rst */
53-
header('X-Accel-Expires: ' . $lifetime);
38+
public function set(string $entryIdentifier, mixed $data, array $tags = [], ?int $lifetime = null): void
39+
{
40+
$this->backend->set($entryIdentifier, $data, $tags, $lifetime);
5441
}
5542

56-
/**
57-
* Removes all cache entries matching the specified identifier.
58-
*
59-
* @param string $entryIdentifier Specifies the cache entry to remove
60-
* @return bool TRUE if (at least) an entry could be removed or FALSE if no entry was found
61-
*/
62-
public function remove($entryIdentifier)
43+
public function remove(string $entryIdentifier): bool
6344
{
64-
$url = parent::get($entryIdentifier);
45+
$url = $this->backend->get($entryIdentifier);
6546
if ($url === false) {
6647
/* The key is not available. Do nothing. */
6748
return false;
6849
}
6950

7051
$this->purge($url);
7152

72-
return parent::remove($entryIdentifier);
53+
return $this->backend->remove($entryIdentifier);
7354
}
7455

75-
/**
76-
* Removes all cache entries of this cache.
77-
*
78-
* @return void
79-
*/
80-
public function flush()
56+
public function flush(): void
8157
{
8258
/* FIXME: this won't work for cli requests. We could try do derive the site_url from
8359
* existing cache entries (using findIdentifierByTag?).
@@ -89,16 +65,10 @@ public function flush()
8965
$url = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . '*';
9066
$this->purge($url);
9167

92-
parent::flush();
68+
$this->backend->flush();
9369
}
9470

95-
/**
96-
* Removes all cache entries of this cache which are tagged by the specified tag.
97-
*
98-
* @param string $tag The tag the entries must have
99-
* @return void
100-
*/
101-
public function flushByTag($tag)
71+
public function flushByTag(string $tag): void
10272
{
10373
$identifiers = $this->findIdentifiersByTag($tag);
10474
foreach ($identifiers as $identifier) {
@@ -107,12 +77,9 @@ public function flushByTag($tag)
10777
}
10878

10979
/**
110-
* Removes all cache entries of this cache which are tagged by any of the specified tags.
111-
*
112-
* @param string[] $tags List of tags
113-
* @return void
80+
* @param list<string> $tasgs
11481
*/
115-
public function flushByTags(array $tags)
82+
public function flushByTags(array $tags): void
11683
{
11784
array_walk($tags, [$this, 'flushByTag']);
11885
}
@@ -150,4 +117,29 @@ protected function purge(string $url): string
150117

151118
return $content;
152119
}
120+
121+
public function get(string $entryIdentifier): mixed
122+
{
123+
return $this->backend->get($entryIdentifier);
124+
}
125+
126+
public function has(string $entryIdentifier): bool
127+
{
128+
return $this->backend->has($entryIdentifier);
129+
}
130+
131+
public function collectGarbage(): void
132+
{
133+
$this->backend->collectGarbage();
134+
}
135+
136+
public function setCache(FrontendInterface $cache): void
137+
{
138+
$this->backend->setCache($cache);
139+
}
140+
141+
public function getTableDefinitions(): string
142+
{
143+
return $this->backend->getTableDefinitions();
144+
}
153145
}

0 commit comments

Comments
 (0)