[BUGFIX] Drop sorting in COUNT() query in list module 80/53680/2
authorSusanne Moog <susanne.moog@typo3.com>
Fri, 11 Aug 2017 11:07:18 +0000 (13:07 +0200)
committerSusanne Moog <susanne.moog@typo3.org>
Fri, 18 Aug 2017 07:56:43 +0000 (09:56 +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/53680
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/recordlist/Classes/RecordList/AbstractDatabaseRecordList.php

index 42276a5..d1c8668 100644 (file)
@@ -790,13 +790,15 @@ class AbstractDatabaseRecordList extends AbstractRecordList
      * @param int $pageId Page id Only used to build the search constraints, $this->pidList is used for restrictions
      * @param string[] $fieldList List of fields to select from the table
      * @param string[] $additionalConstraints Additional part for where clause
+     * @param bool $addSorting Add sorting fields to query
      * @return array
      */
     protected function buildQueryParameters(
         string $table,
         int $pageId,
         array $fieldList = ['*'],
-        array $additionalConstraints = []
+        array $additionalConstraints = [],
+        bool $addSorting = true
     ): array {
         $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
             ->getQueryBuilderForTable($table)
@@ -811,11 +813,13 @@ class AbstractDatabaseRecordList extends AbstractRecordList
             'maxResults' => $this->iLimit ? $this->iLimit : null,
         ];
 
-        if ($this->sortField && in_array($this->sortField, $this->makeFieldList($table, 1))) {
-            $parameters['orderBy'][] = $this->sortRev ? [$this->sortField, 'DESC'] : [$this->sortField, 'ASC'];
-        } else {
-            $orderBy = $GLOBALS['TCA'][$table]['ctrl']['sortby'] ?: $GLOBALS['TCA'][$table]['ctrl']['default_sortby'];
-            $parameters['orderBy'] = QueryHelper::parseOrderBy((string)$orderBy);
+        if ($addSorting === true) {
+            if ($this->sortField && in_array($this->sortField, $this->makeFieldList($table, 1))) {
+                $parameters['orderBy'][] = $this->sortRev ? [$this->sortField, 'DESC'] : [$this->sortField, 'ASC'];
+            } else {
+                $orderBy = $GLOBALS['TCA'][$table]['ctrl']['sortby'] ?: $GLOBALS['TCA'][$table]['ctrl']['default_sortby'];
+                $parameters['orderBy'] = QueryHelper::parseOrderBy((string)$orderBy);
+            }
         }
 
         // Build the query constraints
@@ -876,7 +880,7 @@ class AbstractDatabaseRecordList extends AbstractRecordList
      */
     public function setTotalItems(string $table, int $pageId, array $constraints)
     {
-        $queryParameters = $this->buildQueryParameters($table, $pageId, ['*'], $constraints);
+        $queryParameters = $this->buildQueryParameters($table, $pageId, ['*'], $constraints, false);
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
             ->getQueryBuilderForTable($queryParameters['table']);
         $queryBuilder->getRestrictions()