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

[TASK] TYPO3 v11 & PHP 8.1 compatibility #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion Classes/Command/CheckPageSpeedInsightsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function execute(InputInterface $input, OutputInterface $output)

$url = PageSpeedInsightsUtility::getUrlForPage($pid, $languageId);

$categories = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['page_speed_insights']['categories'] ?: ['performance', 'seo', 'accessibility', 'best-practices', 'pwa'];
$categories = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['page_speed_insights']['categories'] ?? ['performance', 'seo', 'accessibility', 'best-practices', 'pwa'];
$pageSpeedInsightsResultsMobile = PageSpeedInsightsUtility::checkUrl($url, 'mobile', $categories, $reference, $pageId, $languageId, $pid, (string)$input->getArgument('key'));
if (array_key_exists('error', $pageSpeedInsightsResultsMobile)) {
$errors = 10;
Expand Down
9 changes: 2 additions & 7 deletions Classes/FormEngine/Elements/History.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(NodeFactory $nodeFactory, array $data, StandaloneVie
$this->templateView->getRenderingContext()->getTemplatePaths()->fillDefaultsByPackageName('page_speed_insights');
$this->templateView->setTemplate('History');

$this->strategyToShow = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['page_speed_insights']['strategyToShow'] ?: 'mobile';
$this->strategyToShow = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['page_speed_insights']['strategyToShow'] ?? 'mobile';
}

public function render()
Expand All @@ -55,12 +55,7 @@ public function render()
$pageId = $this->data['vanillaUid'];
}

$languageId = 0;
if (array_key_exists('0', (array)$this->data['databaseRow']['sys_language_uid']) &&
$this->data['databaseRow']['sys_language_uid'][0]
) {
$languageId = (int)$this->data['databaseRow']['sys_language_uid'][0];
}
$languageId = (int)$this->data['databaseRow']['sys_language_uid'] ?? 0;

$resultArray = $this->initializeResultArray();

Expand Down
2 changes: 1 addition & 1 deletion Classes/Hooks/DrawHeaderHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(StandaloneView $templateView = null, PageRenderer $p
$this->templateView->getRenderingContext()->getTemplatePaths()->fillDefaultsByPackageName('page_speed_insights');
$this->templateView->setTemplate('DrawHeaderHook');

$this->strategyToShow = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['page_speed_insights']['strategyToShow'] ?: 'mobile';
$this->strategyToShow = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['page_speed_insights']['strategyToShow'] ?? 'mobile';
}

public function render(): string
Expand Down
8 changes: 4 additions & 4 deletions Classes/Utility/PageSpeedInsightsUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ protected static function getResult(string $url, string $strategy = 'mobile', ar

$rawData = curl_exec($ch);
$data = json_decode($rawData);
$categoriesArray = (array)$data->lighthouseResult->categories;

curl_close($ch);

Expand All @@ -73,6 +72,7 @@ protected static function getResult(string $url, string $strategy = 'mobile', ar
return $returnData;
}

$categoriesArray = (array)$data->lighthouseResult->categories;
if (property_exists($categoriesArray['performance'], 'score')) {
$returnData['performance']['score'] = (float)$categoriesArray['performance']->score * 100;
}
Expand Down Expand Up @@ -187,7 +187,7 @@ public static function getLastRun($pageId = 0, $strategy = ''): string
->execute()
->fetch();

return (string)$data['reference'];
return (string)($data['reference'] ?? $strategy . '-');
}

/**
Expand All @@ -203,7 +203,7 @@ public static function getLastRun($pageId = 0, $strategy = ''): string
* @param string $labelFormat
* @return array
*/
public static function getChartData($daysInPastToStartFrom, $daysPerStep, $pageId = 0, $strategy = '', $chartColor1 = '', $chartColor2 = '', $chartColor3 = '', $chartColor4 = '', $chartColor5 = '', $labelFormat = '%d-%m-%Y'): array
public static function getChartData($daysInPastToStartFrom, $daysPerStep, $pageId = 0, $strategy = '', $chartColor1 = '', $chartColor2 = '', $chartColor3 = '', $chartColor4 = '', $chartColor5 = '', $labelFormat = 'd-m-Y'): array
{
$labels = [];
$dataPerformance = [];
Expand All @@ -213,7 +213,7 @@ public static function getChartData($daysInPastToStartFrom, $daysPerStep, $pageI
$dataPwa = [];

for ($daysBefore = $daysInPastToStartFrom; $daysBefore >= 0; $daysBefore-=$daysPerStep) {
$labels[] = strftime($labelFormat, strtotime('-' . $daysBefore . ' day'));
$labels[] = date($labelFormat, strtotime('-' . $daysBefore . ' day'));
$startPeriod = strtotime('-' . $daysBefore . ' day 0:00:00');
$endPeriod = strtotime('-' . ($daysBefore - $daysPerStep + 1) . ' day 23:59:59');

Expand Down
6 changes: 6 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,9 @@ services:
additionalCssClasses: 'dashboard-item--chart'
height: 'large'
width: 'large'

Haassie\PageSpeedInsights\Command\CheckPageSpeedInsightsCommand:
tags:
- name: console.command
command: 'pagespeedinsights:run'
description: 'Check pages on PageSpeed Insight'