[ticket/17525] Add database schema getter

PHPBB-17525
This commit is contained in:
rxu 2025-06-25 20:52:45 +07:00
parent 1339a31c23
commit a229797cd7
No known key found for this signature in database
GPG key ID: 955F0567380E586A
2 changed files with 26 additions and 3 deletions

View file

@ -130,11 +130,12 @@ class table_helper
* @param array $table_prefix Tables prefix.
*
* @return array<string, string> Pairs of table names and their short name representations.
* @psalm-return array{string, string}
*/
public static function map_short_table_names(array $additional_tables = [], string $table_prefix = ''): array
{
$short_table_names_map = [
"{$table_prefix}acl_groups" => 'aclgrps',
"{$table_prefix}acl_groups" => 'aclgrps',
"{$table_prefix}acl_options" => 'aclopts',
"{$table_prefix}acl_roles" => 'aclrls',
"{$table_prefix}acl_roles_data" => 'aclrlsdt',

View file

@ -28,12 +28,11 @@ class rename_duplicated_index_names extends migration
public function update_schema()
{
$rename_index = $table_keys = [];
$db_table_schema = json_decode(file_get_contents($this->phpbb_root_path . 'store/schema.json'), true);
$db_table_schema = $this->get_schema();
foreach ($db_table_schema as $table_name => $table_data)
{
if (isset($table_data['KEYS']))
{
$table_name = $this->table_prefix . $table_name;
foreach ($table_data['KEYS'] as $key_name => $key_data)
{
$table_keys[$table_name][] = $key_name;
@ -66,4 +65,27 @@ class rename_duplicated_index_names extends migration
return $schema;
}
protected function get_schema()
{
$self_classname = '\\' . str_replace('/', '\\', self::class);
$finder_factory = new \phpbb\finder\factory(null, false, $this->phpbb_root_path, $this->php_ext);
$finder = $finder_factory->get();
$migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
$self_class_index = array_search($self_classname, $migrator_classes);
unset($migrator_classes[$self_class_index]);
$schema_generator = new \phpbb\db\migration\schema_generator(
$migrator_classes,
$this->config,
$this->db,
$this->db_tools,
$this->phpbb_root_path,
$this->php_ext,
$this->table_prefix,
$this->tables
);
return $schema_generator->get_schema();
}
}