From 930903e39f2038c4b9df7310bf0150d62439d5ec Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 12 Aug 2020 15:54:03 +0200 Subject: [PATCH] Fix SQL query for pageviewsperpage widget The existing query was not fully working as intended. Also it did not work with proper MySQL sql_mode settings. This is fixed by building a proper query which delivers expected and deterministic results. We now always have latest records first. Also there is no need to fetch the sys_language_uid, as we only fetch localized record if only one language is allowed. That way we can just check configuration and use the configuration to do language overlay. Also there was no need for an join, therefore query was reduced to necessary stuff. Relates: #35 --- .../Dashboard/Provider/PageviewsPerPage.php | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/Classes/Dashboard/Provider/PageviewsPerPage.php b/Classes/Dashboard/Provider/PageviewsPerPage.php index 38cddb3..e1dc9c3 100644 --- a/Classes/Dashboard/Provider/PageviewsPerPage.php +++ b/Classes/Dashboard/Provider/PageviewsPerPage.php @@ -125,28 +125,22 @@ class PageviewsPerPage implements ChartDataProviderInterface } $result = $this->queryBuilder - ->selectLiteral('count(tx_tracking_pageview.pid) as total') - ->addSelect('pages.uid', 'tx_tracking_pageview.sys_language_uid') - ->from('tx_tracking_pageview') - ->leftJoin( - 'tx_tracking_pageview', - 'pages', - 'pages', - $this->queryBuilder->expr()->eq( - 'tx_tracking_pageview.pid', - $this->queryBuilder->quoteIdentifier('pages.uid') - ) + ->selectLiteral( + $this->queryBuilder->expr()->count('pid', 'total'), + $this->queryBuilder->expr()->max('uid', 'latest') ) + ->addSelect('pid') + ->from('tx_tracking_pageview') ->where(... $constraints) - ->groupBy('tx_tracking_pageview.pid') + ->groupBy('pid') ->orderBy('total', 'desc') - ->addOrderBy('tx_tracking_pageview.uid', 'desc') + ->addOrderBy('latest', 'desc') ->setMaxResults($this->maxResults) ->execute() ->fetchAll(); foreach ($result as $row) { - $labels[] = $this->getRecordTitle($row['uid'], $row['sys_language_uid']); + $labels[] = $this->getRecordTitle($row['pid']); $data[] = $row['total']; } @@ -156,11 +150,11 @@ class PageviewsPerPage implements ChartDataProviderInterface ]; } - private function getRecordTitle(int $uid, int $sysLanguageUid): string + private function getRecordTitle(int $uid): string { $record = BackendUtility::getRecord('pages', $uid); - if ($sysLanguageUid > 0 && count($this->languageLimitation) === 1 && $record !== null) { - $record = $this->pageRepository->getRecordOverlay('pages', $record, $sysLanguageUid); + if (count($this->languageLimitation) === 1 && $record !== null) { + $record = $this->pageRepository->getRecordOverlay('pages', $record, $this->languageLimitation[0]); } return strip_tags(BackendUtility::getRecordTitle('pages', $record, true));