Skip to content

Commit

Permalink
[TASK] Return proper exit codes and show error message when check did…
Browse files Browse the repository at this point in the history
… not succeed

Resolves: #8
  • Loading branch information
Richard Haeser committed Sep 23, 2020
1 parent 1f3d8f0 commit 856fb1b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Classes/Command/CheckPageSpeedInsightsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function configure(): void
public function execute(InputInterface $input, OutputInterface $output)
{
$reference = 'command-' . time();
$errors = 0;

$queryBuilderPages = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages')->createQueryBuilder();
$result = $queryBuilderPages
Expand All @@ -48,10 +49,22 @@ public function execute(InputInterface $input, OutputInterface $output)

$strategies = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['page_speed_insights']['strategies'] ?: ['performance', 'seo', 'accessibility', 'best-practices', 'pwa'];
$pageSpeedInsightsResultsMobile = PageSpeedInsightsUtility::checkUrl($url, 'mobile', $strategies, $reference, $pageId, $languageId, $pid, (string)$input->getArgument('key'));
if (array_key_exists('error', $pageSpeedInsightsResultsMobile)) {
$errors = 10;
$output->writeln('<error>' . $row['uid'] . ': Check for ' . $url . ' failed for mobile. Error message: ' . $pageSpeedInsightsResultsMobile['error']['message'] . '</error>');
} else {
$output->writeln($row['uid'] . ': ' . $row['slug'] . ': ' . $url . ' (' . implode(', ', $strategies) . ') succeeded for mobile');
}

$pageSpeedInsightsResultsDesktop = PageSpeedInsightsUtility::checkUrl($url, 'desktop', $strategies, $reference, $pageId, $languageId, $pid, (string)$input->getArgument('key'));
$output->writeln($row['uid'] . ': ' . $row['slug'] . ': ' . $url . ' (' . implode(', ', $strategies) . ')');
if (array_key_exists('error', $pageSpeedInsightsResultsDesktop)) {
$errors = 10;
$output->writeln('<error>' . $row['uid'] . ': Check for ' . $url . ' failed for desktop. Error message: ' . $pageSpeedInsightsResultsDesktop['error']['message'] . '</error>');
} else {
$output->writeln($row['uid'] . ': ' . $row['slug'] . ': ' . $url . ' (' . implode(', ', $strategies) . ') succeeded for desktop');
}
}

return 0;
return $errors;
}
}

0 comments on commit 856fb1b

Please sign in to comment.