From 2491c7a371c9c66b780893b48dd657d1964e100a Mon Sep 17 00:00:00 2001 From: Daniel Hoffmann Date: Tue, 5 Nov 2024 11:16:48 +0100 Subject: [PATCH] [BUGFIX] Correct foreign_table_where handling When there is an order by in the where clause it is now correctly handled. Resolves: https://projekte.in2code.de/issues/67832 --- .../Core/PreProcessing/PreProcessor/SelectProcessor.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Classes/Component/Core/PreProcessing/PreProcessor/SelectProcessor.php b/Classes/Component/Core/PreProcessing/PreProcessor/SelectProcessor.php index 7e4bfede6..e246d5aec 100755 --- a/Classes/Component/Core/PreProcessing/PreProcessor/SelectProcessor.php +++ b/Classes/Component/Core/PreProcessing/PreProcessor/SelectProcessor.php @@ -88,7 +88,14 @@ protected function buildResolver(string $table, string $column, array $processed } } $additionalWhere = implode(' AND ', $foreignMatchFields); - $foreignTableWhere = implode(' AND ', array_filter([$foreignTableWhere, $additionalWhere])); + if (1 === preg_match(AbstractProcessor::ADDITIONAL_ORDER_BY_PATTERN, $foreignTableWhere, $matches) && !empty($matches['where'])) { + $foreignTableWhere = implode(' AND ', [$matches['where'], $additionalWhere]); + if (!empty($matches['col'])) { + $foreignTableWhere .= ' ORDER BY ' . $matches['col'] . ($matches['dir'] ?? ''); + } + } else { + $foreignTableWhere = implode(' AND ', [$foreignTableWhere, $additionalWhere]); + } $foreignTableWhere = DatabaseUtility::stripLogicalOperatorPrefix($foreignTableWhere); $foreignTableWhere = $this->tcaEscapingMarkerService->escapeMarkedIdentifier($foreignTableWhere);