From af93b1aee997502bae38b2590ecfac5a31d45006 Mon Sep 17 00:00:00 2001 From: rxu Date: Tue, 10 Jun 2025 11:31:48 +0700 Subject: [PATCH] [ticket/17524] Add index data getter to db tools PHPBB-17524 --- phpBB/phpbb/db/tools/doctrine.php | 44 +++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/db/tools/doctrine.php b/phpBB/phpbb/db/tools/doctrine.php index 73d47117ce..c7616a2a27 100644 --- a/phpBB/phpbb/db/tools/doctrine.php +++ b/phpBB/phpbb/db/tools/doctrine.php @@ -378,6 +378,46 @@ class doctrine implements tools_interface } } + /** + * Returns an array of the table index names and relevant data in format + * [ + * [$index_name] = [ + * 'columns' => (array) $index_columns, + * 'flags' => (array) $index_flags, + * 'options' => (array) $index_options, + * 'is_primary'=> (bool) $isPrimary, + * 'is_unique' => (bool) $isUnique, + * 'is_simple' => (bool) $isSimple, + * ] + * + * @param Schema $schema + * @param string $table_name + * @param string $column_name + * @param array $column_data + * @param bool $safe_check + * + * @throws SchemaException + */ + public function sql_get_table_index_data(string $table_name): array + { + $schema = $this->get_schema(); + $table = $schema->getTable($table_name); + $indexes = []; + foreach ($table->getIndexes() as $index) + { + $indexes[$index->getName()] = [ + 'columns' => array_map('strtolower', $index->getUnquotedColumns()), + 'flags' => $index->getFlags(), + 'options' => $index->getOptions(), + 'is_primary'=> $index->isPrimary(), + 'is_unique' => $index->isUnique(), + 'is_simple' => $index->isSimpleIndex(), + ]; + } + + return $indexes; + } + /** * Returns an array of indices for either unique and primary keys, or simple indices. * @@ -908,8 +948,8 @@ class doctrine implements tools_interface return $parts[1]; } return $column; - }, $columns); - } + }, $columns); + } } /**