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:
Daniel Siepmann 2020-08-12 15:38:50 +02:00
parent 8f755f79f2
commit 27e0623794

View file

@ -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 [