[FOLLOWUP][TASK] Doctrine: Migrate \TYPO3\CMS\Frontend\Page\PageRepository 56/49456/2
authorGeorg Ringer <georg.ringer@gmail.com>
Thu, 11 Aug 2016 17:33:17 +0000 (19:33 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 11 Aug 2016 20:16:01 +0000 (22:16 +0200)
The sorting field is optional and an empty field leads
to an invalid  query.

Resolves: #76543
Releases: master
Change-Id: I7e4e6c7ea873891b43d428d4db4a2d7ca63dc390
Reviewed-on: https://review.typo3.org/49456
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/frontend/Classes/Page/PageRepository.php

index aa9963f..a22b7aa 100644 (file)
@@ -697,16 +697,19 @@ class PageRepository
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
         $queryBuilder->getRestrictions()->removeAll();
 
-        $result = $queryBuilder->select(...GeneralUtility::trimExplode(',', $fields, true))
+        $res = $queryBuilder->select(...GeneralUtility::trimExplode(',', $fields, true))
             ->from('pages')
             ->where(
                 $queryBuilder->expr()->in($relationField, array_map('intval', $pageIds)),
                 QueryHelper::stripLogicalOperatorPrefix($this->where_hid_del),
                 QueryHelper::stripLogicalOperatorPrefix($this->where_groupAccess),
                 QueryHelper::stripLogicalOperatorPrefix($additionalWhereClause)
-            )
-            ->orderBy($sortField)
-            ->execute();
+            );
+
+        if (!empty($sortField)) {
+            $res->orderBy($sortField);
+        }
+        $result = $res->execute();
 
         while ($page = $result->fetch()) {
             $originalUid = $page['uid'];