Bug #88876
closedPageRepository ignores multiple orderings when fetching subpages for pages
100%
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);
}
}
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?