[BUGFIX] Drop sorting in COUNT() query in list module 77/53677/2
authorSusanne Moog <susanne.moog@typo3.com>
Fri, 11 Aug 2017 09:27:51 +0000 (11:27 +0200)
committerSusanne Moog <susanne.moog@typo3.org>
Fri, 11 Aug 2017 10:59:18 +0000 (12:59 +0200)
The list module throws an exception on mssql as there
is a COUNT(*) query done with an ORDER BY sorting.

Sorting the count is pretty useless and has been
removed.

Change-Id: I8d94da2dc3dfecb7c20308180e9916b16b152b01
Resolves: #82084
Releases: master, 8.7
Reviewed-on: https://review.typo3.org/53677
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/recordlist/Classes/RecordList/AbstractDatabaseRecordList.php

index 2436281..c5a74c1 100644 (file)
@@ -703,6 +703,7 @@ class AbstractDatabaseRecordList extends AbstractRecordList
      * @param string[] $fieldList List of fields to select from the table
      * @param string[] $additionalConstraints Additional part for where clause
      * @param QueryBuilder $queryBuilder
+     * @paran bool $addSorting
      * @return QueryBuilder
      */
     protected function prepareQueryBuilder(
@@ -710,7 +711,8 @@ class AbstractDatabaseRecordList extends AbstractRecordList
         int $pageId,
         array $fieldList = ['*'],
         array $additionalConstraints = [],
-        QueryBuilder $queryBuilder
+        QueryBuilder $queryBuilder,
+        bool $addSorting = true
     ): QueryBuilder {
         $parameters = [
             'table' => $table,
@@ -725,13 +727,15 @@ class AbstractDatabaseRecordList extends AbstractRecordList
             $queryBuilder->setMaxResults($this->iLimit);
         }
 
-        if ($this->sortField && in_array($this->sortField, $this->makeFieldList($table, 1))) {
-            $queryBuilder->orderBy($this->sortField, $this->sortRev ? 'DESC' : 'ASC');
-        } else {
-            $orderBy = $GLOBALS['TCA'][$table]['ctrl']['sortby'] ?: $GLOBALS['TCA'][$table]['ctrl']['default_sortby'];
-            $orderBys = QueryHelper::parseOrderBy((string)$orderBy);
-            foreach ($orderBys as $orderBy) {
-                $queryBuilder->orderBy($orderBy[0], $orderBy[1]);
+        if ($addSorting) {
+            if ($this->sortField && in_array($this->sortField, $this->makeFieldList($table, 1))) {
+                $queryBuilder->orderBy($this->sortField, $this->sortRev ? 'DESC' : 'ASC');
+            } else {
+                $orderBy = $GLOBALS['TCA'][$table]['ctrl']['sortby'] ?: $GLOBALS['TCA'][$table]['ctrl']['default_sortby'];
+                $orderBys = QueryHelper::parseOrderBy((string)$orderBy);
+                foreach ($orderBys as $orderBy) {
+                    $queryBuilder->orderBy($orderBy[0], $orderBy[1]);
+                }
             }
         }
 
@@ -835,7 +839,7 @@ class AbstractDatabaseRecordList extends AbstractRecordList
             $queryBuilder->andWhere(...$constraints);
         }
 
-        $queryBuilder = $this->prepareQueryBuilder($table, $pageId, ['*'], $constraints, $queryBuilder);
+        $queryBuilder = $this->prepareQueryBuilder($table, $pageId, ['*'], $constraints, $queryBuilder, false);
 
         $this->totalItems = (int)$queryBuilder->count('*')
             ->execute()