mirror of
https://github.com/DanielSiepmann/tracking.git
synced 2024-11-25 06:36:12 +01:00
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
This commit is contained in:
parent
27e0623794
commit
930903e39f
1 changed files with 11 additions and 17 deletions
|
@ -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));
|
||||
|
|
Loading…
Reference in a new issue