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 1/3] 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 @@ {% trans 'Size' %} + + {% trans 'Collation' %} + {% set spatial_types = [ @@ -190,6 +193,13 @@ value="{{ index.getChoice() != 'SPATIAL' ? column.getSubPart() }}"> + + + {% endfor %} {% if add_fields > 0 %} From 36b47f265b03708b83535e639d031cc7a8855769 Mon Sep 17 00:00:00 2001 From: Nicolai Ehrhardt <245527909+predictor2718@users.noreply.github.com> Date: Sat, 22 Nov 2025 19:36:01 +0100 Subject: [PATCH 2/3] Fix missing default value for collation (#19749) Signed-off-by: Nicolai Ehrhardt <245527909+predictor2718@users.noreply.github.com> --- libraries/classes/Index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/classes/Index.php b/libraries/classes/Index.php index 819e05a2f4..3225e10a42 100644 --- a/libraries/classes/Index.php +++ b/libraries/classes/Index.php @@ -274,7 +274,7 @@ class Index // $columns[collations][] foreach ($columns['names'] as $key => $name) { $sub_part = $columns['sub_parts'][$key] ?? ''; - $collation = $columns['collations'][$key] ?? + $collation = $columns['collations'][$key] ?? null; $_columns[] = [ 'Column_name' => $name, 'Sub_part' => $sub_part, From 62b7eb0c99ff73b021309e38096cc0840f5886e3 Mon Sep 17 00:00:00 2001 From: Nicolai Ehrhardt <245527909+predictor2718@users.noreply.github.com> Date: Sat, 3 Jan 2026 13:34:21 +0100 Subject: [PATCH 3/3] #19749 add support of adding index with collation --- templates/table/index_form.twig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/templates/table/index_form.twig b/templates/table/index_form.twig index 398b807c8c..c6e01d6e00 100644 --- a/templates/table/index_form.twig +++ b/templates/table/index_form.twig @@ -233,6 +233,13 @@ name="index[columns][sub_parts][]" value=""> + + + {% endfor %} {% endif %}