1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-12 03:34:04 +02:00

[ticket/17525] Fix handling index name prefix logic for renaming

PHPBB-17525
This commit is contained in:
rxu
2025-07-04 00:08:28 +07:00
parent b5c3befa87
commit 5eaabb1c39
24 changed files with 149 additions and 84 deletions

View File

@@ -25,7 +25,7 @@ class phpbb_captcha_qa_test extends \phpbb_database_test_case
protected function setUp(): void
{
global $db, $request, $phpbb_container;
global $db, $request, $phpbb_container, $table_prefix;
$db = $this->new_dbal();
$db_doctrine = $this->new_doctrine_dbal();
@@ -35,7 +35,9 @@ class phpbb_captcha_qa_test extends \phpbb_database_test_case
$request = new \phpbb_mock_request();
$phpbb_container = new \phpbb_mock_container_builder();
$factory = new \phpbb\db\tools\factory();
$phpbb_container->set('dbal.tools', $factory->get($db_doctrine));
$db_tools = $factory->get($db_doctrine);
$db_tools->set_table_prefix($table_prefix);
$phpbb_container->set('dbal.tools', $db_tools);
$this->qa = new \phpbb\captcha\plugins\qa('phpbb_captcha_questions', 'phpbb_captcha_answers', 'phpbb_qa_confirm');
}

View File

@@ -32,7 +32,7 @@ abstract class phpbb_console_user_base extends phpbb_database_test_case
protected function setUp(): void
{
global $auth, $db, $cache, $config, $user, $phpbb_dispatcher, $phpbb_container, $phpbb_root_path, $phpEx;
global $auth, $db, $cache, $config, $user, $phpbb_dispatcher, $phpbb_container, $phpbb_root_path, $phpEx, $table_prefix;
$phpbb_dispatcher = new \phpbb\event\dispatcher();
$phpbb_container = new phpbb_mock_container_builder();
@@ -141,6 +141,7 @@ abstract class phpbb_console_user_base extends phpbb_database_test_case
$factory = new \phpbb\db\tools\factory();
$db_doctrine = $this->new_doctrine_dbal();
$db_tools = $factory->get($db_doctrine);
$db_tools->set_table_prefix($table_prefix);
$migrator = new \phpbb\db\migrator(
$phpbb_container,
$config,

View File

@@ -26,12 +26,15 @@ class phpbb_dbal_auto_increment_test extends phpbb_database_test_case
protected function setUp(): void
{
global $table_prefix;
parent::setUp();
$this->db = $this->new_dbal();
$this->db_doctrine = $this->new_doctrine_dbal();
$factory = new \phpbb\db\tools\factory();
$this->tools = $factory->get($this->db_doctrine);
$this->tools->set_table_prefix($table_prefix);
$this->table_data = array(
'COLUMNS' => array(

View File

@@ -35,12 +35,15 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
protected function setUp(): void
{
parent::setUp();
$table_prefix = 'prefix_';
$this->db = $this->new_dbal();
$this->doctrine_db = $this->new_doctrine_dbal();
$factory = new \phpbb\db\tools\factory();
$this->tools = $factory->get($this->doctrine_db);
$this->tools->set_table_prefix($table_prefix);
$this->table_data = array(
'COLUMNS' => array(

View File

@@ -53,12 +53,15 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
protected function setUp(): void
{
global $table_prefix;
parent::setUp();
$this->db = $this->new_dbal();
$this->doctrine_db = $this->new_doctrine_dbal();
$factory = new \phpbb\db\tools\factory();
$this->db_tools = $factory->get($this->doctrine_db);
$this->db_tools->set_table_prefix($table_prefix);
$this->config = new \phpbb\config\db($this->db, new phpbb_mock_cache, 'phpbb_config');

View File

@@ -154,6 +154,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
{
$phpbb_root_path = __DIR__ . './../../phpBB/';
$php_ext = 'php';
$table_prefix = 'phpbb_';
$config = new \phpbb\config\config(array('version' => PHPBB_VERSION));
$db = $this->new_dbal();
@@ -162,7 +163,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
$factory = new \phpbb\db\tools\factory();
$finder_factory = new \phpbb\finder\factory(null, false, $phpbb_root_path, $php_ext);
$db_tools = $factory->get($db_doctrine);
$table_prefix = 'phpbb_';
$db_tools->set_table_prefix($table_prefix);
$container = new phpbb_mock_container_builder();

View File

@@ -37,6 +37,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
{
parent::setUp();
$this->table_prefix = 'phpbb_';
$this->config = new \phpbb\config\config(array(
'version' => '3.1.0',
));
@@ -45,13 +46,13 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$factory = new \phpbb\db\tools\factory();
$this->db_tools = $factory->get($this->db_doctrine);
$this->db_tools->set_table_prefix($this->table_prefix);
$finder_factory = $this->createMock('\phpbb\finder\factory');
$this->phpbb_root_path = __DIR__ . '/';
$this->phpEx = 'php';
$this->cache = new \phpbb\cache\service(new phpbb_mock_cache(), $this->config, $this->db, $phpbb_dispatcher, $this->phpbb_root_path, $this->phpEx);
$this->table_prefix = 'phpbb_';
$container = new phpbb_mock_container_builder();
$cache_path = $this->phpbb_root_path . 'cache/twig';

View File

@@ -55,6 +55,10 @@ class migrations_check_config_added_test extends phpbb_test_case
{
global $phpbb_root_path, $phpEx;
$this->table_prefix = 'phpbb_';
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
$this->config = new \phpbb\config\config([
'search_type' => '\phpbb\search\fulltext_mysql',
]);
@@ -63,9 +67,7 @@ class migrations_check_config_added_test extends phpbb_test_case
$this->db_doctrine = $this->createMock(\Doctrine\DBAL\Connection::class);
$factory = new \phpbb\db\tools\factory();
$this->db_tools = $factory->get($this->db_doctrine);
$this->table_prefix = 'phpbb_';
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
$this->db_tools->set_table_prefix($this->table_prefix);
$tools = [
new \phpbb\db\migration\tool\config($this->config),

View File

@@ -18,10 +18,13 @@ class phpbb_migrator_convert_timezones_test extends phpbb_database_test_case
public function getDataSet()
{
global $table_prefix;
$this->db = $this->new_dbal();
$this->db_doctrine = $this->new_doctrine_dbal();
$factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($this->db_doctrine);
$db_tools->set_table_prefix($table_prefix);
// user_dst doesn't exist anymore, must re-add it to test this
$db_tools->sql_column_add('phpbb_users', 'user_dst', array('BOOL', 1));
@@ -55,16 +58,18 @@ class phpbb_migrator_convert_timezones_test extends phpbb_database_test_case
{
parent::setUp();
global $phpbb_root_path, $phpEx;
global $phpbb_root_path, $phpEx, $table_prefix;
$this->db = $this->new_dbal();
$this->db_doctrine = $this->new_doctrine_dbal();
$factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($this->db_doctrine);
$db_tools->set_table_prefix($table_prefix);
$this->migration = new \phpbb\db\migration\data\v310\timezone(
new \phpbb\config\config(array()),
$this->db,
$factory->get($this->db_doctrine),
$db_tools,
$phpbb_root_path,
$phpEx,
'phpbb_',
@@ -84,6 +89,8 @@ class phpbb_migrator_convert_timezones_test extends phpbb_database_test_case
public function test_convert()
{
global $table_prefix;
$this->migration->update_timezones(0);
$sql = 'SELECT user_id, user_timezone
@@ -98,6 +105,7 @@ class phpbb_migrator_convert_timezones_test extends phpbb_database_test_case
$factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($this->db_doctrine);
$db_tools->set_table_prefix($table_prefix);
// Remove the user_dst field again
$db_tools->sql_column_remove('phpbb_users', 'user_dst');

View File

@@ -23,6 +23,8 @@ class get_callable_from_step_test extends phpbb_database_test_case
$db = $this->new_dbal();
$db_doctrine = $this->new_doctrine_dbal();
$factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($db_doctrine);
$db_tools->set_table_prefix($table_prefix);
$user = $this->getMockBuilder('\phpbb\user')->disableOriginalConstructor()->getMock();
$user->ip = '127.0.0.1';
$module_manager = new \phpbb\module\module_manager(
@@ -38,7 +40,7 @@ class get_callable_from_step_test extends phpbb_database_test_case
new phpbb_mock_container_builder(),
new \phpbb\config\config(array()),
$db,
$factory->get($db_doctrine),
$db_tools,
'phpbb_migrations',
$phpbb_root_path,
$php_ext,

View File

@@ -30,14 +30,16 @@ class schema_generator_test extends phpbb_test_case
parent::setUp();
$this->table_prefix = 'phpbb_';
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
$this->config = new \phpbb\config\config(array());
$this->db = new \phpbb\db\driver\sqlite3();
$this->doctrine_db = \phpbb\db\doctrine\connection_factory::get_connection(new phpbb_mock_config_php_file());
$factory = new \phpbb\db\tools\factory();
$this->db_tools = $factory->get($this->doctrine_db);
$this->table_prefix = 'phpbb_';
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
$this->db_tools->set_table_prefix($this->table_prefix);
}
protected function get_schema_generator(array $class_names)

View File

@@ -25,12 +25,13 @@ class phpbb_notification_convert_test extends phpbb_database_test_case
{
parent::setUp();
global $phpbb_root_path, $phpEx;
global $phpbb_root_path, $phpEx, $table_prefix;
$this->db = $this->new_dbal();
$this->doctrine_db = $this->new_doctrine_dbal();
$factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($this->doctrine_db);
$db_tools->set_table_prefix($table_prefix);
$core_tables = self::get_core_tables();
// Add user_notify_type column for testing this migration and set type

View File

@@ -25,7 +25,7 @@ class phpbb_search_native_test extends phpbb_search_test_case
protected function setUp(): void
{
global $phpbb_root_path, $phpEx, $config, $cache;
global $phpbb_root_path, $phpEx, $config, $cache, $table_prefix;
parent::setUp();
@@ -41,6 +41,7 @@ class phpbb_search_native_test extends phpbb_search_test_case
$this->db = $this->new_dbal();
$tools_factory = new \phpbb\db\tools\factory();
$this->db_tools = $tools_factory->get($this->new_doctrine_dbal());
$this->db_tools->set_table_prefix($table_prefix);
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$class = self::get_search_wrapper('\phpbb\search\backend\fulltext_native');
$config['fulltext_native_min_chars'] = 2;

View File

@@ -88,6 +88,7 @@ abstract class phpbb_database_test_case extends TestCase
$doctrine = \phpbb\db\doctrine\connection_factory::get_connection(new phpbb_mock_config_php_file());
$factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($doctrine, true);
$db_tools->set_table_prefix($table_prefix);
$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, $db_tools, $phpbb_root_path, $phpEx, $table_prefix, self::get_core_tables());
file_put_contents(self::$schema_file, json_encode($schema_generator->get_schema()));

View File

@@ -327,6 +327,8 @@ class phpbb_database_test_connection_manager
*/
protected function load_schema_from_file($directory, \phpbb\db\driver\driver_interface $db, \Doctrine\DBAL\Connection $doctrine)
{
global $table_prefix;
$schema = $this->dbms['SCHEMA'];
if ($this->config['dbms'] == 'phpbb\db\driver\mysql')
@@ -363,7 +365,7 @@ class phpbb_database_test_connection_manager
}
else
{
global $phpbb_root_path, $phpEx, $table_prefix;
global $phpbb_root_path, $phpEx;
$finder = new \phpbb\finder\finder(null, false, $phpbb_root_path, $phpEx);
$classes = $finder->core_path('phpbb/db/migration/data/')
@@ -373,6 +375,7 @@ class phpbb_database_test_connection_manager
$doctrine = \phpbb\db\doctrine\connection_factory::get_connection(new phpbb_mock_config_php_file());
$factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($doctrine, true);
$db_tools->set_table_prefix($table_prefix);
$tables = phpbb_database_test_case::get_core_tables();
$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, $db_tools, $phpbb_root_path, $phpEx, $table_prefix, $tables);
@@ -381,6 +384,7 @@ class phpbb_database_test_connection_manager
$factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($doctrine);
$db_tools->set_table_prefix($table_prefix);
foreach ($db_table_schema as $table_name => $table_data)
{
$db_tools->sql_create_table(

View File

@@ -286,6 +286,7 @@ class phpbb_functional_test_case extends phpbb_test_case
$factory = new \phpbb\db\tools\factory();
$finder_factory = new \phpbb\finder\factory(null, false, $phpbb_root_path, $phpEx);
$db_tools = $factory->get($db_doctrine);
$db_tools->set_table_prefix(self::$config['table_prefix']);
$container = new phpbb_mock_container_builder();
$migrator = new \phpbb\db\migrator(