From d5478c928a13ed81563b900f652b2b65b24e26dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BCrk?= Date: Tue, 19 Mar 2024 14:49:32 +0100 Subject: [PATCH] [BUGFIX] Ensure working count query in `DatabaseRecordList::getTable()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `\TYPO3\CMS\Backend\RecordList\DatabaseRecordList` provides the ability to modify the QueryBuilder used for the record list representation with the PSR-14 `ModifyDatabaseQueryForRecordListingEvent`, after generic query information like default orderings and similar have been added. That is covered within the `getQueryBuilder()` method, which is used in other class methods, for example in `getTables()` where it is changed to a `COUNT()` query. MariaDB for example is picky about count queries using `order by`, `group by` or aggregation methods which are not reflected or added in the counter parts leading to a not so useful error like Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause or similar variants. This error message can be missleading for the case a order by has been used along with a COUNT() query. Listener of the event do not get the information if order-by can be added or should be left out, therefore maybe adding sorting conditions for a count query. This change now resets any order statements for the count-query like other places in the TYPO3 core. Resolves: #103427 Releases: main, 12.4, 11.5 Change-Id: Ie421993a1890dd6682d02f54203d538e6ae1b76c Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83523 Reviewed-by: Thomas Hohn Tested-by: core-ci Reviewed-by: Stefan Bürk Tested-by: Christian Kuhn Tested-by: Garvin Hicking Reviewed-by: Christian Kuhn Reviewed-by: Garvin Hicking Tested-by: Stefan Bürk --- .../backend/Classes/RecordList/DatabaseRecordList.php | 7 ++++++- .../Event/ModifyDatabaseQueryForRecordListingEvent.php | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/typo3/sysext/backend/Classes/RecordList/DatabaseRecordList.php b/typo3/sysext/backend/Classes/RecordList/DatabaseRecordList.php index ecc5c8dc66f5..65c0e373bfd1 100644 --- a/typo3/sysext/backend/Classes/RecordList/DatabaseRecordList.php +++ b/typo3/sysext/backend/Classes/RecordList/DatabaseRecordList.php @@ -528,7 +528,9 @@ public function getTable($table) { // Finding the total amount of records on the page $queryBuilderTotalItems = $this->getQueryBuilder($table, ['*'], false, 0, 1); - $totalItems = (int)$queryBuilderTotalItems->count('*') + $totalItems = (int)$queryBuilderTotalItems + ->count('*') + ->resetOrderBy() ->executeQuery() ->fetchOne(); if ($totalItems === 0) { @@ -2442,6 +2444,9 @@ public function getQueryBuilder( ); } + // @todo This event should contain the $addSorting value, so listener knows when to add ORDER-BY stuff. + // Additionally, having QueryBuilder order-by with `addSorting: false` should be deprecated along + // with the additional event flag. $event = new ModifyDatabaseQueryForRecordListingEvent( $queryBuilder, $table, diff --git a/typo3/sysext/backend/Classes/View/Event/ModifyDatabaseQueryForRecordListingEvent.php b/typo3/sysext/backend/Classes/View/Event/ModifyDatabaseQueryForRecordListingEvent.php index 36e604477cb8..c5b069d9d943 100644 --- a/typo3/sysext/backend/Classes/View/Event/ModifyDatabaseQueryForRecordListingEvent.php +++ b/typo3/sysext/backend/Classes/View/Event/ModifyDatabaseQueryForRecordListingEvent.php @@ -23,6 +23,7 @@ /** * Use this Event to alter the database query when loading content for a page (usually in the list module) * before it is executed. + * @todo This event should contain the $addSorting value, so listener knows when to add ORDER-BY stuff. */ final class ModifyDatabaseQueryForRecordListingEvent {