Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TYPO3 13 #117

Merged
merged 8 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
38 changes: 16 additions & 22 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.3
coverage: none
tools: composer:v2
env:
Expand All @@ -29,10 +29,9 @@ jobs:
strategy:
matrix:
php-version:
- 7.4
- 8.0
- 8.1
- 8.2
- 8.3
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -56,7 +55,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"
php-version: "8.3"
coverage: none
tools: composer:v2
env:
Expand Down Expand Up @@ -104,24 +103,21 @@ jobs:
strategy:
matrix:
include:
- db-version: '8'
php-version: '7.4'
typo3-version: '^11.5'
- db-version: '8'
php-version: '8.0'
typo3-version: '^11.5'
- db-version: '8'
php-version: '8.1'
typo3-version: '^11.5'
typo3-version: '^12.4'
- db-version: '8'
php-version: '8.2'
typo3-version: '^11.5'
typo3-version: '^12.4'
- db-version: '8'
php-version: '8.1'
php-version: '8.3'
typo3-version: '^12.4'
- db-version: '8'
php-version: '8.2'
typo3-version: '^12.4'
typo3-version: '13.0'
- db-version: '8'
php-version: '8.3'
typo3-version: '13.0'
steps:
- uses: actions/checkout@v3

Expand Down Expand Up @@ -164,18 +160,16 @@ jobs:
strategy:
matrix:
include:
- php-version: '7.4'
typo3-version: '^11.5'
- php-version: '8.0'
typo3-version: '^11.5'
- php-version: '8.1'
typo3-version: '^11.5'
- php-version: '8.2'
typo3-version: '^11.5'
- php-version: '8.1'
typo3-version: '^12.4'
- php-version: '8.2'
typo3-version: '^12.4'
- php-version: '8.3'
typo3-version: '^12.4'
- php-version: '8.2'
typo3-version: '13.0'
- php-version: '8.3'
typo3-version: '13.0'
steps:
- uses: actions/checkout@v3

Expand Down
418 changes: 360 additions & 58 deletions .php-cs-fixer.dist.php

Large diffs are not rendered by default.

12 changes: 3 additions & 9 deletions Classes/Command/UpdateDataCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,9 @@

class UpdateDataCommand extends Command
{
/**
* @var Pageview
*/
private $repository;

public function __construct(Pageview $repository)
{
$this->repository = $repository;

public function __construct(
private readonly Pageview $repository
) {
parent::__construct();
}

Expand Down
41 changes: 12 additions & 29 deletions Classes/Dashboard/Provider/NewestPageviews.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,22 @@

namespace DanielSiepmann\Tracking\Dashboard\Provider;

use Exception;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Dashboard\Widgets\ListDataProviderInterface;

class NewestPageviews implements ListDataProviderInterface
{
/**
* @var QueryBuilder
* @param int[] $languageLimitation
*/
private $queryBuilder;

/**
* @var int
*/
private $maxResults;

/**
* @var array
*/
private $pagesToExclude;

/**
* @var array<int>
*/
private $languageLimitation;

public function __construct(
QueryBuilder $queryBuilder,
int $maxResults = 6,
array $pagesToExclude = [],
array $languageLimitation = []
private readonly QueryBuilder $queryBuilder,
private readonly int $maxResults = 6,
private readonly array $pagesToExclude = [],
private readonly array $languageLimitation = []
) {
$this->queryBuilder = $queryBuilder;
$this->maxResults = $maxResults;
$this->pagesToExclude = $pagesToExclude;
$this->languageLimitation = $languageLimitation;
}

public function getItems(): array
Expand Down Expand Up @@ -98,10 +78,13 @@ public function getItems(): array
$this->queryBuilder->where(...$constraints);
}

$items = $this->queryBuilder->execute()->fetchAll();
$items = $this->queryBuilder->executeQuery()->fetchAllAssociative();
foreach ($items as $item) {
if (is_array($item) === false) {
continue;
if (is_string($item['url']) === false) {
throw new Exception('url of item was not string: ' . var_export($item['url'], true), 1707327319);
}
if (is_string($item['user_agent']) === false) {
throw new Exception('user_agent of item was not string: ' . var_export($item['user_agent'], true), 1707327344);
}

$preparedItems[] = sprintf(
Expand Down
62 changes: 18 additions & 44 deletions Classes/Dashboard/Provider/PageviewsPerDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace DanielSiepmann\Tracking\Dashboard\Provider;

use DanielSiepmann\Tracking\Extension;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Localization\LanguageService;
Expand All @@ -32,49 +33,20 @@

class PageviewsPerDay implements ChartDataProviderInterface
{
/**
* @var LanguageService
*/
private $languageService;

/**
* @var QueryBuilder
*/
private $queryBuilder;

/**
* @var int
*/
private $days;
private LanguageService $languageService;

/**
* @var array<int>
* @param int[] $pagesToExclude
* @param int[] $languageLimitation
*/
private $pagesToExclude;

/**
* @var string
*/
private $dateFormat;

/**
* @var array<int>
*/
private $languageLimitation;

public function __construct(
QueryBuilder $queryBuilder,
int $days = 31,
array $pagesToExclude = [],
array $languageLimitation = [],
string $dateFormat = 'Y-m-d'
private readonly QueryBuilder $queryBuilder,
private readonly int $days = 31,
private readonly array $pagesToExclude = [],
private readonly array $languageLimitation = [],
private readonly string $dateFormat = 'Y-m-d'
) {
$this->languageService = $GLOBALS['LANG'];
$this->queryBuilder = $queryBuilder;
$this->days = $days;
$this->pagesToExclude = $pagesToExclude;
$this->languageLimitation = $languageLimitation;
$this->dateFormat = $dateFormat;
}

public function getChartData(): array
Expand Down Expand Up @@ -102,16 +74,16 @@ private function calculateData(): array
$data = [];

for ($daysBefore = $this->days; $daysBefore >= 0; $daysBefore--) {
$label = date($this->dateFormat, (int)strtotime('-' . $daysBefore . ' day'));
$label = date($this->dateFormat, (int) strtotime('-' . $daysBefore . ' day'));
$labels[$label] = $label;
$data[$label] = 0;
}

$start = (int)strtotime('-' . $this->days . ' day 0:00:00');
$end = (int)strtotime('tomorrow midnight');
$start = (int) strtotime('-' . $this->days . ' day 0:00:00');
$end = (int) strtotime('tomorrow midnight');

foreach ($this->getPageviewsInPeriod($start, $end) as $day) {
$data[$day['label']] = (int)$day['count'];
$data[$day['label']] = (int) $day['count'];
}

return [
Expand Down Expand Up @@ -154,13 +126,15 @@ private function getPageviewsInPeriod(int $start, int $end): array
->groupBy('label')
->orderBy('label', 'ASC')
;

if ($this->queryBuilder->getConnection()->getDatabasePlatform()->getName() === 'sqlite') {
if (
(class_exists(SqlitePlatform::class) && $this->queryBuilder->getConnection()->getDatabasePlatform() instanceof SqlitePlatform)
|| (method_exists($this->queryBuilder->getConnection()->getDatabasePlatform(), 'getName') && $this->queryBuilder->getConnection()->getDatabasePlatform()->getName() === 'sqlite')
) {
$this->queryBuilder->addSelectLiteral('date(crdate, "unixepoch") as "label"');
} else {
$this->queryBuilder->addSelectLiteral('FROM_UNIXTIME(crdate, "%Y-%m-%d") as "label"');
}

return $this->queryBuilder->execute()->fetchAll();
return $this->queryBuilder->executeQuery()->fetchAllAssociative();
}
}
40 changes: 10 additions & 30 deletions Classes/Dashboard/Provider/PageviewsPerOperatingSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace DanielSiepmann\Tracking\Dashboard\Provider;

use Exception;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Dashboard\WidgetApi;
Expand All @@ -31,35 +32,14 @@
class PageviewsPerOperatingSystem implements ChartDataProviderInterface
{
/**
* @var QueryBuilder
* @param int[] $languageLimitation
*/
private $queryBuilder;

/**
* @var int
*/
private $days;

/**
* @var int
*/
private $maxResults;

/**
* @var array<int>
*/
private $languageLimitation;

public function __construct(
QueryBuilder $queryBuilder,
int $days = 31,
int $maxResults = 6,
array $languageLimitation = []
private readonly QueryBuilder $queryBuilder,
private readonly int $days = 31,
private readonly int $maxResults = 6,
private readonly array $languageLimitation = []
) {
$this->queryBuilder = $queryBuilder;
$this->days = $days;
$this->maxResults = $maxResults;
$this->languageLimitation = $languageLimitation;
}

public function getChartData(): array
Expand Down Expand Up @@ -112,13 +92,13 @@ private function getPageViewsPerPage(): array
->orderBy('total', 'desc')
->addOrderBy('operating_system', 'asc')
->setMaxResults($this->maxResults)
->execute()
->fetchAll()
->executeQuery()
->fetchAllAssociative()
;

foreach ($result as $row) {
if (is_array($row) === false) {
continue;
if (is_string($row['operating_system']) === false) {
throw new Exception('operating_system of row was not string: ' . var_export($row['operating_system'], true), 1707326866);
}

$labels[] = mb_strimwidth($row['operating_system'], 0, 50, '…');
Expand Down
Loading
Loading