[ticket/16284] Adjust create schema and add tables to tests

PHPBB3-16284
This commit is contained in:
Marc Alexander 2020-01-01 16:17:23 +01:00
parent af7dcb9ba2
commit 2b65ce123c
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
16 changed files with 103 additions and 31 deletions

View file

@ -7,6 +7,7 @@ services:
- '@filesystem' - '@filesystem'
- '%core.root_path%' - '%core.root_path%'
- '%core.php_ext%' - '%core.php_ext%'
- '%tables%'
tags: tags:
- { name: install_database_install, order: 10 } - { name: install_database_install, order: 10 }

View file

@ -52,7 +52,15 @@ $db = new \phpbb\db\driver\sqlite3();
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($db, true); $db_tools = $factory->get($db, true);
$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, $db_tools, $phpbb_root_path, $phpEx, $table_prefix); $tables_data = \Symfony\Component\Yaml\Yaml::parseFile($phpbb_root_path . '/config/default/container/tables.yml');
$tables = [];
foreach ($tables_data['parameters'] as $parameter => $table)
{
$tables[str_replace('tables.', '', $parameter)] = str_replace('%core.table_prefix%', $table_prefix, $table);
}
$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, $db_tools, $phpbb_root_path, $phpEx, $table_prefix, $tables);
$schema_data = $schema_generator->get_schema(); $schema_data = $schema_generator->get_schema();
$fp = fopen($schema_path . 'schema.json', 'wb'); $fp = fopen($schema_path . 'schema.json', 'wb');

View file

@ -42,13 +42,24 @@ class schema_generator
/** @var array */ /** @var array */
protected $tables; protected $tables;
/** @var array */
protected $table_names;
/** @var array */ /** @var array */
protected $dependencies = array(); protected $dependencies = array();
/** /**
* Constructor * Constructor
*/ * @param array $class_names
public function __construct(array $class_names, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\db\tools\tools_interface $db_tools, $phpbb_root_path, $php_ext, $table_prefix) * @param \phpbb\config\config $config
* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\db\tools\tools_interface $db_tools
* @param string $phpbb_root_path
* @param string $php_ext
* @param string $table_prefix
* @param array $tables
*/
public function __construct(array $class_names, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\db\tools\tools_interface $db_tools, $phpbb_root_path, $php_ext, $table_prefix, $tables)
{ {
$this->config = $config; $this->config = $config;
$this->db = $db; $this->db = $db;
@ -57,6 +68,7 @@ class schema_generator
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext; $this->php_ext = $php_ext;
$this->table_prefix = $table_prefix; $this->table_prefix = $table_prefix;
$this->table_names = $tables;
} }
/** /**
@ -90,7 +102,7 @@ class schema_generator
if (empty($open_dependencies)) if (empty($open_dependencies))
{ {
$migration = new $migration_class($this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix); $migration = new $migration_class($this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix, $this->table_names);
$tree[] = $migration_class; $tree[] = $migration_class;
$migration_key = array_search($migration_class, $migrations); $migration_key = array_search($migration_class, $migrations);

View file

@ -13,7 +13,14 @@
namespace phpbb\install\module\install_database\task; namespace phpbb\install\module\install_database\task;
use phpbb\db\driver\driver_interface;
use phpbb\db\migration\schema_generator;
use phpbb\db\tools\tools_interface;
use phpbb\filesystem\filesystem_interface;
use phpbb\install\exception\resource_limit_reached_exception; use phpbb\install\exception\resource_limit_reached_exception;
use phpbb\install\helper\config;
use phpbb\install\helper\database;
use phpbb\install\helper\iohandler\iohandler_interface;
/** /**
* Create database schema * Create database schema
@ -21,32 +28,32 @@ use phpbb\install\exception\resource_limit_reached_exception;
class create_schema extends \phpbb\install\task_base class create_schema extends \phpbb\install\task_base
{ {
/** /**
* @var \phpbb\install\helper\config * @var config
*/ */
protected $config; protected $config;
/** /**
* @var \phpbb\db\driver\driver_interface * @var driver_interface
*/ */
protected $db; protected $db;
/** /**
* @var \phpbb\db\tools\tools_interface * @var tools_interface
*/ */
protected $db_tools; protected $db_tools;
/** /**
* @var \phpbb\install\helper\database * @var database
*/ */
protected $database_helper; protected $database_helper;
/** /**
* @var \phpbb\filesystem\filesystem_interface * @var filesystem_interface
*/ */
protected $filesystem; protected $filesystem;
/** /**
* @var \phpbb\install\helper\iohandler\iohandler_interface * @var iohandler_interface
*/ */
protected $iohandler; protected $iohandler;
@ -60,22 +67,29 @@ class create_schema extends \phpbb\install\task_base
*/ */
protected $php_ext; protected $php_ext;
/**
* @var array
*/
protected $tables;
/** /**
* Constructor * Constructor
* *
* @param \phpbb\install\helper\config $config Installer's config provider * @param config $config Installer's config provider
* @param \phpbb\install\helper\database $db_helper Installer's database helper * @param database $db_helper Installer's database helper
* @param \phpbb\filesystem\filesystem_interface $filesystem Filesystem service * @param filesystem_interface $filesystem Filesystem service
* @param \phpbb\install\helper\iohandler\iohandler_interface $iohandler Installer's input-output handler * @param iohandler_interface $iohandler Installer's input-output handler
* @param string $phpbb_root_path Path phpBB's root * @param string $phpbb_root_path Path phpBB's root
* @param string $php_ext Extension of PHP files * @param string $php_ext Extension of PHP files
* @param array $tables Tables array
*/ */
public function __construct(\phpbb\install\helper\config $config, public function __construct(config $config,
\phpbb\install\helper\database $db_helper, database $db_helper,
\phpbb\filesystem\filesystem_interface $filesystem, filesystem_interface $filesystem,
\phpbb\install\helper\iohandler\iohandler_interface $iohandler, iohandler_interface $iohandler,
$phpbb_root_path, $phpbb_root_path,
$php_ext) $php_ext,
$tables)
{ {
$dbms = $db_helper->get_available_dbms($config->get('dbms')); $dbms = $db_helper->get_available_dbms($config->get('dbms'));
$dbms = $dbms[$config->get('dbms')]['DRIVER']; $dbms = $dbms[$config->get('dbms')]['DRIVER'];
@ -99,6 +113,7 @@ class create_schema extends \phpbb\install\task_base
$this->iohandler = $iohandler; $this->iohandler = $iohandler;
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext; $this->php_ext = $php_ext;
$this->tables = $tables;
parent::__construct(true); parent::__construct(true);
} }
@ -180,14 +195,15 @@ class create_schema extends \phpbb\install\task_base
$migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes(); $migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($this->db, true); $db_tools = $factory->get($this->db, true);
$schema_generator = new \phpbb\db\migration\schema_generator( $schema_generator = new schema_generator(
$migrator_classes, $migrator_classes,
new \phpbb\config\config(array()), new \phpbb\config\config(array()),
$this->db, $this->db,
$db_tools, $db_tools,
$this->phpbb_root_path, $this->phpbb_root_path,
$this->php_ext, $this->php_ext,
$table_prefix $table_prefix,
$this->tables
); );
$db_table_schema = $schema_generator->get_schema(); $db_table_schema = $schema_generator->get_schema();
} }

View file

@ -121,6 +121,13 @@ class create_schema_file extends \phpbb\install\task_base
$migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes(); $migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($this->db, true); $db_tools = $factory->get($this->db, true);
$tables_data = \Symfony\Component\Yaml\Yaml::parseFile($this->phpbb_root_path . '/config/default/container/tables.yml');
$tables = [];
foreach ($tables_data['parameters'] as $parameter => $table)
{
$tables[str_replace('tables.', '', $parameter)] = str_replace('%core.table_prefix%', $table_prefix, $table);
}
$schema_generator = new \phpbb\db\migration\schema_generator( $schema_generator = new \phpbb\db\migration\schema_generator(
$migrator_classes, $migrator_classes,
new \phpbb\config\config(array()), new \phpbb\config\config(array()),
@ -128,7 +135,8 @@ class create_schema_file extends \phpbb\install\task_base
$db_tools, $db_tools,
$this->phpbb_root_path, $this->phpbb_root_path,
$this->php_ext, $this->php_ext,
$table_prefix $table_prefix,
$tables
); );
$db_table_schema = $schema_generator->get_schema(); $db_table_schema = $schema_generator->get_schema();
$db_table_schema = json_encode($db_table_schema, JSON_PRETTY_PRINT); $db_table_schema = json_encode($db_table_schema, JSON_PRETTY_PRINT);

View file

@ -69,6 +69,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
dirname(__FILE__) . '/../../phpBB/', dirname(__FILE__) . '/../../phpBB/',
'php', 'php',
'phpbb_', 'phpbb_',
self::get_core_tables(),
$tools, $tools,
new \phpbb\db\migration\helper() new \phpbb\db\migration\helper()
); );

View file

@ -167,6 +167,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
$phpbb_root_path, $phpbb_root_path,
$php_ext, $php_ext,
$table_prefix, $table_prefix,
self::get_core_tables(),
array(), array(),
new \phpbb\db\migration\helper() new \phpbb\db\migration\helper()
); );

View file

@ -87,6 +87,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
$this->phpbb_root_path, $this->phpbb_root_path,
'php', 'php',
$this->table_prefix, $this->table_prefix,
self::get_core_tables(),
array(), array(),
new \phpbb\db\migration\helper() new \phpbb\db\migration\helper()
); );

View file

@ -64,7 +64,8 @@ class phpbb_migrator_convert_timezones_test extends phpbb_database_test_case
$factory->get($this->db), $factory->get($this->db),
$phpbb_root_path, $phpbb_root_path,
$phpEx, $phpEx,
'phpbb_' 'phpbb_',
self::get_core_tables()
); );
} }

View file

@ -43,6 +43,7 @@ class get_callable_from_step_test extends phpbb_database_test_case
$phpbb_root_path, $phpbb_root_path,
$php_ext, $php_ext,
$table_prefix, $table_prefix,
self::get_core_tables(),
array($module_tools), array($module_tools),
new \phpbb\db\migration\helper() new \phpbb\db\migration\helper()
); );

View file

@ -41,7 +41,7 @@ class schema_generator_test extends phpbb_test_case
protected function get_schema_generator(array $class_names) protected function get_schema_generator(array $class_names)
{ {
$this->generator = new \phpbb\db\migration\schema_generator($class_names, $this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix); $this->generator = new \phpbb\db\migration\schema_generator($class_names, $this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix, phpbb_database_test_case::get_core_tables());
return $this->generator; return $this->generator;
} }

View file

@ -36,7 +36,8 @@ class phpbb_notification_convert_test extends phpbb_database_test_case
$factory->get($this->db), $factory->get($this->db),
$phpbb_root_path, $phpbb_root_path,
$phpEx, $phpEx,
'phpbb_' 'phpbb_',
self::get_core_tables()
); );
} }

View file

@ -75,14 +75,13 @@ abstract class phpbb_database_test_case extends TestCase
if (!file_exists(self::$schema_file)) if (!file_exists(self::$schema_file))
{ {
global $table_prefix; global $table_prefix;
$db = new \phpbb\db\driver\sqlite3(); $db = new \phpbb\db\driver\sqlite3();
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($db, true); $db_tools = $factory->get($db, true);
$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, $db_tools, $phpbb_root_path, $phpEx, $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())); file_put_contents(self::$schema_file, json_encode($schema_generator->get_schema()));
} }
@ -319,4 +318,23 @@ abstract class phpbb_database_test_case extends TestCase
$this->assertTrue(true); $this->assertTrue(true);
} }
} }
static public function get_core_tables() : array
{
global $phpbb_root_path, $table_prefix;
static $core_tables = [];
if (empty($tables))
{
$tables_yml_data = \Symfony\Component\Yaml\Yaml::parseFile($phpbb_root_path . '/config/default/container/tables.yml');
foreach ($tables_yml_data['parameters'] as $parameter => $table)
{
$core_tables[str_replace('tables.', '', $parameter)] = str_replace('%core.table_prefix%', $table_prefix, $table);
}
}
return $core_tables;
}
} }

View file

@ -372,8 +372,9 @@ class phpbb_database_test_connection_manager
$db = new \phpbb\db\driver\sqlite3(); $db = new \phpbb\db\driver\sqlite3();
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($db, true); $db_tools = $factory->get($db, true);
$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); $schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, $db_tools, $phpbb_root_path, $phpEx, $table_prefix, $tables);
$db_table_schema = $schema_generator->get_schema(); $db_table_schema = $schema_generator->get_schema();
} }

View file

@ -249,6 +249,7 @@ class phpbb_functional_test_case extends phpbb_test_case
$phpbb_root_path, $phpbb_root_path,
$phpEx, $phpEx,
self::$config['table_prefix'], self::$config['table_prefix'],
phpbb_database_test_case::get_core_tables(),
array(), array(),
new \phpbb\db\migration\helper() new \phpbb\db\migration\helper()
); );

View file

@ -486,6 +486,7 @@ class phpbb_ui_test_case extends phpbb_test_case
$phpbb_root_path, $phpbb_root_path,
$phpEx, $phpEx,
self::$config['table_prefix'], self::$config['table_prefix'],
phpbb_database_test_case::get_core_tables(),
array(), array(),
new \phpbb\db\migration\helper() new \phpbb\db\migration\helper()
); );