Compare commits

..

No commits in common. "5e9d616f5760812cd5ed6b63dca0fefb4adf0b78" and "1339a31c2369ed545dc086873e644bb28b5bce1b" have entirely different histories.

3 changed files with 6 additions and 88 deletions

View file

@ -127,15 +127,14 @@ class table_helper
* Maps short table names for the purpose of prefixing tables' index names.
*
* @param array $additional_tables Additional table names without prefix to add to the map.
* @param string $table_prefix Tables prefix.
* @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',
@ -198,13 +197,12 @@ class table_helper
"{$table_prefix}sessions_keys" => 'ssnkeys',
"{$table_prefix}sitelist" => 'sitelst',
"{$table_prefix}smilies" => 'smls',
"{$table_prefix}sphinx" => 'sphnx',
"{$table_prefix}storage" => 'strg',
"{$table_prefix}styles" => 'stls',
"{$table_prefix}teampage" => 'teampg',
"{$table_prefix}topics" => 'tpcs',
"{$table_prefix}topics_posted" => 'tpcspstd',
"{$table_prefix}topics_track" => 'tpcstrck',
"{$table_prefix}topics_track" => 'tpcstrk',
"{$table_prefix}topics_watch" => 'tpkswtch',
"{$table_prefix}user_group" => 'usrgrp',
"{$table_prefix}user_notifications" => 'usrntfs',
@ -215,7 +213,7 @@ class table_helper
];
// Add table prefix to additional tables
if (!empty($table_prefix) && !empty($additional_tables))
if (!empty($table_prefix && !empty($additional_tables)))
{
foreach ($additional_tables as $key => $value)
{

View file

@ -28,11 +28,12 @@ class rename_duplicated_index_names extends migration
public function update_schema()
{
$rename_index = $table_keys = [];
$db_table_schema = $this->get_schema();
$db_table_schema = json_decode(file_get_contents($this->phpbb_root_path . 'store/schema.json'), true);
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;
@ -65,27 +66,4 @@ 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();
}
}

View file

@ -440,62 +440,4 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
$this->assertFalse($this->db_tools->sql_table_exists('phpbb_foobar1'));
$this->assertFalse($this->db_tools->sql_table_exists('phpbb_foobar2'));
}
public function test_schema_generator(): array
{
global $phpbb_root_path, $phpEx;
$finder_factory = new \phpbb\finder\factory(null, false, $phpbb_root_path, $phpEx);
$finder = $finder_factory->get();
$migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
$schema_generator = new \phpbb\db\migration\schema_generator(
$migrator_classes,
$this->config,
$this->db,
$this->db_tools,
$phpbb_root_path,
$phpEx,
'phpbb_',
self::get_core_tables()
);
$db_table_schema = $schema_generator->get_schema();
$this->assertNotEmpty($db_table_schema);
return $db_table_schema;
}
/**
* @depends test_schema_generator
*/
public function test_table_indexes(array $db_table_schema)
{
$table_keys = [];
foreach ($db_table_schema as $table_name => $table_data)
{
if (isset($table_data['KEYS']))
{
foreach ($table_data['KEYS'] as $key_name => $key_data)
{
$table_keys[$table_name][] = $key_name;
}
}
}
$this->assertNotEmpty($table_keys);
$short_table_names = \phpbb\db\doctrine\table_helper::map_short_table_names(['custom_table' => 'cstmtbl'], 'phpbb_');
$this->assertEquals('phpbb_custom_table', array_search('cstmtbl', $short_table_names));
$this->assertEquals($short_table_names['phpbb_custom_table'], 'cstmtbl');
foreach ($table_keys as $table_name => $key_names)
{
$index_prefix = $short_table_names[$table_name] . '_';
foreach ($key_names as $key_name)
{
$this->assertEquals(0, strpos($key_name, $index_prefix), "$key_name does not contain $index_prefix");
}
}
}
}