Skip to content

Commit

Permalink
[TASK] Make Bootstrap Package TYPO3 v12 compatible (#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminkott authored Oct 12, 2022
1 parent cfed9c0 commit e4c3b5f
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 104 deletions.
6 changes: 2 additions & 4 deletions .ddev/config.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
13 changes: 11 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.build
.ddev/docker-compose.tempfs.yaml
Build/node_modules/*
composer.lock
*.cache
nbproject
/Documentation-GENERATED-temp/

config/
var/
2 changes: 2 additions & 0 deletions .phplint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ extensions:
- php
exclude:
- .build
- config
- var
22 changes: 20 additions & 2 deletions Build/phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 4 additions & 0 deletions Build/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
1 change: 0 additions & 1 deletion Build/phpunit-unit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 3 additions & 20 deletions Classes/Updates/AbstractUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
}
85 changes: 48 additions & 37 deletions Classes/ViewHelpers/Data/PaginateViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Classes/ViewHelpers/Link/PaginateViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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());
Expand All @@ -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
);
}
Expand Down
11 changes: 5 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -61,7 +61,7 @@ Compatibility
- v7

* - BP 13.x
-
- ✔️
- ✔️
-
-
Expand Down Expand Up @@ -99,4 +99,3 @@ Compatibility
-
-
- ✔️

2 changes: 1 addition & 1 deletion Tests/Functional/Parser/ScssParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class ScssParserTest extends FunctionalTestCase
{
protected $testExtensionsToLoad = [
protected array $testExtensionsToLoad = [
'typo3conf/ext/bootstrap_package',
'typo3conf/ext/demo_package',
];
Expand Down
Loading

0 comments on commit e4c3b5f

Please sign in to comment.