From 112145086406b4c7ef007d74aa31e1dc83fdd3d9 Mon Sep 17 00:00:00 2001 From: Nicolai Ehrhardt <245527909+predictor2718@users.noreply.github.com> Date: Sat, 22 Nov 2025 19:15:56 +0100 Subject: [PATCH] Fix descending index being converted to ascending (#19749) Signed-off-by: Nicolai Ehrhardt <245527909+predictor2718@users.noreply.github.com> --- libraries/classes/Index.php | 3 +++ libraries/classes/IndexColumn.php | 2 +- libraries/classes/Table.php | 13 +++++++++++-- templates/table/index_form.twig | 10 ++++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/libraries/classes/Index.php b/libraries/classes/Index.php index 79f9e3a239..819e05a2f4 100644 --- a/libraries/classes/Index.php +++ b/libraries/classes/Index.php @@ -271,11 +271,14 @@ class Index // coming from form // $columns[names][] // $columns[sub_parts][] + // $columns[collations][] foreach ($columns['names'] as $key => $name) { $sub_part = $columns['sub_parts'][$key] ?? ''; + $collation = $columns['collations'][$key] ?? $_columns[] = [ 'Column_name' => $name, 'Sub_part' => $sub_part, + 'Collation' => $collation, ]; } } else { diff --git a/libraries/classes/IndexColumn.php b/libraries/classes/IndexColumn.php index 4921002f32..8b98223d9a 100644 --- a/libraries/classes/IndexColumn.php +++ b/libraries/classes/IndexColumn.php @@ -17,7 +17,7 @@ class IndexColumn /** @var int The column sequence number in the index, starting with 1. */ private $seqInIndex = 1; - /** @var string|null How the column is sorted in the index. "A" (Ascending) or NULL (Not sorted) */ + /** @var string|null How the column is sorted in the index. "A" (Ascending), "D" (Descending) or NULL (Not sorted) */ private $collation = null; /** diff --git a/libraries/classes/Table.php b/libraries/classes/Table.php index 426ae59629..e6419cda1b 100644 --- a/libraries/classes/Table.php +++ b/libraries/classes/Table.php @@ -2137,11 +2137,20 @@ class Table implements Stringable $indexFields = []; foreach ($index->getColumns() as $key => $column) { $indexFields[$key] = Util::backquote($column->getName()); - if (! $column->getSubPart()) { + if ($column->getSubPart()) { + $indexFields[$key] .= '(' . $column->getSubPart() . ')'; + } + + if (! $column->getCollation()) { continue; } - $indexFields[$key] .= '(' . $column->getSubPart() . ')'; + $collation = $column->getCollation(); + if ($collation === 'A') { + $indexFields[$key] .= ' ASC'; + } elseif ($collation === 'D') { + $indexFields[$key] .= ' DESC'; + } } if (empty($indexFields)) { diff --git a/templates/table/index_form.twig b/templates/table/index_form.twig index cb18d52e54..398b807c8c 100644 --- a/templates/table/index_form.twig +++ b/templates/table/index_form.twig @@ -143,6 +143,9 @@