mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-25 19:38:53 +00:00
Compare commits
4 commits
1339a31c23
...
5e9d616f57
Author | SHA1 | Date | |
---|---|---|---|
|
5e9d616f57 | ||
|
de1f6329ff | ||
|
75c5fe9459 | ||
|
a229797cd7 |
3 changed files with 88 additions and 6 deletions
|
@ -127,14 +127,15 @@ 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 array $table_prefix Tables prefix.
|
||||
* @param string $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',
|
||||
|
@ -197,12 +198,13 @@ 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" => 'tpcstrk',
|
||||
"{$table_prefix}topics_track" => 'tpcstrck',
|
||||
"{$table_prefix}topics_watch" => 'tpkswtch',
|
||||
"{$table_prefix}user_group" => 'usrgrp',
|
||||
"{$table_prefix}user_notifications" => 'usrntfs',
|
||||
|
@ -213,7 +215,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)
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -440,4 +440,62 @@ 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue