From e4c3b5fe86599c0ac5fff94a03f8cc15739f76e9 Mon Sep 17 00:00:00 2001 From: Benjamin Kott Date: Wed, 12 Oct 2022 10:10:01 +0200 Subject: [PATCH] [TASK] Make Bootstrap Package TYPO3 v12 compatible (#1201) --- .ddev/config.yaml | 6 +- .github/workflows/ci.yml | 13 ++- .gitignore | 4 +- .phplint.yml | 2 + Build/phpstan-baseline.neon | 22 ++++- Build/phpstan.neon | 4 + Build/phpunit-unit.xml | 1 - Classes/Updates/AbstractUpdate.php | 23 +---- .../ViewHelpers/Data/PaginateViewHelper.php | 85 +++++++++++-------- .../ViewHelpers/Link/PaginateViewHelper.php | 6 +- README.rst | 11 ++- Tests/Functional/Parser/ScssParserTest.php | 2 +- composer.json | 52 ++++++------ 13 files changed, 127 insertions(+), 104 deletions(-) diff --git a/.ddev/config.yaml b/.ddev/config.yaml index 11bb1f71c..fa84cb828 100644 --- a/.ddev/config.yaml +++ b/.ddev/config.yaml @@ -1,7 +1,7 @@ name: bootstrap-package -type: typo3 +type: php docroot: .build/public -php_version: "7.4" +php_version: "8.1" webserver_type: apache-fpm router_http_port: "80" router_https_port: "443" @@ -260,5 +260,3 @@ nodejs_version: "16" # information on the commands that can be extended and the tasks you can define # for them. Example: #hooks: -# post-start: -# - exec: composer install -d /var/www/html diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d6cab5569..5fbdc89a5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,9 +17,18 @@ jobs: fail-fast: false max-parallel: 4 matrix: - typo3: ['^11'] + typo3: ['^11', '^12'] php: ['7.4', '8.0', '8.1'] mysql: ['5.7', '8.0'] + exclude: + - typo3: '^11' + mysql: '8.0' + - typo3: '^12' + mysql: '5.7' + - typo3: '^12' + php: '7.4' + - typo3: '^12' + php: '8.0' steps: - id: checkout @@ -78,7 +87,7 @@ jobs: composer test:php:unit - id: tests_functional name: Functional Tests - if: ${{ always() && steps.install.conclusion == 'success' }} + if: ${{ always() && steps.install.conclusion == 'success' && matrix.typo3 == '^11' }} run: | composer test:php:functional env: diff --git a/.gitignore b/.gitignore index 5b2cc518d..5e1f522bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ .build -.ddev/docker-compose.tempfs.yaml Build/node_modules/* composer.lock *.cache nbproject /Documentation-GENERATED-temp/ + +config/ +var/ diff --git a/.phplint.yml b/.phplint.yml index cc3c4fe92..9dadd310b 100644 --- a/.phplint.yml +++ b/.phplint.yml @@ -5,3 +5,5 @@ extensions: - php exclude: - .build + - config + - var diff --git a/Build/phpstan-baseline.neon b/Build/phpstan-baseline.neon index 98f9f1b01..47263932a 100644 --- a/Build/phpstan-baseline.neon +++ b/Build/phpstan-baseline.neon @@ -1,17 +1,35 @@ parameters: ignoreErrors: + - + message: """ + #^Fetching class constant class of deprecated class TYPO3\\\\CMS\\\\Core\\\\TypoScript\\\\Parser\\\\TypoScriptParser\\: + This class should not be used anymore, last core usages will be removed during v12\\. + Using methods or properties of this class will start logging deprecation messages\\.$# + """ + count: 1 + path: ../Classes/DataProcessing/ConstantsProcessor.php + + - + message: """ + #^Return type of method BK2K\\\\BootstrapPackage\\\\Hooks\\\\PageRenderer\\\\GoogleFontHook\\:\\:getTemplateService\\(\\) has typehint with deprecated class TYPO3\\\\CMS\\\\Core\\\\TypoScript\\\\TemplateService\\: + This class should not be used anymore, last core usages will be removed during v12\\. + Using methods or properties of this class will start logging deprecation messages\\.$# + """ + count: 1 + path: ../Classes/Hooks/PageRenderer/GoogleFontHook.php + - message: "#^Variable method call on \\$this\\(BK2K\\\\BootstrapPackage\\\\Utility\\\\ExternalMediaUtility\\)\\.$#" count: 1 path: ../Classes/Utility/ExternalMediaUtility.php - - message: "#^Variable property access on SimpleXMLElement\\.$#" + message: "#^Call to deprecated function libxml_disable_entity_loader\\(\\)\\.$#" count: 2 path: ../Classes/Utility/SvgUtility.php - - message: "#^Call to deprecated function libxml_disable_entity_loader\\(\\)\\.$#" + message: "#^Variable property access on SimpleXMLElement\\.$#" count: 2 path: ../Classes/Utility/SvgUtility.php diff --git a/Build/phpstan.neon b/Build/phpstan.neon index 33921b627..2a1c00dda 100644 --- a/Build/phpstan.neon +++ b/Build/phpstan.neon @@ -12,6 +12,10 @@ parameters: ignoreErrors: - "#Casting to string something that's already string.#" + - """ + #^Call to deprecated method getFileFieldTCAConfig\\(\\) of class TYPO3\\\\CMS\\\\Core\\\\Utility\\\\ExtensionManagementUtility\\: + since TYPO3 v12\\.0\\. Use the TCA type "file" directly$# + """ paths: - %currentWorkingDirectory%/Classes/ diff --git a/Build/phpunit-unit.xml b/Build/phpunit-unit.xml index faf8f1477..9e3d30a69 100644 --- a/Build/phpunit-unit.xml +++ b/Build/phpunit-unit.xml @@ -3,7 +3,6 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="true" - bootstrap="../.build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTestsBootstrap.php" colors="true" convertErrorsToExceptions="true" convertWarningsToExceptions="true" diff --git a/Classes/Updates/AbstractUpdate.php b/Classes/Updates/AbstractUpdate.php index 05b9c3738..0af3ce1b3 100644 --- a/Classes/Updates/AbstractUpdate.php +++ b/Classes/Updates/AbstractUpdate.php @@ -14,7 +14,6 @@ use BK2K\BootstrapPackage\Updates\Criteria\EqualStringCriteria; use BK2K\BootstrapPackage\Updates\Criteria\InCriteria; use BK2K\BootstrapPackage\Updates\Criteria\LikeCriteria; -use Doctrine\DBAL\Result; use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\QueryBuilder; @@ -87,12 +86,7 @@ protected function createQueryBuilder(): QueryBuilder protected function tableHasColumn(string $column): bool { - /** @phpstan-ignore-next-line */ - if (method_exists($this->getConnection(), 'createSchemaManager')) { - $schemaManager = $this->getConnection()->createSchemaManager(); - } else { - $schemaManager = $this->getConnection()->getSchemaManager(); - } + $schemaManager = $this->getConnection()->createSchemaManager(); $tableColumns = $schemaManager->listTableColumns($this->table); if (array_key_exists($column, $tableColumns)) { @@ -136,13 +130,7 @@ protected function getRecordsByCriteria(QueryBuilder $queryBuilder, array $crite $queryBuilder->orWhere(...$criteria); } - /** @phpstan-ignore-next-line */ - if (method_exists($queryBuilder, 'executeQuery')) { - $result = $queryBuilder->executeQuery(); - } else { - /** @var Result $result */ - $result = $queryBuilder->execute(); - } + $result = $queryBuilder->executeQuery(); return $result->fetchAllAssociative(); } @@ -157,11 +145,6 @@ protected function updateRecord(int $uid, array $values): void $queryBuilder->set($field, $value); } - /** @phpstan-ignore-next-line */ - if (method_exists($queryBuilder, 'executeStatement')) { - $queryBuilder->executeStatement(); - } else { - $queryBuilder->execute(); - } + $queryBuilder->executeStatement(); } } diff --git a/Classes/ViewHelpers/Data/PaginateViewHelper.php b/Classes/ViewHelpers/Data/PaginateViewHelper.php index 12d7cd9fe..963efa683 100644 --- a/Classes/ViewHelpers/Data/PaginateViewHelper.php +++ b/Classes/ViewHelpers/Data/PaginateViewHelper.php @@ -9,6 +9,7 @@ namespace BK2K\BootstrapPackage\ViewHelpers\Data; +use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Pagination\ArrayPaginator; use TYPO3\CMS\Core\Pagination\SimplePagination; @@ -48,52 +49,62 @@ public function render(): string { /** @var RenderingContext $renderingContext */ $renderingContext = $this->renderingContext; - $request = $renderingContext->getRequest(); - $objects = $this->arguments['objects']; - if (!($objects instanceof QueryResultInterface || is_array($objects))) { - throw new \UnexpectedValueException('Supplied file object type ' . get_class($objects) . ' must be QueryResultInterface or be an array.', 1623322979); - } + /** @var ServerRequestInterface|null $request */ + $request = $renderingContext->getRequest(); - $configuration = [ - 'itemsPerPage' => 10, - 'insertAbove' => false, - 'insertBelow' => true, - 'section' => '' - ]; - ArrayUtility::mergeRecursiveWithOverrule($configuration, $this->arguments['configuration'], false); + /** @phpstan-ignore-next-line */ + if ($request instanceof ServerRequestInterface) { + $objects = $this->arguments['objects']; + if (!($objects instanceof QueryResultInterface || is_array($objects))) { + throw new \UnexpectedValueException('Supplied file object type ' . get_class($objects) . ' must be QueryResultInterface or be an array.', 1623322979); + } - $id = $this->arguments['id']; - $itemsPerPage = (int) $configuration['itemsPerPage']; - $currentPage = (int) ($request->getQueryParams()['paginate'][$id]['page'] ?? 1); + $configuration = [ + 'itemsPerPage' => 10, + 'insertAbove' => false, + 'insertBelow' => true, + 'section' => '' + ]; + ArrayUtility::mergeRecursiveWithOverrule($configuration, $this->arguments['configuration'], false); + + $id = $this->arguments['id']; + $itemsPerPage = (int) $configuration['itemsPerPage']; + $currentPage = (int) ($request->getQueryParams()['paginate'][$id]['page'] ?? 1); + + if ($objects instanceof QueryResultInterface) { + $paginator = new QueryResultPaginator($objects, $currentPage, $itemsPerPage); + } else { + $paginator = new ArrayPaginator($objects, $currentPage, $itemsPerPage); + } + $pagination = new SimplePagination($paginator); - if ($objects instanceof QueryResultInterface) { - $paginator = new QueryResultPaginator($objects, $currentPage, $itemsPerPage); - } else { - $paginator = new ArrayPaginator($objects, $currentPage, $itemsPerPage); - } - $pagination = new SimplePagination($paginator); + $paginationView = $this->getTemplateObject($renderingContext); + $paginationView->assignMultiple([ + 'id' => $id, + 'paginator' => $paginator, + 'pagination' => $pagination, + 'configuration' => $configuration + ]); + $paginationRendered = $paginationView->render(); - $paginationView = $this->getTemplateObject($renderingContext); - $paginationView->assignMultiple([ - 'id' => $id, - 'paginator' => $paginator, - 'pagination' => $pagination, - 'configuration' => $configuration - ]); - $paginationRendered = $paginationView->render(); + $variableProvider = $renderingContext->getVariableProvider(); + $variableProvider->add('paginator', $paginator); - $variableProvider = $renderingContext->getVariableProvider(); - $variableProvider->add('paginator', $paginator); + $contents = []; + $contents[] = $configuration['insertAbove'] === true ? $paginationRendered : ''; + $contents[] = $this->renderChildren(); + $contents[] = $configuration['insertBelow'] === true ? $paginationRendered : ''; - $contents = []; - $contents[] = $configuration['insertAbove'] === true ? $paginationRendered : ''; - $contents[] = $this->renderChildren(); - $contents[] = $configuration['insertBelow'] === true ? $paginationRendered : ''; + $variableProvider->remove('paginator'); - $variableProvider->remove('paginator'); + return implode('', $contents); + } - return implode('', $contents); + throw new \RuntimeException( + 'ViewHelper bk2k:data.paginate needs a request implementing ServerRequestInterface.', + 1639819269 + ); } protected function getTemplateObject(RenderingContext $renderingContext): StandaloneView diff --git a/Classes/ViewHelpers/Link/PaginateViewHelper.php b/Classes/ViewHelpers/Link/PaginateViewHelper.php index c1c97ba7c..323c405ad 100644 --- a/Classes/ViewHelpers/Link/PaginateViewHelper.php +++ b/Classes/ViewHelpers/Link/PaginateViewHelper.php @@ -66,8 +66,8 @@ public function render(): string return $this->renderLink($uriBuilder->build()); } - $applicationType = ApplicationType::fromRequest($request); if ($request instanceof ServerRequestInterface) { + $applicationType = ApplicationType::fromRequest($request); if ($applicationType->isFrontend()) { try { $typolinkConfiguration = []; @@ -82,7 +82,7 @@ public function render(): string /** @var LinkFactory $linkFactory */ $linkFactory = GeneralUtility::makeInstance(LinkFactory::class); - $linkResult = $linkFactory->create((string)$this->renderChildren(), $typolinkConfiguration, $contentObjectRenderer); + $linkResult = $linkFactory->create('', $typolinkConfiguration, $contentObjectRenderer); return $this->renderLink($linkResult->getUrl()); } catch (UnableToLinkException $e) { return strval($this->renderChildren()); @@ -91,7 +91,7 @@ public function render(): string } throw new \RuntimeException( - 'ViewHelper bk2k:paginate.data needs a request implementing ServerRequestInterface.', + 'ViewHelper bk2k:link.paginate needs a request implementing ServerRequestInterface.', 1639819269 ); } diff --git a/README.rst b/README.rst index 9605fa669..bf598f440 100644 --- a/README.rst +++ b/README.rst @@ -2,14 +2,14 @@ :alt: Latest Stable Version :target: https://extensions.typo3.org/extension/bootstrap_package/ +.. image:: https://img.shields.io/badge/TYPO3-12-orange.svg + :alt: TYPO3 12 + :target: https://get.typo3.org/version/12 + .. image:: https://img.shields.io/badge/TYPO3-11-orange.svg :alt: TYPO3 11 :target: https://get.typo3.org/version/11 -.. image:: https://img.shields.io/badge/TYPO3-10-orange.svg - :alt: TYPO3 10 - :target: https://get.typo3.org/version/10 - .. image:: https://poser.pugx.org/bk2k/bootstrap-package/d/total :alt: Total Downloads :target: https://packagist.org/packages/bk2k/bootstrap-package @@ -61,7 +61,7 @@ Compatibility - v7 * - BP 13.x - - + - ✔️ - ✔️ - - @@ -99,4 +99,3 @@ Compatibility - - - ✔️ - diff --git a/Tests/Functional/Parser/ScssParserTest.php b/Tests/Functional/Parser/ScssParserTest.php index 5909d4a16..0741aa8a8 100644 --- a/Tests/Functional/Parser/ScssParserTest.php +++ b/Tests/Functional/Parser/ScssParserTest.php @@ -20,7 +20,7 @@ */ class ScssParserTest extends FunctionalTestCase { - protected $testExtensionsToLoad = [ + protected array $testExtensionsToLoad = [ 'typo3conf/ext/bootstrap_package', 'typo3conf/ext/demo_package', ]; diff --git a/composer.json b/composer.json index c78f1e06b..a574866f8 100644 --- a/composer.json +++ b/composer.json @@ -32,38 +32,37 @@ "ext-libxml": "*", "ext-simplexml": "*", "scssphp/scssphp": "^1.8.1", - "typo3/cms-backend": "^11.5", - "typo3/cms-core": "^11.5", - "typo3/cms-extbase": "^11.5", - "typo3/cms-extensionmanager": "^11.5", - "typo3/cms-fluid": "^11.5", - "typo3/cms-frontend": "^11.5", - "typo3/cms-install": "^11.5", - "typo3/cms-rte-ckeditor": "^11.5", - "typo3/cms-seo": "^11.5", - "typo3fluid/fluid": "^2.5.2" + "typo3/cms-backend": "^11.5 || ^12.0 || 12.*.*@dev", + "typo3/cms-core": "^11.5 || ^12.0 || 12.*.*@dev", + "typo3/cms-extbase": "^11.5 || ^12.0 || 12.*.*@dev", + "typo3/cms-extensionmanager": "^11.5 || ^12.0 || 12.*.*@dev", + "typo3/cms-fluid": "^11.5 || ^12.0 || 12.*.*@dev", + "typo3/cms-frontend": "^11.5 || ^12.0 || 12.*.*@dev", + "typo3/cms-install": "^11.5 || ^12.0 || 12.*.*@dev", + "typo3/cms-rte-ckeditor": "^11.5 || ^12.0 || 12.*.*@dev", + "typo3/cms-seo": "^11.5 || ^12.0 || 12.*.*@dev" }, "require-dev": { - "b13/container": "^1.3", + "b13/container": "^2.0 || dev-feature/v12-2", "bk2k/demo-package": "@dev", - "bk2k/extension-helper": "^1.0", + "bk2k/extension-helper": "^2.0 || dev-master", "friendsofphp/php-cs-fixer": "^3.0.0", "friendsoftypo3/phpstan-typo3": "^0.9", - "overtrue/phplint": "^2.3.5", + "overtrue/phplint": "^3.2 || ^4.3 || ^5.3", "phpstan/phpstan": "^1.7", "phpstan/phpstan-deprecation-rules": "^1.0", "phpstan/phpstan-phpunit": "^1.1", "phpstan/phpstan-strict-rules": "^1.2", - "typo3/cms-belog": "^11.5", - "typo3/cms-felogin": "^11.5", - "typo3/cms-filelist": "^11.5", - "typo3/cms-form": "^11.5", - "typo3/cms-indexed-search": "^11.5", - "typo3/cms-info": "^11.5", - "typo3/cms-lowlevel": "^11.5", - "typo3/cms-tstemplate": "^11.5", - "typo3/cms-workspaces": "^11.5", - "typo3/testing-framework": "^6.16" + "typo3/cms-belog": "^11.5 || ^12.0 || 12.*.*@dev", + "typo3/cms-felogin": "^11.5 || ^12.0 || 12.*.*@dev", + "typo3/cms-filelist": "^11.5 || ^12.0 || 12.*.*@dev", + "typo3/cms-form": "^11.5 || ^12.0 || 12.*.*@dev", + "typo3/cms-indexed-search": "^11.5 || ^12.0 || 12.*.*@dev", + "typo3/cms-info": "^11.5 || ^12.0 || 12.*.*@dev", + "typo3/cms-lowlevel": "^11.5 || ^12.0 || 12.*.*@dev", + "typo3/cms-tstemplate": "^11.5 || ^12.0 || 12.*.*@dev", + "typo3/cms-workspaces": "^11.5 || ^12.0 || 12.*.*@dev", + "typo3/testing-framework": "7.x-dev" }, "config": { "bin-dir": ".build/bin", @@ -77,10 +76,9 @@ }, "extra": { "branch-alias": { - "dev-master": "13.x-dev" + "dev-master": "13.0.x-dev" }, "typo3/cms": { - "app-dir": ".build", "extension-key": "bootstrap_package", "web-dir": ".build/public" } @@ -104,8 +102,8 @@ "prefer-stable": true, "scripts": { "post-autoload-dump": [ - "mkdir -p .build/public/typo3conf/ext/", - "[ -L .build/public/typo3conf/ext/bootstrap_package ] || ln -snvf ../../../../. .build/public/typo3conf/ext/bootstrap_package" + "[ -d .build/public/_assets ] || mkdir -p .build/public/typo3conf/ext/", + "[ -d .build/public/_assets ] || [ -L .build/public/typo3conf/ext/bootstrap_package ] || ln -snvf ../../../../. .build/public/typo3conf/ext/bootstrap_package" ], "cgl": [ "php-cs-fixer --diff -v fix"