Skip to content

Commit

Permalink
Support TYPO3 v13.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bnf committed Jan 30, 2024
1 parent f14e48e commit cc22d69
Show file tree
Hide file tree
Showing 24 changed files with 283 additions and 50 deletions.
12 changes: 7 additions & 5 deletions .build/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/composer.lock
/config/sites/
/var
/public
/vendor
v*/composer.lock
v*/config/system/settings.php
v*/config/sites/
v*/var
v*/public
v*/vendor
/assert*.sh
/public
1 change: 0 additions & 1 deletion .build/config/system/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion .build/packages/cache_status/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
"license": "GPL-2.0+",
"require": {
"typo3/cms-core": "^12.4.0"
"typo3/cms-core": "^12.4.0 || ~13.0.0 || dev-main"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 2 additions & 1 deletion .build/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
DIR=$(realpath $(dirname "$0"))
ROOT=$(realpath "$DIR/..")
HOST="${DDEV_PRIMARY_URL}"
PREFIX="${1:-v12}"

make -C ${ROOT} .build/assert-1.1.sh

Expand All @@ -12,7 +13,7 @@ source $DIR/assert.sh
cookiefile=/tmp/nginx_cache-backend.cookie

function clear_cache() {
$ROOT/.build/vendor/bin/typo3 cache:flush
$ROOT/.build/${PREFIX}/vendor/bin/typo3 cache:flush
curl -X PURGE "${HOST}/*"
}

Expand Down
19 changes: 13 additions & 6 deletions .build/setup-typo3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

set -ve

rm -rf \
.build/config/sites/ \
.build/config/system/settings.php \
.build/composer.lock \
.build/public/ \
.build/vendor/
prefix=${1}

cd .build/
ln -snf ${1}/public public

cd ${prefix}

rm -rf \
config/sites/ \
config/system/settings.php \
composer.lock \
public/ \
vendor/

composer install

TYPO3_DB_USERNAME=db \
Expand All @@ -18,6 +24,7 @@ TYPO3_DB_HOST=db \
TYPO3_DB_DBNAME=db \
TYPO3_DB_PASSWORD=db \
TYPO3_DB_DRIVER=mysqli \
TYPO3_SERVER_TYPE=other \
[email protected] \
TYPO3_SETUP_ADMIN_USERNAME=admin \
TYPO3_SETUP_ADMIN_PASSWORD='Pa$$w0rd' \
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions .build/composer.json → .build/v12/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
"repositories": [
{
"type": "path",
"url": "../"
"url": "../../"
},
{
"type": "path",
"url": "./packages/*/"
"url": "../packages/*/"
}
],
"license": "GPL-2.0+",
"require": {
"bnf/cache-status": "@dev",
"bnf/nginx-cache": "@dev",
"typo3/cms-adminpanel": "^12.4.0 || dev-main",
"typo3/minimal": "^12.4.0 || dev-main"
"typo3/cms-adminpanel": "^12.4",
"typo3/minimal": "^12.4"
},
"config": {
"allow-plugins": {
Expand Down
1 change: 1 addition & 0 deletions .build/v12/config/system/additional.php
35 changes: 35 additions & 0 deletions .build/v13-dev/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "bnf/nginx-cache-test-site",
"repositories": [
{
"type": "path",
"url": "../../"
},
{
"type": "path",
"url": "../packages/*/"
}
],
"license": "GPL-2.0+",
"require": {
"bnf/cache-status": "@dev",
"bnf/nginx-cache": "@dev",
"cweagans/composer-patches": "^1.7",
"doctrine/dbal": "4.0.0-RC2@rc",
"typo3/cms-adminpanel": "13.1.x-dev as 13.0.0",
"typo3/cms-backend": "13.1.x-dev as 13.0.0",
"typo3/cms-core": "13.1.x-dev as 13.0.0",
"typo3/cms-extbase": "13.1.x-dev as 13.0.0",
"typo3/cms-filelist": "13.1.x-dev as 13.0.0",
"typo3/cms-fluid": "13.1.x-dev as 13.0.0",
"typo3/cms-frontend": "13.1.x-dev as 13.0.0",
"typo3/cms-install": "13.1.x-dev as 13.0.0"
},
"config": {
"allow-plugins": {
"typo3/class-alias-loader": true,
"typo3/cms-composer-installers": true,
"cweagans/composer-patches": false
}
}
}
1 change: 1 addition & 0 deletions .build/v13-dev/config/system/additional.php
38 changes: 38 additions & 0 deletions .build/v13/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "bnf/nginx-cache-test-site",
"repositories": [
{
"type": "path",
"url": "../../"
},
{
"type": "path",
"url": "../packages/*/"
}
],
"license": "GPL-2.0+",
"require": {
"bnf/cache-status": "@dev",
"bnf/nginx-cache": "@dev",
"cweagans/composer-patches": "^1.7",
"doctrine/dbal": "4.0.0-RC2@rc",
"typo3/cms-adminpanel": "~13.0.0",
"typo3/cms-install": "~13.0.0",
"typo3/minimal": "~13.0.0"
},
"extra": {
"composer-exit-on-patch-failure": true,
"patches": {
"typo3/cms-install": {
"[BUGFIX] Cast database port to int in setup command": "patches/f5296972ae7-install.patch"
}
}
},
"config": {
"allow-plugins": {
"typo3/class-alias-loader": true,
"typo3/cms-composer-installers": true,
"cweagans/composer-patches": true
}
}
}
1 change: 1 addition & 0 deletions .build/v13/config/system/additional.php
86 changes: 86 additions & 0 deletions .build/v13/patches/f5296972ae7-install.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
diff --git a/Classes/Command/SetupCommand.php b/Classes/Command/SetupCommand.php
index a52afe5c1fb..aaec25928d3 100644
--- a/Classes/Command/SetupCommand.php
+++ b/Classes/Command/SetupCommand.php
@@ -432,7 +432,6 @@ EOT
$default = $this->getDefinition()->getOption($key)->getDefault();
$defaultLabel = empty($value) ? '' : ' [default: ' . $default . ']';
$question = new Question('Enter the database "' . $key . '"' . $defaultLabel . ' ? ', $default);
-
if ($key === 'password') {
$question = new Question('Enter the database "' . $key . '" ? ', $default);
$question->setHidden(true);
@@ -445,19 +444,18 @@ EOT
1669747572
);
}
-
return $host;
};
$question->setValidator($hostValidator);
} elseif ($key === 'port') {
$portValidator = function ($port) {
- if (!$this->setupDatabaseService->isValidDbPort((int)$port)) {
+ $port = (int)$port;
+ if (!$this->setupDatabaseService->isValidDbPort($port)) {
throw new \RuntimeException(
'Please use a port in the range between 1 and 65535.',
1669747592,
);
}
-
return $port;
};
$question->setValidator($portValidator);
@@ -469,12 +467,10 @@ EOT
1669747601,
);
}
-
return $value;
};
$question->setValidator($emptyValidator);
}
-
if ($envValue === false && $key === 'password') {
// Force this question if no `TYPO3_DB_PASSWORD` set via cli.
// Thus, the user will always be prompted for a password even --no-interaction is set.
@@ -491,7 +487,6 @@ EOT
$envValue = $envValue ?: $default;
$value = $validator ? $validator($envValue) : $envValue;
}
-
$databaseConnectionOptions[$key] = $value;
}
}
diff --git a/Classes/Service/SetupDatabaseService.php b/Classes/Service/SetupDatabaseService.php
index 11714d955ce..85ebd65ffff 100644
--- a/Classes/Service/SetupDatabaseService.php
+++ b/Classes/Service/SetupDatabaseService.php
@@ -597,7 +597,7 @@ class SetupDatabaseService
'driver' => 'mysqli',
'username' => $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['user'] ?? '',
'password' => $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['password'] ?? '',
- 'port' => $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['port'] ?? 3306,
+ 'port' => (int)($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['port'] ?? 3306),
'database' => $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['dbname'] ?? '',
];
$host = $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['host'] ?? '127.0.0.1';
@@ -629,7 +629,7 @@ class SetupDatabaseService
'driver' => 'pdo_mysql',
'username' => $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['user'] ?? '',
'password' => $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['password'] ?? '',
- 'port' => $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['port'] ?? 3306,
+ 'port' => (int)($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['port'] ?? 3306),
'database' => $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['dbname'] ?? '',
];
$host = $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['host'] ?? '127.0.0.1';
@@ -666,7 +666,7 @@ class SetupDatabaseService
'username' => $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['user'] ?? '',
'password' => $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['password'] ?? '',
'host' => $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['host'] ?? '127.0.0.1',
- 'port' => $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['port'] ?? 5432,
+ 'port' => (int)($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['port'] ?? 5432),
'database' => $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['dbname'] ?? '',
];
if (($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['driver'] ?? '') === 'pdo_pgsql') {
3 changes: 3 additions & 0 deletions .ddev/commands/web/clean-db
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
mysql -Bs --execute='drop database if exists db' ''
mysql -Bs --execute='create database db' ''
2 changes: 1 addition & 1 deletion .ddev/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: nginx-cache
type: typo3
docroot: .build/public
php_version: "8.1"
php_version: "8.2"
webserver_type: nginx-fpm
router_http_port: "80"
router_https_port: "443"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ jobs:
steps:
- uses: actions/checkout@v1
- uses: ddev/github-action-setup-ddev@v1
- run: make ddev-12
- run: make check
56 changes: 50 additions & 6 deletions Classes/Hooks/PageLoadedFromCacheHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Event\AfterTypoScriptDeterminedEvent;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;


class PageLoadedFromCacheHook
{
use RequestAwareTrait;
Expand All @@ -37,12 +37,56 @@ public function __construct(FrontendInterface $nginxCache)
$this->nginxCache = $nginxCache;
}

/**
* v13.0 event
*/
public function handleEvent(AfterTypoScriptDeterminedEvent $event): void
{
$tsfe = $this->getTypoScriptFrontendController();
// @todo $tsfe->pageContentWasLoadedFromCache is protected and $tsfe->isGeneratePage() is internal
if ($tsfe->isGeneratePage()) {
return;
}

$pageCacheTags = $tsfe->getPageCacheTags();
if (!in_array('nginx-cache-later-cacheable', $pageCacheTags, true)) {
return;
}

$request = $this->getServerRequest();
$uri = $this->getUri($request);

$context = GeneralUtility::makeInstance(Context::class);

$frontendTypoScript = $event->getFrontendTypoScript();
$cachable = (
$tsfe->isStaticCacheble($request) &&
$context->getPropertyFromAspect('workspace', 'isOffline', false) === false &&
strpos($uri, '?') === false &&
$this->isAdminPanelVisible($frontendTypoScript) === false &&
$this->isFrontendEditingActive($tsfe) === false &&
$request->getMethod() === 'GET'
);

if (!$cachable) {
return;
}

// @todo This is ugly because $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['pageLoadedFromCache'] was removed in v13 without replacement,
// and TSFE does not provide public access to current cache expiry timestamp
$cacheExpires = \Closure::bind(static fn() => $tsfe->cacheExpires, null, TypoScriptFrontendController::class);
$lifetime = $cacheExpires()- $context->getPropertyFromAspect('date', 'timestamp');
$this->nginxCache->set(md5($uri), $uri, $pageCacheTags, $lifetime);
}

/**
* v12 hook
*/
public function loadedFromCache(array &$params, TypoScriptFrontendController $tsfe): void
{
$row = $params['cache_pages_row'] ?? [];

$nginxCacheTags = $row['tx_nginx_cache_tags'] ?? null;
if ($nginxCacheTags === null) {
$pageCacheTags = $row['cacheTags'] ?? [];
if (!in_array('nginx-cache-later-cacheable', $pageCacheTags, true)) {
return;
}

Expand All @@ -55,7 +99,7 @@ public function loadedFromCache(array &$params, TypoScriptFrontendController $ts

$context = GeneralUtility::makeInstance(Context::class);
$cachable = (
$tsfe->isStaticCacheble($request) &&
$tsfe->isStaticCacheble() &&
$context->getPropertyFromAspect('workspace', 'isOffline', false) === false &&
strpos($uri, '?') === false &&
$this->isAdminPanelVisible() === false &&
Expand All @@ -68,6 +112,6 @@ public function loadedFromCache(array &$params, TypoScriptFrontendController $ts
}

$lifetime = $row['expires'] - $context->getPropertyFromAspect('date', 'timestamp');
$this->nginxCache->set(md5($uri), $uri, $nginxCacheTags, $lifetime);
$this->nginxCache->set(md5($uri), $uri, $pageCacheTags, $lifetime);
}
}
Loading

0 comments on commit cc22d69

Please sign in to comment.