From cc79d2e375587dbf87facca3f5fc98d4b1c0bae6 Mon Sep 17 00:00:00 2001 From: Clemente Raposo Date: Thu, 11 Mar 2021 11:15:48 +0000 Subject: [PATCH] Add error handling to default subpanel statistic - Check if queries is empty -- Return error statistic -- Add logging --- core/legacy/Statistics/SubpanelDefault.php | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/core/legacy/Statistics/SubpanelDefault.php b/core/legacy/Statistics/SubpanelDefault.php index ab41c4507..dc3110caa 100644 --- a/core/legacy/Statistics/SubpanelDefault.php +++ b/core/legacy/Statistics/SubpanelDefault.php @@ -5,13 +5,20 @@ namespace App\Legacy\Statistics; use App\Entity\Statistic; use App\Legacy\Data\PresetDataHandlers\SubpanelDataQueryHandler; use App\Service\StatisticsProviderInterface; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerInterface; -class SubpanelDefault extends SubpanelDataQueryHandler implements StatisticsProviderInterface +class SubpanelDefault extends SubpanelDataQueryHandler implements StatisticsProviderInterface, LoggerAwareInterface { use StatisticsHandlingTrait; public const KEY = 'default'; + /** + * @var LoggerInterface + */ + protected $logger; + /** * @inheritDoc */ @@ -38,6 +45,12 @@ class SubpanelDefault extends SubpanelDataQueryHandler implements StatisticsProv $queries = $this->getQueries($module, $id, $subpanel); + if (empty($queries)) { + $this->logger->error('default-statistic: No queries found.', ['query' => $query]); + + return $this->getErrorResponse(self::KEY); + } + $parts = $queries[0]; $parts['select'] = 'SELECT COUNT(*) as value'; @@ -50,4 +63,12 @@ class SubpanelDefault extends SubpanelDataQueryHandler implements StatisticsProv return $statistic; } + + /** + * @inheritDoc + */ + public function setLogger(LoggerInterface $logger) + { + $this->logger = $logger; + } }