Skip to content

Commit

Permalink
Merge pull request #3 from astehlik/feature/typo3-12
Browse files Browse the repository at this point in the history
[FEATURE] TYPO3 12 compatibility
  • Loading branch information
astehlik committed May 5, 2024
2 parents efa43e1 + 5c4e81d commit e5df3b4
Show file tree
Hide file tree
Showing 27 changed files with 156 additions and 139 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/composer/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ inputs:
runs:
using: "composite"
steps:
- uses: actions/cache@v3
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.json') }}
- uses: php-actions/composer@v6
with:
php_version: ${{ inputs.php_version }}
php_extensions: zip
php_extensions: intl zip
- run: sudo chown -R $(id -u):$(id -g) .
shell: bash
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.3
extensions: intl, mbstring, json, zip, curl
tools: composer:v2

Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ name: test

on:
push:
branches:
- main
- develop
pull_request:
workflow_dispatch:
schedule:
- cron: '30 8 * * 6'

env:
TYPO3_EXTENSION_KEY: cacheopt
MAIN_PHP_VERSION: 8.2
MAIN_PHP_VERSION: 8.3

jobs:
"composer-validate":
Expand Down Expand Up @@ -62,7 +67,7 @@ jobs:
name: "PHP Unit tests"
strategy:
matrix:
php_version: ["7.4", "8.2"]
php_version: ["8.1", "8.3"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -98,7 +103,7 @@ jobs:
name: "PHP linting"
strategy:
matrix:
php_version: ["7.4", "8.0", "8.1", "8.2"]
php_version: ["8.1", "8.3"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -182,4 +187,4 @@ jobs:
- uses: shivammathur/setup-php@v2
with:
php-version: "${{ env.MAIN_PHP_VERSION }}"
- run: php .Build/bin/typo3scan scan --target 11 .
- run: php .Build/bin/typo3scan scan --target 12 .
16 changes: 8 additions & 8 deletions Classes/CacheOptimizerDataHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* The TYPO3 project - inspiring people to share! *
* */

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ArrayParameterType;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\DataHandling\DataHandler;
Expand Down Expand Up @@ -88,11 +88,11 @@ protected function getPidExcludeStatement(bool $neverExcludeRoot, QueryBuilder $

$pidQuery = $queryBuilder->expr()->notIn(
'pid',
$queryBuilder->createNamedParameter($flushedCachePids, Connection::PARAM_INT_ARRAY)
$queryBuilder->createNamedParameter($flushedCachePids, ArrayParameterType::INTEGER)
);

if ($neverExcludeRoot) {
$pidQuery = $queryBuilder->expr()->orX(
$pidQuery = $queryBuilder->expr()->or(
$pidQuery,
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))
);
Expand All @@ -114,17 +114,17 @@ protected function getTtContentWhereStatementForTable(string $table, QueryBuilde
if ($contentTypesForTable !== []) {
$orStatements[] = $queryBuilder->expr()->in(
'tt_content.CType',
$queryBuilder->createNamedParameter($contentTypesForTable, Connection::PARAM_STR_ARRAY)
$queryBuilder->createNamedParameter($contentTypesForTable, ArrayParameterType::STRING)
);
}

$pluginTypesForTable = $this->cacheOptimizerRegistry->getPluginTypesForTable($table);
if ($pluginTypesForTable !== []) {
$orStatements[] = $queryBuilder->expr()->andX(
$orStatements[] = $queryBuilder->expr()->and(
$queryBuilder->expr()->eq('tt_content.CType', $queryBuilder->createNamedParameter('list')),
$queryBuilder->expr()->in(
'tt_content.list_type',
$queryBuilder->createNamedParameter($pluginTypesForTable, Connection::PARAM_STR_ARRAY)
$queryBuilder->createNamedParameter($pluginTypesForTable, ArrayParameterType::STRING)
)
);
}
Expand All @@ -138,7 +138,7 @@ protected function getTtContentWhereStatementForTable(string $table, QueryBuilde
return;
}

$queryBuilder->andWhere($queryBuilder->expr()->orX(...$orStatements));
$queryBuilder->andWhere($queryBuilder->expr()->or(...$orStatements));
}

/**
Expand Down Expand Up @@ -185,7 +185,7 @@ protected function registerRelatedPluginPagesForCacheFlush(string $table): void
$this->getPidExcludeStatement(false, $queryBuilder);
$this->getTtContentWhereStatementForTable($table, $queryBuilder);

$pageUidResult = $queryBuilder->execute();
$pageUidResult = $queryBuilder->executeQuery();

while ($pageUid = (int)$pageUidResult->fetchOne()) {
$this->registerPageForCacheFlush($pageUid);
Expand Down
35 changes: 29 additions & 6 deletions Classes/CacheOptimizerFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,23 @@ protected function flushCacheForAllRegisteredTags(): void
}
}

protected function flushCacheForFolderFileCollection(int $fileCollectionUid): void
{
$this->registerRecordForCacheFlushing('sys_file_collection', $fileCollectionUid);

// Find content elements using this collection
$queryBuilder = $this->getQueryBuilderForTable('tt_content');
$queryBuilder->select('uid')
->from('tt_content')
->where($queryBuilder->expr()->eq('deleted', 0))
->andWhere($queryBuilder->expr()->inSet('file_collections', (string)$fileCollectionUid));

$result = $queryBuilder->executeQuery();
while ($contentElementUid = (int)$result->fetchOne()) {
$this->registerRecordForCacheFlushing('tt_content', $contentElementUid);
}
}

/**
* Searches for all records pointing to the given folder and flushes
* the related page caches.
Expand All @@ -219,17 +236,24 @@ protected function flushCacheForRelatedFolders(int $storageUid, string $folderId

$this->cacheOptimizerRegistry->registerProcessedFolder($storageUid, $folderIdentifier);

$combinedFolderIdentifier = $storageUid . ':' . $folderIdentifier;

$queryBuilder = $this->getQueryBuilderForTable('sys_file_collection');
$queryBuilder->select('uid')
->from('sys_file_collection')
->where($queryBuilder->expr()->eq('deleted', 0))
->andWhere('type', 'folder')
->andWhere('storage', $queryBuilder->createNamedParameter($storageUid, \PDO::PARAM_INT))
->andWhere('folder', $queryBuilder->createNamedParameter($folderIdentifier));
->andWhere($queryBuilder->expr()->eq('type', $queryBuilder->expr()->literal('folder')))
->andWhere(
$queryBuilder->expr()->eq(
'folder_identifier',
$queryBuilder->createNamedParameter($combinedFolderIdentifier)
)
);

$fileCollectionResult = $queryBuilder->executeQuery();

$fileCollectionResult = $queryBuilder->execute();
while ($fileCollectionUid = (int)$fileCollectionResult->fetchOne()) {
$this->registerRecordForCacheFlushing('sys_file_collection', $fileCollectionUid);
$this->flushCacheForFolderFileCollection($fileCollectionUid);
}
}

Expand All @@ -254,7 +278,6 @@ protected function registerRecordForCacheFlushing(string $table, int $uid): void
$this->flushCacheTags[] = $table . '_' . $uid;
}

/** @noinspection PhpSameParameterValueInspection */
private function getQueryBuilderForTable(string $tableName): QueryBuilder
{
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
Expand Down
60 changes: 30 additions & 30 deletions Tests/Functional/CacheOptimizerFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* */

use Tx\Cacheopt\CacheOptimizerFiles;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
use TYPO3\CMS\Core\Resource\DuplicationBehavior;
use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\Resource\StorageRepository;
Expand Down Expand Up @@ -54,7 +54,8 @@ protected function setUp(): void
$this->initFileProcessor();

$this->setUpBackendUserMain();
$GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageService::class);
$GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)
->createFromUserPreferences($GLOBALS['BE_USER']);
}

/**
Expand All @@ -67,17 +68,8 @@ public function testFileChangeClearsCacheForPagesReferencingToTheDirectory(): vo
$this->fillPageCache(self::PAGE_UID_REFERENCED_DIRECTORY);
$this->fillPageCache(self::PAGE_UID_REFERENCING_CONTENT_REFERENCING_DIRECTORY);

$fileValues = [
'editfile' => [
[
'data' => 'testcontent_modified_directory',
'target' => $this->getRootFolderIdentifier()
. ltrim(self::FILE_IDENTIFIER_REFERENCED_IN_DIRECTORY, '/'),
],
],
];
$this->uploadFile(dirname(self::FILE_IDENTIFIER_REFERENCED_IN_DIRECTORY) . '/new_uploaded_file.txt');

$this->processFileArrayAndFlushCache($fileValues);
$this->assertPageCacheIsEmpty(self::PAGE_UID_REFERENCED_DIRECTORY);
$this->assertPageCacheIsEmpty(self::PAGE_UID_REFERENCING_CONTENT_REFERENCING_DIRECTORY);
}
Expand Down Expand Up @@ -111,25 +103,8 @@ public function testFileUploadClearsCacheOfPageWhereOverwrittenFileIsReferenced(
{
$this->fillPageCache(self::PAGE_UID_REFERENCED_FILE);

$uploadPosition = 'file1';
$_FILES['upload_' . $uploadPosition] = [
'name' => basename(self::FILE_IDENTIFIER_REFERENCED),
'type' => 'text/plain',
'tmp_name' => $this->instancePath . '/typo3temp/uploadfiles/testfile_referenced.txt',
'size' => 31,
];

$fileValues = [
'upload' => [
[
'data' => $uploadPosition,
'target' => $this->getRootFolderIdentifier()
. ltrim(dirname(self::FILE_IDENTIFIER_REFERENCED), '/'),
],
],
];
$this->uploadFile(self::FILE_IDENTIFIER_REFERENCED);

$this->processFileArrayAndFlushCache($fileValues);
$this->assertPageCacheIsEmpty(self::PAGE_UID_REFERENCED_FILE);
}

Expand Down Expand Up @@ -166,6 +141,31 @@ protected function initFileProcessor(): void
protected function processFileArrayAndFlushCache(array $fileValues): void
{
$this->fileProcessor->start($fileValues);
// @extensionScannerIgnoreLine False positive.
$this->fileProcessor->processData();
}

protected function uploadFile(string $filePath): void
{
$uploadPosition = 'file1';

$_FILES['upload_' . $uploadPosition] = [
'name' => basename($filePath),
'type' => 'text/plain',
'tmp_name' => $this->instancePath . '/typo3temp/uploadfiles/testfile_referenced.txt',
'size' => 31,
];

$fileValues = [
'upload' => [
[
'data' => $uploadPosition,
'target' => $this->getRootFolderIdentifier()
. ltrim(dirname($filePath), '/'),
],
],
];

$this->processFileArrayAndFlushCache($fileValues);
}
}
21 changes: 7 additions & 14 deletions Tests/Functional/CacheOptimizerTestAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Tx\Cacheopt\Tests\Functional\Support\SiteBasedTestTrait;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\ActionService;
Expand All @@ -38,10 +38,8 @@ abstract class CacheOptimizerTestAbstract extends FunctionalTestCase

/**
* We want the folders containing the test files to be created.
*
* @var array
*/
protected $additionalFoldersToCreate = [
protected array $additionalFoldersToCreate = [
'/fileadmin/testdirectory',
'/fileadmin/testdirectory_referenced',
'/typo3temp/uploadfiles',
Expand All @@ -66,15 +64,10 @@ abstract class CacheOptimizerTestAbstract extends FunctionalTestCase
* We need to remove the additional configuration of our base class,
* otherwise the content renderer will not work properly and the cache
* will not be filled.
*
* @var array
*/
protected $pathsToLinkInTestInstance = [];
protected array $pathsToLinkInTestInstance = [];

/**
* @var array
*/
protected $testExtensionsToLoad = [
protected array $testExtensionsToLoad = [
'typo3conf/ext/cacheopt/Tests/Functional/Fixtures/Extensions/cacheopt_test',
'typo3conf/ext/cacheopt',
];
Expand Down Expand Up @@ -127,7 +120,7 @@ protected function assertPageCacheIsFilled(int $pageUid): void
$builder = $this->getQueryBuilderForSelect('cache_pages_tags');
$entryCount = (int)$builder->count('id')
->where($builder->expr()->eq('tag', $builder->createNamedParameter($cacheTag)))
->execute()
->executeQuery()
->fetchOne();

self::assertGreaterThanOrEqual(1, $entryCount, 'Page cache for page ' . $pageUid . ' is not filled.');
Expand Down Expand Up @@ -177,7 +170,7 @@ protected function fillPageCache(int $pageUid): void
protected function getActionService(): ActionService
{
$this->setUpBackendUserMain();
$GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageService::class);
$GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->createFromUserPreferences($GLOBALS['BE_USER']);
return GeneralUtility::makeInstance(ActionService::class);
}

Expand All @@ -199,7 +192,7 @@ protected function getPageCacheRecords(int $pageUid): array
)
->andWhere($builder->expr()->eq('tag', $builder->createNamedParameter($cacheTag)));

return $builder->execute()->fetchAssociative() ?: [];
return $builder->executeQuery()->fetchAssociative() ?: [];
}

/**
Expand Down
8 changes: 4 additions & 4 deletions Tests/Functional/Fixtures/Database/be_users.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
be_users,,,,,,,,,
,uid,pid,tstamp,username,password,crdate,cruser_id,workspace_perms,lastlogin
,2,0,1370009282,_cli_phpunit,3b39e927252519dbfc099ea16d7c1518,1370009282,1,1,1371033743
,4,0,1381919418,_cli_scheduler,$P$CsB4D0cK.qg8iyJAbp4l7Cs7UTyZGw1,1381919418,1,1,1371033743
,5,0,1382365029,_cli_lowlevel,$P$CsB4D0cK.qg8iyJAbp4l7Cs7UTyZGw1,1382365029,1,1,1371033743
,uid,pid,tstamp,username,password,crdate,workspace_perms,lastlogin
,2,0,1370009282,_cli_phpunit,3b39e927252519dbfc099ea16d7c1518,1370009282,1,1371033743
,4,0,1381919418,_cli_scheduler,$P$CsB4D0cK.qg8iyJAbp4l7Cs7UTyZGw1,1381919418,1,1371033743
,5,0,1382365029,_cli_lowlevel,$P$CsB4D0cK.qg8iyJAbp4l7Cs7UTyZGw1,1382365029,1,1371033743
28 changes: 14 additions & 14 deletions Tests/Functional/Fixtures/Database/pages.csv
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
pages,,,,,,,,,
,uid,pid,crdate,tstamp,cruser_id,title,sorting,doktype,is_siteroot
,128,0,1401290268,1401290272,1,root,256,1,1
,129,128,1401291877,1401291979,1,normal_page,256,1,0
,130,128,1401291975,1401291975,1,page_referencing_file,512,1,0
,131,128,1401291975,1401291975,1,page_referencing_directory,768,1,0
,1310,128,1401291975,1401291975,1,page_referencing_content_referencing_directory,768,1,0
,132,128,1401291975,1401291975,1,page_referenced_in_menu,1024,1,0
,133,128,1401291975,1401291975,1,page_containing_menu,1280,1,0
,134,128,1401291975,1401390460,1,page_containing_ext_plugin,1536,1,0
,135,128,1401291975,1401291975,1,plugin_records,1792,254,0
,136,128,1401390439,1401390456,1,page_containing_ext_content,1664,1,0
,137,128,1401434680,1401434688,1,page_referencing_content,384,1,0
,138,128,1401434680,1401434688,1,page_containing_subpages,384,1,0
,139,138,1401434680,1401434688,1,page_referenced_in_menu_in_sublevel,384,1,0
,uid,pid,crdate,tstamp,title,sorting,doktype,is_siteroot
,128,0,1401290268,1401290272,root,256,1,1
,129,128,1401291877,1401291979,normal_page,256,1,0
,130,128,1401291975,1401291975,page_referencing_file,512,1,0
,131,128,1401291975,1401291975,page_referencing_directory,768,1,0
,1310,128,1401291975,1401291975,page_referencing_content_referencing_directory,768,1,0
,132,128,1401291975,1401291975,page_referenced_in_menu,1024,1,0
,133,128,1401291975,1401291975,page_containing_menu,1280,1,0
,134,128,1401291975,1401390460,page_containing_ext_plugin,1536,1,0
,135,128,1401291975,1401291975,plugin_records,1792,254,0
,136,128,1401390439,1401390456,page_containing_ext_content,1664,1,0
,137,128,1401434680,1401434688,page_referencing_content,384,1,0
,138,128,1401434680,1401434688,page_containing_subpages,384,1,0
,139,138,1401434680,1401434688,page_referenced_in_menu_in_sublevel,384,1,0
4 changes: 2 additions & 2 deletions Tests/Functional/Fixtures/Database/sys_file_collection.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sys_file_collection,,,,,,,,,
,uid,pid,crdate,tstamp,cruser_id,title,type,storage,folder
,1,131,1401292072,1401292050,1,testdirectory,folder,1,/testdirectory_referenced/
,uid,pid,crdate,tstamp,title,type,folder_identifier
,1,131,1401292072,1401292050,testdirectory,folder,1:/testdirectory_referenced/

0 comments on commit e5df3b4

Please sign in to comment.