mirror of
https://github.com/DanielSiepmann/tracking.git
synced 2024-11-22 05:56:08 +01:00
Fix SQL query for recordviews 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. Relates: #35
This commit is contained in:
parent
8f755f79f2
commit
27e0623794
1 changed files with 11 additions and 10 deletions
|
@ -127,8 +127,7 @@ class Recordviews implements ChartDataProviderInterface
|
||||||
foreach ($this->getRecordviewsRecords() as $recordview) {
|
foreach ($this->getRecordviewsRecords() as $recordview) {
|
||||||
$record = $this->getRecord(
|
$record = $this->getRecord(
|
||||||
$recordview['record_uid'],
|
$recordview['record_uid'],
|
||||||
$recordview['record_table_name'],
|
$recordview['record_table_name']
|
||||||
$recordview['sys_language_uid']
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
@ -188,13 +187,16 @@ class Recordviews implements ChartDataProviderInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->queryBuilder
|
$result = $this->queryBuilder
|
||||||
->selectLiteral('count(record) as total')
|
->selectLiteral(
|
||||||
->addSelect('record_uid', 'record_table_name', 'sys_language_uid')
|
$this->queryBuilder->expr()->count('record', 'total'),
|
||||||
|
$this->queryBuilder->expr()->max('uid', 'latest')
|
||||||
|
)
|
||||||
|
->addSelect('record_uid', 'record_table_name')
|
||||||
->from('tx_tracking_recordview')
|
->from('tx_tracking_recordview')
|
||||||
->where(... $constraints)
|
->where(... $constraints)
|
||||||
->groupBy('record')
|
->groupBy('record', 'record_uid', 'record_table_name')
|
||||||
->orderBy('total', 'desc')
|
->orderBy('total', 'desc')
|
||||||
->addOrderBy('uid', 'desc')
|
->addOrderBy('latest', 'desc')
|
||||||
->setMaxResults($this->maxResults)
|
->setMaxResults($this->maxResults)
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
|
@ -205,14 +207,13 @@ class Recordviews implements ChartDataProviderInterface
|
||||||
|
|
||||||
private function getRecord(
|
private function getRecord(
|
||||||
int $uid,
|
int $uid,
|
||||||
string $table,
|
string $table
|
||||||
int $sysLanguageUid
|
|
||||||
): array {
|
): array {
|
||||||
$recordTypeField = $GLOBALS['TCA'][$table]['ctrl']['type'] ?? '';
|
$recordTypeField = $GLOBALS['TCA'][$table]['ctrl']['type'] ?? '';
|
||||||
|
|
||||||
$record = BackendUtility::getRecord($table, $uid);
|
$record = BackendUtility::getRecord($table, $uid);
|
||||||
if ($sysLanguageUid > 0 && count($this->languageLimitation) === 1 && $record !== null) {
|
if (count($this->languageLimitation) === 1 && $record !== null) {
|
||||||
$record = $this->pageRepository->getRecordOverlay($table, $record, $sysLanguageUid);
|
$record = $this->pageRepository->getRecordOverlay($table, $record, $this->languageLimitation[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
Loading…
Reference in a new issue