mirror of
https://github.com/DanielSiepmann/tracking.git
synced 2024-11-12 18:26:09 +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) {
|
||||
$record = $this->getRecord(
|
||||
$recordview['record_uid'],
|
||||
$recordview['record_table_name'],
|
||||
$recordview['sys_language_uid']
|
||||
$recordview['record_table_name']
|
||||
);
|
||||
|
||||
if (
|
||||
|
@ -188,13 +187,16 @@ class Recordviews implements ChartDataProviderInterface
|
|||
}
|
||||
|
||||
$result = $this->queryBuilder
|
||||
->selectLiteral('count(record) as total')
|
||||
->addSelect('record_uid', 'record_table_name', 'sys_language_uid')
|
||||
->selectLiteral(
|
||||
$this->queryBuilder->expr()->count('record', 'total'),
|
||||
$this->queryBuilder->expr()->max('uid', 'latest')
|
||||
)
|
||||
->addSelect('record_uid', 'record_table_name')
|
||||
->from('tx_tracking_recordview')
|
||||
->where(... $constraints)
|
||||
->groupBy('record')
|
||||
->groupBy('record', 'record_uid', 'record_table_name')
|
||||
->orderBy('total', 'desc')
|
||||
->addOrderBy('uid', 'desc')
|
||||
->addOrderBy('latest', 'desc')
|
||||
->setMaxResults($this->maxResults)
|
||||
->execute();
|
||||
|
||||
|
@ -205,14 +207,13 @@ class Recordviews implements ChartDataProviderInterface
|
|||
|
||||
private function getRecord(
|
||||
int $uid,
|
||||
string $table,
|
||||
int $sysLanguageUid
|
||||
string $table
|
||||
): array {
|
||||
$recordTypeField = $GLOBALS['TCA'][$table]['ctrl']['type'] ?? '';
|
||||
|
||||
$record = BackendUtility::getRecord($table, $uid);
|
||||
if ($sysLanguageUid > 0 && count($this->languageLimitation) === 1 && $record !== null) {
|
||||
$record = $this->pageRepository->getRecordOverlay($table, $record, $sysLanguageUid);
|
||||
if (count($this->languageLimitation) === 1 && $record !== null) {
|
||||
$record = $this->pageRepository->getRecordOverlay($table, $record, $this->languageLimitation[0]);
|
||||
}
|
||||
|
||||
return [
|
||||
|
|
Loading…
Reference in a new issue