From 856fb1b5e8eb410990c308c2c59fd3f41914647d Mon Sep 17 00:00:00 2001 From: Richard Haeser Date: Wed, 23 Sep 2020 19:50:01 +0200 Subject: [PATCH] [TASK] Return proper exit codes and show error message when check did not succeed Resolves: #8 --- .../Command/CheckPageSpeedInsightsCommand.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Classes/Command/CheckPageSpeedInsightsCommand.php b/Classes/Command/CheckPageSpeedInsightsCommand.php index db1ff1c..141152c 100644 --- a/Classes/Command/CheckPageSpeedInsightsCommand.php +++ b/Classes/Command/CheckPageSpeedInsightsCommand.php @@ -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 @@ -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('' . $row['uid'] . ': Check for ' . $url . ' failed for mobile. Error message: ' . $pageSpeedInsightsResultsMobile['error']['message'] . ''); + } 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('' . $row['uid'] . ': Check for ' . $url . ' failed for desktop. Error message: ' . $pageSpeedInsightsResultsDesktop['error']['message'] . ''); + } else { + $output->writeln($row['uid'] . ': ' . $row['slug'] . ': ' . $url . ' (' . implode(', ', $strategies) . ') succeeded for desktop'); + } } - return 0; + return $errors; } }