Project

General

Profile

Actions

Bug #88876

closed

PageRepository ignores multiple orderings when fetching subpages for pages

Added by Elias Häußler almost 5 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Frontend
Target version:
-
Start date:
2019-08-01
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
9
PHP Version:
7.2
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:

Description

The PageRepository currently does not allow to define multiple orderings when fetching subpages for pages.

When I call either $pageRepository->getMenu(<uid>, '*', 'crdate DESC, sorting ASC') or $pageRepository->getMenuForPages([<uids>], '*', 'crdate DESC, sorting ASC') (for example), the last defined order field (in this case sorting) takes precedence as it overrides all previously defined fields (in this case crdate).

Affected code:

if (!empty($sortField)) {
    $orderBy = QueryHelper::parseOrderBy($sortField);
    foreach ($orderBy as $order) {
        $res->orderBy(...$order);
    }
}

Source: https://github.com/TYPO3/TYPO3.CMS/blob/master/typo3/sysext/core/Classes/Domain/Repository/PageRepository.php#L760-L765

The problem is that each $res->orderBy() replaces the previous calls as the QueryBuilder replaces the queryPart instead of adding it.

I would suggest to check if an orderBy query part has been added previously and in this case to use $res->addOrderBy(). This leads to the following code:

if (!empty($sortField)) {
    $orderBy = QueryHelper::parseOrderBy($sortField);
    foreach ($orderBy as $order) {
        if (!$res->getQueryPart('orderBy')) {
            $res->orderBy(...$order);
        } else {
            $res->addOrderBy(...$order);
        }
    }
}

What do you think?

Actions

Also available in: Atom PDF