Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,44 @@ jobs:
runs-on: 'ubuntu-latest'
needs:
- 'base-qa'
# The following is not a string, but boolean
# yamllint disable-line rule:quoted-strings
continue-on-error: ${{ matrix.experimental }}
strategy:
matrix:
include:
- db-version: '8'
php-version: '8.1'
typo3-version: '^12.4'
- db-version: '8'
php-version: '8.2'
typo3-version: '^12.4'
typo3-version: '^13.4'
experimental: false
- db-version: '8'
php-version: '8.3'
typo3-version: '^12.4'
typo3-version: '^13.4'
experimental: false
- db-version: '8'
php-version: '8.4'
typo3-version: '^12.4'
typo3-version: '^13.4'
experimental: false
- db-version: '8'
php-version: '8.2'
php-version: '8.5'
typo3-version: '^13.4'
experimental: false
- db-version: '8'
php-version: '8.2'
typo3-version: '^14.1'
experimental: true
- db-version: '8'
php-version: '8.3'
typo3-version: '^13.4'
typo3-version: '^14.1'
experimental: true
- db-version: '8'
php-version: '8.4'
typo3-version: '^13.4'
typo3-version: '^14.1'
experimental: true
- db-version: '8'
php-version: '8.5'
typo3-version: '^13.4'
typo3-version: '^14.1'
experimental: true
steps:
- uses: 'actions/checkout@v4'

Expand Down Expand Up @@ -125,4 +136,4 @@ jobs:
export typo3DatabaseHost="127.0.0.1"
export typo3DatabaseUsername="root"
export typo3DatabasePassword="root"
./vendor/bin/phpunit --testdox
./vendor/bin/phpunit --testdox --display-all-issues
3 changes: 3 additions & 0 deletions Classes/Dashboard/Provider/PageviewsPerDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ private function calculateData(): array
];
}

/**
* @return array{count: numeric, label: string}[]
*/
private function getPageviewsInPeriod(int $start, int $end): array
{
$constraints = [
Expand Down
15 changes: 13 additions & 2 deletions Classes/Dashboard/Provider/Recordviews.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
use TYPO3\CMS\Dashboard\WidgetApi;
use TYPO3\CMS\Dashboard\Widgets\ChartDataProviderInterface;

Expand Down Expand Up @@ -96,7 +98,12 @@ private function getRecordviews(): array
continue;
}

$labels[] = mb_strimwidth((string) $record['title'], 0, 25, '…');
$labels[] = mb_strimwidth(
StringUtility::cast($record['title']) ?? '',
0,
25,
'…'
);
$data[] = $recordview['total'];
}

Expand Down Expand Up @@ -172,7 +179,11 @@ private function getRecord(
int $uid,
string $table
): ?array {
$recordTypeField = $GLOBALS['TCA'][$table]['ctrl']['type'] ?? '';
$recordTypeField = '';
$recordTypeFieldPath = 'TCA/' . $table . '/ctrl/type';
if (ArrayUtility::isValidPath($GLOBALS, $recordTypeFieldPath)) {
$recordTypeField = StringUtility::cast(ArrayUtility::getValueByPath($GLOBALS, $recordTypeFieldPath)) ?? '';
}

$record = BackendUtility::getRecord($table, $uid);
if (count($this->languageLimitation) === 1 && $record !== null) {
Expand Down
15 changes: 15 additions & 0 deletions Classes/Domain/Model/RecordRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

namespace DanielSiepmann\Tracking\Domain\Model;

use InvalidArgumentException;

class RecordRule
{
public function __construct(
Expand All @@ -34,13 +36,26 @@ public function __construct(

public static function fromArray(array $config): self
{
if (
is_string($config['matches']) === false
|| is_string($config['recordUid']) === false
|| is_string($config['tableName']) === false
) {
throw new InvalidArgumentException('Expected all three keys to be strings.', 1772793074);
}

return new self(
$config['matches'],
$config['recordUid'],
$config['tableName']
);
}

/**
* @param array[] $configs
*
* @return array<RecordRule>
*/
public static function multipleFromArray(array $configs): array
{
$rules = [];
Expand Down
19 changes: 12 additions & 7 deletions Classes/Domain/Pageview/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Routing\PageArguments;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
use UnexpectedValueException;

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

public function fromDbRow(array $dbRow): Pageview
{
$pid = MathUtility::forceIntegerInRange($dbRow['pid'], 1);
return new Pageview(
(int) $dbRow['pid'],
$this->siteRepository->findByPageUid((int) $dbRow['pid'])->getLanguageById((int) $dbRow['sys_language_uid']),
new DateTimeImmutable('@' . $dbRow['crdate']),
(int) $dbRow['type'],
$dbRow['url'],
$dbRow['user_agent'],
(int) $dbRow['uid']
$pid,
$this->siteRepository
->findByPageUid($pid)
->getLanguageById(MathUtility::forceIntegerInRange($dbRow['sys_language_uid'], 0)),
new DateTimeImmutable('@' . StringUtility::cast($dbRow['crdate'])),
MathUtility::forceIntegerInRange($dbRow['type'], 0),
StringUtility::cast($dbRow['url']) ?? '',
StringUtility::cast($dbRow['user_agent']) ?? '',
MathUtility::forceIntegerInRange($dbRow['uid'], 1)
);
}

Expand Down
21 changes: 19 additions & 2 deletions Classes/Hooks/DataHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class DataHandler
{
public function processCmdmap_beforeStart(Typo3DataHandler $dataHandler): void
{
// @phpstan-ignore function.alreadyNarrowedType (It is available in v13, but not v14)
if (property_exists($dataHandler, 'copyWhichTables')) {
$this->preventCopyOfTrackingTablesV13($dataHandler);
return;
}

$this->preventCopyOfTrackingTables($dataHandler);
}

Expand All @@ -47,19 +53,30 @@ public static function register(): void
]);
}

private function preventCopyOfTrackingTables(Typo3DataHandler $dataHandler): void
private function preventCopyOfTrackingTablesV13(Typo3DataHandler $dataHandler): void
{
$copyWhichTables = array_keys($GLOBALS['TCA']);

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

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

// @phpstan-ignore property.notFound (this code is only executed on v13 where it exists)
$dataHandler->copyWhichTables = implode(',', $copyWhichTables);
}

private function preventCopyOfTrackingTables(Typo3DataHandler $dataHandler): void
{
// TODO: Find a way to prevent copy of tracking tables on page copy.
// See upstream issue: https://forge.typo3.org/issues/108353
}
}
3 changes: 3 additions & 0 deletions Classes/Middleware/Recordview.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class Recordview implements MiddlewareInterface
*/
private array $rules = [];

/**
* @param array[] $rules
*/
public function __construct(
private readonly Repository $repository,
private readonly Context $context,
Expand Down
30 changes: 30 additions & 0 deletions Documentation/Changelog/4.0.0.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
3.0.0
=====

Breaking
--------

* Drop support for TYPO3 v12.
I only support last two TYPO3 versions.

Features
--------

* Add Support for TYPO3 v14.

* Add Support for PHP 8.5.

Fixes
-----

Nothing

Tasks
-----

Nothing

Deprecation
-----------

Nothing
4 changes: 2 additions & 2 deletions Documentation/Maintenance/v12.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
V12
V13
===

Remove `new DataHandler()` calls.
* Remove `->copyWhichTables` checks and usages.
9 changes: 5 additions & 4 deletions Tests/Functional/Command/UpdateDataCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Component\Console\Tester\CommandTester;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

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

$records = $this->getAllRecords('tx_tracking_pageview');
self::assertCount(2, $records);
self::assertSame('Linux', $records[0]['operating_system']);
self::assertSame('Android', $records[1]['operating_system']);
self::assertSame('Linux', ArrayUtility::getValueByPath($records, '0/operating_system'));
self::assertSame('Android', ArrayUtility::getValueByPath($records, '1/operating_system'));
}

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

$records = $this->getAllRecords('tx_tracking_pageview');
self::assertCount(2, $records);
self::assertSame('Linux', $records[0]['operating_system']);
self::assertSame('Android', $records[1]['operating_system']);
self::assertSame('Linux', ArrayUtility::getValueByPath($records, '0/operating_system'));
self::assertSame('Android', ArrayUtility::getValueByPath($records, '1/operating_system'));
}

#[Test]
Expand Down
11 changes: 6 additions & 5 deletions Tests/Functional/Dashboard/Provider/PageviewsPerDayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use PHPUnit\Framework\Attributes\Test;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

#[CoversClass(PageviewsPerDay::class)]
Expand Down Expand Up @@ -63,7 +64,7 @@ public function listsResultsForLast31DaysByDefault(): void

$result = $subject->getChartData();
self::assertCount(32, $result['labels']);
self::assertCount(32, $result['datasets'][0]['data']);
self::assertCount(32, ArrayUtility::getValueByPath($result, 'datasets/0/data'));
}

#[Test]
Expand All @@ -90,7 +91,7 @@ public function respectedNumberOfDays(): void
1,
1,
0,
], $result['datasets'][0]['data']);
], ArrayUtility::getValueByPath($result, 'datasets/0/data'));
}

#[Test]
Expand Down Expand Up @@ -118,7 +119,7 @@ public function respectedExcludedPages(): void
0,
1,
0,
], $result['datasets'][0]['data']);
], ArrayUtility::getValueByPath($result, 'datasets/0/data'));
}

#[Test]
Expand All @@ -140,7 +141,7 @@ public function respectedDateFormat(): void
date('d.m.Y', strtotime('-1 day')),
date('d.m.Y'),
], $result['labels']);
self::assertCount(2, $result['datasets'][0]['data']);
self::assertCount(2, ArrayUtility::getValueByPath($result, 'datasets/0/data'));
}

#[Test]
Expand Down Expand Up @@ -176,6 +177,6 @@ public function respectsLimitToLanguages(): void
9 => 0,
10 => 1,
11 => 0,
], $result['datasets'][0]['data']);
], ArrayUtility::getValueByPath($result, 'datasets/0/data'));
}
}
Loading
Loading