Skip to content

Commit 6a2cf26

Browse files
authored
Merge pull request #105 from extcode/87-make-extension-compatible-to-typo3-v13
[TASK] Make extension compatible to TYPO3 v13.4
2 parents a11fc1b + 3691282 commit 6a2cf26

69 files changed

Lines changed: 1929 additions & 1443 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yaml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ jobs:
1515
strategy:
1616
matrix:
1717
php-version:
18-
- 8.1
1918
- 8.2
2019
- 8.3
2120
- 8.4
@@ -54,7 +53,7 @@ jobs:
5453
- name: Install PHP
5554
uses: shivammathur/setup-php@v2
5655
with:
57-
php-version: "8.1"
56+
php-version: "8.2"
5857
tools: composer:v2
5958

6059
- name: Install dependencies
@@ -70,14 +69,12 @@ jobs:
7069
strategy:
7170
matrix:
7271
include:
73-
- php-version: '8.1'
74-
typo3-version: '^12.4'
7572
- php-version: '8.2'
76-
typo3-version: '^12.4'
73+
typo3-version: '^13.4'
7774
- php-version: '8.3'
78-
typo3-version: '^12.4'
75+
typo3-version: '^13.4'
7976
- php-version: '8.4'
80-
typo3-version: '^12.4'
77+
typo3-version: '^13.4'
8178
steps:
8279
- uses: actions/checkout@v4
8380

@@ -112,9 +109,6 @@ jobs:
112109
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= fossar.cachix.org-1:Zv6FuqIboeHPWQS7ysLCJ7UT7xExb4OE8c4LyGb5AsE=
113110
substituters = https://cache.nixos.org/ https://fossar.cachix.org
114111
115-
- name: Run Unit Tests PHP8.1
116-
run: nix-shell --arg phpVersion \"php81\" --pure --run project-test-unit
117-
118112
- name: Run Unit Tests PHP8.2
119113
run: nix-shell --arg phpVersion \"php82\" --pure --run project-test-unit
120114

@@ -124,9 +118,6 @@ jobs:
124118
- name: Run Unit Tests PHP8.4
125119
run: nix-shell --arg phpVersion \"php84\" --pure --run project-test-unit
126120

127-
- name: Run Functional Tests PHP8.1
128-
run: nix-shell --arg phpVersion \"php81\" --pure --run project-test-functional
129-
130121
- name: Run Functional Tests PHP8.2
131122
run: nix-shell --arg phpVersion \"php82\" --pure --run project-test-functional
132123

@@ -150,9 +141,6 @@ jobs:
150141
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= fossar.cachix.org-1:Zv6FuqIboeHPWQS7ysLCJ7UT7xExb4OE8c4LyGb5AsE=
151142
substituters = https://cache.nixos.org/ https://fossar.cachix.org
152143
153-
- name: Run Acceptance Tests PHP8.1
154-
run: nix-shell --arg phpVersion \"php81\" --pure --run project-test-acceptance
155-
156144
- name: Run Acceptance Tests PHP8.2
157145
run: nix-shell --arg phpVersion \"php82\" --pure --run project-test-acceptance
158146

.gitlab-ci.yml

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cache:
55
- .php_cs.cache
66

77
variables:
8-
TYPO3_VERSION: ^12.4
8+
TYPO3_VERSION: ^13.4
99

1010
before_script:
1111
- apk add git --update
@@ -39,11 +39,6 @@ lint:yaml:
3939
script:
4040
- find *.php Classes Configuration Tests -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l
4141

42-
lint:php81:
43-
<<: *lint_php
44-
variables:
45-
CONTAINER_IMAGE: php:8.1-alpine
46-
4742
lint:php82:
4843
<<: *lint_php
4944
variables:
@@ -60,11 +55,11 @@ lint:php84:
6055
CONTAINER_IMAGE: php:8.4-alpine
6156

6257
phpstan:analyse:
63-
image: $CI_REGISTRY/containers/phpunit-with-php-8.1:main
58+
image: $CI_REGISTRY/containers/phpunit-with-php-8.2:main
6459
stage: lint
6560
before_script:
6661
- sed -i -e "s#ssh://git@code.extco.de:22722#https://gitlab-ci-token:$CI_JOB_TOKEN@code.extco.de#g" composer.json
67-
- composer config platform.php 8.1
62+
- composer config platform.php 8.2
6863
- composer install --no-progress --no-ansi --no-interaction
6964
script:
7065
- vendor/bin/codecept build
@@ -83,12 +78,7 @@ phpstan:analyse:
8378
- composer require typo3/cms-core="${TYPO3_VERSION}"
8479
script:
8580
- vendor/bin/phpunit -c Build/UnitTests.xml
86-
- typo3DatabaseDriver=pdo_sqlite vendor/bin/phpunit -c Build/FunctionalTests.xml
87-
88-
test:php81:
89-
<<: *test_php
90-
variables:
91-
CONTAINER_IMAGE: $CI_REGISTRY/containers/phpunit-with-php-8.1:main
81+
- typo3DatabaseDriver=pdo_sqlite vendor/bin/phpunit -d memory_limit=256M -c Build/FunctionalTests.xml
9282

9383
test:php82:
9484
<<: *test_php
@@ -129,15 +119,8 @@ test:php84:
129119
expire_in: 1 day
130120
when: always
131121

132-
codeception:php81:
133-
<<: *test_codeception
134-
variables:
135-
CONTAINER_IMAGE: $CI_REGISTRY/containers/codeception-with-php-8.1:main
136-
137122
codeception:php82:
138123
<<: *test_codeception
139-
needs:
140-
- codeception:php81
141124
variables:
142125
CONTAINER_IMAGE: $CI_REGISTRY/containers/codeception-with-php-8.2:main
143126

Build/phpstan-baseline.neon

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Extcode\\\\CartEvents\\\\Domain\\\\Model\\\\AbstractEventDate'' and Extcode\\CartEvents\\Domain\\Model\\CalendarEntry will always evaluate to true\.$#'
5+
identifier: staticMethod.alreadyNarrowedType
6+
count: 1
7+
path: ../Tests/Unit/Domain/Model/CalenderEntryTest.php
8+
9+
-
10+
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''TYPO3\\\\CMS\\\\Extbase\\\\Domain\\\\Model\\\\Category'' and Extcode\\CartEvents\\Domain\\Model\\Category will always evaluate to true\.$#'
11+
identifier: staticMethod.alreadyNarrowedType
12+
count: 1
13+
path: ../Tests/Unit/Domain/Model/CategoryTest.php
14+
15+
-
16+
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Extcode\\\\CartEvents\\\\Domain\\\\Model\\\\AbstractEventDate'' and Extcode\\CartEvents\\Domain\\Model\\EventDate will always evaluate to true\.$#'
17+
identifier: staticMethod.alreadyNarrowedType
18+
count: 1
19+
path: ../Tests/Unit/Domain/Model/EventDateTest.php

Build/phpstan.neon

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,38 @@
1+
includes:
2+
- 'phpstan-baseline.neon'
3+
14
parameters:
2-
level: 0
5+
level: 5
6+
37
paths:
48
- ../Classes
59
- ../Configuration
610
- ../Tests
711
- ../ext_emconf.php
812
- ../ext_localconf.php
13+
excludePaths:
14+
- '../Tests/Acceptance/Support/_generated/TesterActions.php'
15+
16+
disallowedFunctionCalls:
17+
-
18+
function:
19+
- 'var_dump()'
20+
- 'xdebug_break()'
21+
message: 'Do not add debugging'
22+
-
23+
function: 'header()'
24+
message: 'Use API instead'
25+
26+
disallowedStaticCalls:
27+
-
28+
method: 'TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump()'
29+
message: 'Do not add debugging'
30+
31+
disallowedSuperglobals:
32+
-
33+
superglobal:
34+
- '$_GET'
35+
- '$_POST'
36+
- '$_FILES'
37+
- '$_SERVER'
38+
message: 'Use API instead'

Classes/Controller/EventController.php

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
* LICENSE file that was distributed with this source code.
1212
*/
1313

14+
use Exception;
1415
use Extcode\Cart\Domain\Model\Cart\Cart;
1516
use Extcode\Cart\Service\SessionHandler;
1617
use Extcode\Cart\Utility\CartUtility;
18+
use Extcode\CartEvents\Domain\Model\Category;
1719
use Extcode\CartEvents\Domain\Model\Dto\EventDemand;
1820
use Extcode\CartEvents\Domain\Model\Event;
1921
use Extcode\CartEvents\Domain\Model\EventDate;
@@ -28,9 +30,8 @@
2830
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
2931
use TYPO3\CMS\Extbase\Http\ForwardResponse;
3032
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
31-
use TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface;
3233

33-
class EventController extends ActionController
34+
final class EventController extends ActionController
3435
{
3536
private Cart $cart;
3637

@@ -40,6 +41,7 @@ public function __construct(
4041
private readonly SessionHandler $sessionHandler,
4142
private readonly CartUtility $cartUtility,
4243
private readonly EventRepository $eventRepository,
44+
private readonly EventDateRepository $eventDateRepository,
4345
private readonly CategoryRepository $categoryRepository,
4446
) {}
4547

@@ -118,6 +120,10 @@ public function showAction(?Event $event = null): ResponseInterface
118120
#[IgnoreValidation(['value' => 'priceCategory'])]
119121
public function formAction(?EventDate $eventDate = null, ?PriceCategory $priceCategory = null): ResponseInterface
120122
{
123+
if (class_exists(\TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface::class) === false) {
124+
throw new \BadFunctionCallException('This action requires the installation of typo3/cms-form.');
125+
}
126+
121127
if (!$eventDate) {
122128
$arguments = $this->request->getArguments();
123129
foreach ($arguments as $argumentKey => $argumentValue) {
@@ -126,14 +132,17 @@ public function formAction(?EventDate $eventDate = null, ?PriceCategory $priceCa
126132
$priceCategoryId = (int)$argumentValue['priceCategoryId'];
127133

128134
if ($eventDateId) {
129-
$eventDateRepository = GeneralUtility::makeInstance(
130-
EventDateRepository::class
131-
);
132-
$eventDate = $eventDateRepository->findByUid($eventDateId);
133-
134-
$formDefinition = $eventDate->getEvent()->getFormDefinition();
135+
$eventDate = $this->eventDateRepository->findByUid($eventDateId);
136+
if (($eventDate instanceof EventDate) === false) {
137+
throw new Exception('Can not find EventDate with uid ' . $eventDateId . '.', 1769617660);
138+
}
139+
$event = $eventDate->getEvent();
140+
if (($event instanceof Event) === false) {
141+
throw new Exception('EventDate with uid ' . $eventDateId . ' has no event!', 1769617873);
142+
}
143+
$formDefinition = $event->getFormDefinition();
135144
$formPersistenceManager = GeneralUtility::makeInstance(
136-
FormPersistenceManagerInterface::class
145+
\TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface::class
137146
);
138147
$form = $formPersistenceManager->load($formDefinition);
139148

@@ -146,14 +155,17 @@ public function formAction(?EventDate $eventDate = null, ?PriceCategory $priceCa
146155
PriceCategoryRepository::class
147156
);
148157
$priceCategory = $priceCategoryRepository->findByUid($priceCategoryId);
158+
if (($priceCategory instanceof PriceCategory) === false) {
159+
throw new Exception('Can not find PriceCategory with uid ' . $priceCategoryId . '.', 1769642011);
160+
}
149161
}
150162
}
151163
}
152164
}
153165
}
154166

155-
if (!$eventDate) {
156-
throw new \InvalidArgumentException();
167+
if (($eventDate instanceof EventDate) === false) {
168+
throw new Exception('Can not find EventDate.', 1769641914);
157169
}
158170

159171
$this->view->assign('eventDate', $eventDate);
@@ -169,19 +181,19 @@ public function formAction(?EventDate $eventDate = null, ?PriceCategory $priceCa
169181
'type' => 'Hidden',
170182
'identifier' => 'productType',
171183
'label' => 'productType',
172-
'defaultValue' => ($eventDate ? 'CartEvents' : ''),
184+
'defaultValue' => 'CartEvents',
173185
],
174186
9998 => [
175187
'type' => 'Hidden',
176188
'identifier' => 'eventDateId',
177189
'label' => 'eventDateId',
178-
'defaultValue' => ($eventDate ? $eventDate->getUid() : ''),
190+
'defaultValue' => $eventDate->getUid(),
179191
],
180192
9999 => [
181193
'type' => 'Hidden',
182194
'identifier' => 'priceCategoryId',
183195
'label' => 'priceCategoryId',
184-
'defaultValue' => ($priceCategory ? $priceCategory->getUid() : ''),
196+
'defaultValue' => (($priceCategory instanceof PriceCategory) ? $priceCategory->getUid() : ''),
185197
],
186198
],
187199
],
@@ -195,28 +207,7 @@ public function formAction(?EventDate $eventDate = null, ?PriceCategory $priceCa
195207
return $this->htmlResponse();
196208
}
197209

198-
protected function getEvent(): ?Event
199-
{
200-
$eventUid = 0;
201-
202-
if ((int)$GLOBALS['TSFE']->page['doktype'] == 186) {
203-
$eventUid = (int)$GLOBALS['TSFE']->page['cart_events_event'];
204-
}
205-
206-
if ($eventUid > 0) {
207-
$event = $this->eventRepository->findByUid($eventUid);
208-
if ($event && $event instanceof Event) {
209-
return $event;
210-
}
211-
}
212-
213-
return null;
214-
}
215-
216-
/**
217-
* Create the demand object which define which records will get shown
218-
*/
219-
protected function createDemandObjectFromSettings(string $type, array $settings): EventDemand
210+
private function createDemandObjectFromSettings(string $type, array $settings): EventDemand
220211
{
221212
/** @var EventDemand $demand */
222213
$demand = GeneralUtility::makeInstance(
@@ -254,7 +245,7 @@ protected function createDemandObjectFromSettings(string $type, array $settings)
254245
return $demand;
255246
}
256247

257-
protected function addCategoriesToDemandObjectFromSettings(EventDemand &$demand): void
248+
private function addCategoriesToDemandObjectFromSettings(EventDemand &$demand): void
258249
{
259250
if ($this->settings['categoriesList']) {
260251
$selectedCategories = GeneralUtility::intExplode(
@@ -268,6 +259,9 @@ protected function addCategoriesToDemandObjectFromSettings(EventDemand &$demand)
268259
if ($this->settings['listSubcategories']) {
269260
foreach ($selectedCategories as $selectedCategory) {
270261
$category = $this->categoryRepository->findByUid($selectedCategory);
262+
if (($category instanceof Category) === false) {
263+
continue;
264+
}
271265
$categories = array_merge(
272266
$categories,
273267
$this->categoryRepository->findSubcategoriesRecursiveAsArray($category)
@@ -281,10 +275,7 @@ protected function addCategoriesToDemandObjectFromSettings(EventDemand &$demand)
281275
}
282276
}
283277

284-
/**
285-
* assigns currency translation array to view
286-
*/
287-
protected function assignCurrencyTranslationData(): void
278+
private function assignCurrencyTranslationData(): void
288279
{
289280
$this->restoreSession();
290281

@@ -297,7 +288,7 @@ protected function assignCurrencyTranslationData(): void
297288
$this->view->assign('currencyTranslationData', $currencyTranslationData);
298289
}
299290

300-
protected function addCacheTags(iterable $events): void
291+
private function addCacheTags(iterable $events): void
301292
{
302293
$cacheTags = [];
303294

@@ -333,7 +324,7 @@ private function forwardToShowActionWhenRequested(): ?ForwardResponse
333324
return $forwardResponse->withArguments(['event' => $this->request->getArgument('event')]);
334325
}
335326

336-
protected function restoreSession(): void
327+
private function restoreSession(): void
337328
{
338329
$cart = $this->sessionHandler->restoreCart($this->cartConfiguration['settings']['cart']['pid']);
339330

0 commit comments

Comments
 (0)