diff --git a/phpBB/phpbb/db/tools/doctrine.php b/phpBB/phpbb/db/tools/doctrine.php index 043252b4c5..49ff2a23b6 100644 --- a/phpBB/phpbb/db/tools/doctrine.php +++ b/phpBB/phpbb/db/tools/doctrine.php @@ -686,24 +686,16 @@ class doctrine implements tools_interface $columns = (is_array($key_data[1])) ? $key_data[1] : [$key_data[1]]; $key_name = !str_starts_with($key_name, $short_table_name) ? self::add_prefix($key_name, $short_table_name) : $key_name; - // Supports key columns defined with there length - $columns = array_map(function (string $column) - { - if (strpos($column, ':') !== false) - { - $parts = explode(':', $column, 2); - return $parts[0]; - } - return $column; - }, $columns); + $options = []; + $this->schema_get_index_key_data($columns, $options); if ($key_data[0] === 'UNIQUE') { - $table->addUniqueIndex($columns, $key_name); + $table->addUniqueIndex($columns, $key_name, $options); } else { - $table->addIndex($columns, $key_name); + $table->addIndex($columns, $key_name, [], $options); } } } @@ -900,7 +892,10 @@ class doctrine implements tools_interface return; } - $table->addIndex($columns, $index_name); + $options = []; + $this->schema_get_index_key_data($columns, $options); + + $table->addIndex($columns, $index_name, [], $options); } /** @@ -956,7 +951,10 @@ class doctrine implements tools_interface return; } - $table->addUniqueIndex($columns, $index_name); + $options = []; + $this->schema_get_index_key_data($columns, $options); + + $table->addUniqueIndex($columns, $index_name, $options); } /** @@ -1005,6 +1003,30 @@ class doctrine implements tools_interface $table->setPrimaryKey($columns); } + /** + * Checks if index data contains key length + * and put it into $options['lengths'] array. + * Handles key length in formats of 'keyname:123' or 'keyname(123)' + * + * @param array $columns + * @param array $options + */ + protected function schema_get_index_key_data(array &$columns, array &$options): void + { + if (!empty($columns)) + { + $columns = array_map(function (string $column) use (&$options) + { + if (preg_match('/^([a-zA-Z0-9_]+)(?:(?:\:|\()([0-9]{1,3})\)?)?$/', $column, $parts)) + { + $options['lengths'][] = $parts[2] ?? null; + return $parts[1]; + } + return $column; + }, $columns); + } + } + /** * Recreate an index of a table *