Skip to content

Commit d7ab0e1

Browse files
Make compatible with TYPO3 v14.1
Current state seems to be usable. There are still some issues: 1. TYPO3 doesn't offer a way to prevent copying of the tracking tables anymore, see: https://forge.typo3.org/issues/108353 Feel free to use the current branch state and report other unknown issues.
1 parent 08869aa commit d7ab0e1

File tree

24 files changed

+289
-141
lines changed

24 files changed

+289
-141
lines changed

.github/workflows/ci.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,30 +59,30 @@ jobs:
5959
strategy:
6060
matrix:
6161
include:
62-
- db-version: '8'
63-
php-version: '8.1'
64-
typo3-version: '^12.4'
6562
- db-version: '8'
6663
php-version: '8.2'
67-
typo3-version: '^12.4'
64+
typo3-version: '^13.4'
6865
- db-version: '8'
6966
php-version: '8.3'
70-
typo3-version: '^12.4'
67+
typo3-version: '^13.4'
7168
- db-version: '8'
7269
php-version: '8.4'
73-
typo3-version: '^12.4'
70+
typo3-version: '^13.4'
7471
- db-version: '8'
75-
php-version: '8.2'
72+
php-version: '8.5'
7673
typo3-version: '^13.4'
74+
- db-version: '8'
75+
php-version: '8.2'
76+
typo3-version: '^14.1'
7777
- db-version: '8'
7878
php-version: '8.3'
79-
typo3-version: '^13.4'
79+
typo3-version: '^14.1'
8080
- db-version: '8'
8181
php-version: '8.4'
82-
typo3-version: '^13.4'
82+
typo3-version: '^14.1'
8383
- db-version: '8'
8484
php-version: '8.5'
85-
typo3-version: '^13.4'
85+
typo3-version: '^14.1'
8686
steps:
8787
- uses: 'actions/checkout@v4'
8888

@@ -125,4 +125,4 @@ jobs:
125125
export typo3DatabaseHost="127.0.0.1"
126126
export typo3DatabaseUsername="root"
127127
export typo3DatabasePassword="root"
128-
./vendor/bin/phpunit --testdox
128+
./vendor/bin/phpunit --testdox --display-all-issues

Classes/Dashboard/Provider/PageviewsPerDay.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ private function calculateData(): array
9292
];
9393
}
9494

95+
/**
96+
* @return array{count: numeric, label: string}[]
97+
*/
9598
private function getPageviewsInPeriod(int $start, int $end): array
9699
{
97100
$constraints = [

Classes/Dashboard/Provider/Recordviews.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
use TYPO3\CMS\Core\Database\Connection;
3131
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
3232
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
33+
use TYPO3\CMS\Core\Utility\ArrayUtility;
34+
use TYPO3\CMS\Core\Utility\StringUtility;
3335
use TYPO3\CMS\Dashboard\WidgetApi;
3436
use TYPO3\CMS\Dashboard\Widgets\ChartDataProviderInterface;
3537

@@ -96,7 +98,12 @@ private function getRecordviews(): array
9698
continue;
9799
}
98100

99-
$labels[] = mb_strimwidth((string) $record['title'], 0, 25, '');
101+
$labels[] = mb_strimwidth(
102+
StringUtility::cast($record['title']) ?? '',
103+
0,
104+
25,
105+
''
106+
);
100107
$data[] = $recordview['total'];
101108
}
102109

@@ -172,7 +179,11 @@ private function getRecord(
172179
int $uid,
173180
string $table
174181
): ?array {
175-
$recordTypeField = $GLOBALS['TCA'][$table]['ctrl']['type'] ?? '';
182+
$recordTypeField = '';
183+
$recordTypeFieldPath = 'TCA/' . $table . '/ctrl/type';
184+
if (ArrayUtility::isValidPath($GLOBALS, $recordTypeFieldPath)) {
185+
$recordTypeField = StringUtility::cast(ArrayUtility::getValueByPath($GLOBALS, $recordTypeFieldPath)) ?? '';
186+
}
176187

177188
$record = BackendUtility::getRecord($table, $uid);
178189
if (count($this->languageLimitation) === 1 && $record !== null) {

Classes/Domain/Model/RecordRule.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
namespace DanielSiepmann\Tracking\Domain\Model;
2525

26+
use InvalidArgumentException;
27+
2628
class RecordRule
2729
{
2830
public function __construct(
@@ -34,13 +36,26 @@ public function __construct(
3436

3537
public static function fromArray(array $config): self
3638
{
39+
if (
40+
is_string($config['matches']) === false
41+
|| is_string($config['recordUid']) === false
42+
|| is_string($config['tableName']) === false
43+
) {
44+
throw new InvalidArgumentException('Expected all three keys to be strings.', 1772793074);
45+
}
46+
3747
return new self(
3848
$config['matches'],
3949
$config['recordUid'],
4050
$config['tableName']
4151
);
4252
}
4353

54+
/**
55+
* @param array[] $configs
56+
*
57+
* @return array<RecordRule>
58+
*/
4459
public static function multipleFromArray(array $configs): array
4560
{
4661
$rules = [];

Classes/Domain/Pageview/Factory.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
use Psr\Http\Message\ServerRequestInterface;
3030
use TYPO3\CMS\Core\Routing\PageArguments;
3131
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
32+
use TYPO3\CMS\Core\Utility\MathUtility;
33+
use TYPO3\CMS\Core\Utility\StringUtility;
3234
use UnexpectedValueException;
3335

3436
class Factory
@@ -52,14 +54,17 @@ public function fromRequest(ServerRequestInterface $request): Pageview
5254

5355
public function fromDbRow(array $dbRow): Pageview
5456
{
57+
$pid = MathUtility::forceIntegerInRange($dbRow['pid'], 1);
5558
return new Pageview(
56-
(int) $dbRow['pid'],
57-
$this->siteRepository->findByPageUid((int) $dbRow['pid'])->getLanguageById((int) $dbRow['sys_language_uid']),
58-
new DateTimeImmutable('@' . $dbRow['crdate']),
59-
(int) $dbRow['type'],
60-
$dbRow['url'],
61-
$dbRow['user_agent'],
62-
(int) $dbRow['uid']
59+
$pid,
60+
$this->siteRepository
61+
->findByPageUid($pid)
62+
->getLanguageById(MathUtility::forceIntegerInRange($dbRow['sys_language_uid'], 0)),
63+
new DateTimeImmutable('@' . StringUtility::cast($dbRow['crdate'])),
64+
MathUtility::forceIntegerInRange($dbRow['type'], 0),
65+
StringUtility::cast($dbRow['url']) ?? '',
66+
StringUtility::cast($dbRow['user_agent']) ?? '',
67+
MathUtility::forceIntegerInRange($dbRow['uid'], 1)
6368
);
6469
}
6570

Classes/Hooks/DataHandler.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ class DataHandler
3131
{
3232
public function processCmdmap_beforeStart(Typo3DataHandler $dataHandler): void
3333
{
34+
// @phpstan-ignore function.alreadyNarrowedType (It is available in v13, but not v14)
35+
if (property_exists($dataHandler, 'copyWhichTables')) {
36+
$this->preventCopyOfTrackingTablesV13($dataHandler);
37+
return;
38+
}
39+
3440
$this->preventCopyOfTrackingTables($dataHandler);
3541
}
3642

@@ -47,19 +53,30 @@ public static function register(): void
4753
]);
4854
}
4955

50-
private function preventCopyOfTrackingTables(Typo3DataHandler $dataHandler): void
56+
private function preventCopyOfTrackingTablesV13(Typo3DataHandler $dataHandler): void
5157
{
5258
$copyWhichTables = array_keys($GLOBALS['TCA']);
5359

60+
// @phpstan-ignore property.notFound (this code is only executed on v13 where it exists)
5461
if ($dataHandler->copyWhichTables !== '*') {
55-
$copyWhichTables = GeneralUtility::trimExplode(',', $dataHandler->copyWhichTables, true);
62+
// @phpstan-ignore property.notFound (this code is only executed on v13 where it exists)
63+
$copyWhichTables = $dataHandler->copyWhichTables;
64+
// @phpstan-ignore argument.type (this is a string in v13, and not executed in v14)
65+
$copyWhichTables = GeneralUtility::trimExplode(',', $copyWhichTables, true);
5666
}
5767

5868
$copyWhichTables = array_filter(
5969
$copyWhichTables,
6070
static fn (int|string $tableName): bool => \str_starts_with((string) $tableName, 'tx_tracking_') === false
6171
);
6272

73+
// @phpstan-ignore property.notFound (this code is only executed on v13 where it exists)
6374
$dataHandler->copyWhichTables = implode(',', $copyWhichTables);
6475
}
76+
77+
private function preventCopyOfTrackingTables(Typo3DataHandler $dataHandler): void
78+
{
79+
// TODO: Find a way to prevent copy of tracking tables on page copy.
80+
// See upstream issue: https://forge.typo3.org/issues/108353
81+
}
6582
}

Classes/Middleware/Recordview.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class Recordview implements MiddlewareInterface
4040
*/
4141
private array $rules = [];
4242

43+
/**
44+
* @param array[] $rules
45+
*/
4346
public function __construct(
4447
private readonly Repository $repository,
4548
private readonly Context $context,

Documentation/Changelog/4.0.0.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
3.0.0
2+
=====
3+
4+
Breaking
5+
--------
6+
7+
* Drop support for TYPO3 v12.
8+
I only support last two TYPO3 versions.
9+
10+
Features
11+
--------
12+
13+
* Add Support for TYPO3 v14.
14+
15+
* Add Support for PHP 8.5.
16+
17+
Fixes
18+
-----
19+
20+
Nothing
21+
22+
Tasks
23+
-----
24+
25+
Nothing
26+
27+
Deprecation
28+
-----------
29+
30+
Nothing

Documentation/Maintenance/v12.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
V12
1+
V13
22
===
33

4-
Remove `new DataHandler()` calls.
4+
* Remove `->copyWhichTables` checks and usages.

Tests/Functional/Command/UpdateDataCommandTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use PHPUnit\Framework\Attributes\CoversClass;
2929
use PHPUnit\Framework\Attributes\Test;
3030
use Symfony\Component\Console\Tester\CommandTester;
31+
use TYPO3\CMS\Core\Utility\ArrayUtility;
3132
use TYPO3\CMS\Core\Utility\GeneralUtility;
3233

3334
#[CoversClass(UpdateDataCommand::class)]
@@ -50,8 +51,8 @@ public function updatesAllEntriesWithMissingOperatingSystem(): void
5051

5152
$records = $this->getAllRecords('tx_tracking_pageview');
5253
self::assertCount(2, $records);
53-
self::assertSame('Linux', $records[0]['operating_system']);
54-
self::assertSame('Android', $records[1]['operating_system']);
54+
self::assertSame('Linux', ArrayUtility::getValueByPath($records, '0/operating_system'));
55+
self::assertSame('Android', ArrayUtility::getValueByPath($records, '1/operating_system'));
5556
}
5657

5758
#[Test]
@@ -67,8 +68,8 @@ public function doesNotChangeExistingOperatingSystem(): void
6768

6869
$records = $this->getAllRecords('tx_tracking_pageview');
6970
self::assertCount(2, $records);
70-
self::assertSame('Linux', $records[0]['operating_system']);
71-
self::assertSame('Android', $records[1]['operating_system']);
71+
self::assertSame('Linux', ArrayUtility::getValueByPath($records, '0/operating_system'));
72+
self::assertSame('Android', ArrayUtility::getValueByPath($records, '1/operating_system'));
7273
}
7374

7475
#[Test]

0 commit comments

Comments
 (0)