From a72810465f47d9a7db02e7f89b1cd9dd07976d4c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 1 Jan 2020 12:08:11 +0100 Subject: [PATCH] [ticket/16284] Provide tables as array in migrations PHPBB3-16284 --- .../default/container/services_migrator.yml | 1 + phpBB/phpbb/db/migration/migration.php | 7 +++- phpBB/phpbb/db/migrator.php | 35 ++++++++++++++----- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/phpBB/config/default/container/services_migrator.yml b/phpBB/config/default/container/services_migrator.yml index c63b087adb..3362598204 100644 --- a/phpBB/config/default/container/services_migrator.yml +++ b/phpBB/config/default/container/services_migrator.yml @@ -11,6 +11,7 @@ services: - '%core.root_path%' - '%core.php_ext%' - '%core.table_prefix%' + - '%tables%' - '@migrator.tool_collection' - '@migrator.helper' diff --git a/phpBB/phpbb/db/migration/migration.php b/phpBB/phpbb/db/migration/migration.php index 4e218344f4..c94ac29407 100644 --- a/phpBB/phpbb/db/migration/migration.php +++ b/phpBB/phpbb/db/migration/migration.php @@ -34,6 +34,9 @@ abstract class migration implements migration_interface /** @var string */ protected $table_prefix; + /** @var array Tables array */ + protected $tables; + /** @var string */ protected $phpbb_root_path; @@ -55,13 +58,15 @@ abstract class migration implements migration_interface * @param string $phpbb_root_path * @param string $php_ext * @param string $table_prefix + * @param array $tables */ - public function __construct(\phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\db\tools\tools_interface $db_tools, $phpbb_root_path, $php_ext, $table_prefix) + public function __construct(\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->db = $db; $this->db_tools = $db_tools; $this->table_prefix = $table_prefix; + $this->tables = $tables; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php index 3a1ee758cf..e93b96ad28 100644 --- a/phpBB/phpbb/db/migrator.php +++ b/phpBB/phpbb/db/migrator.php @@ -13,8 +13,12 @@ namespace phpbb\db; +use phpbb\config\config; +use phpbb\db\driver\driver_interface; +use phpbb\db\migration\helper; use phpbb\db\output_handler\migrator_output_handler_interface; use phpbb\db\output_handler\null_migrator_output_handler; +use phpbb\db\tools\tools_interface; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -28,21 +32,24 @@ class migrator */ protected $container; - /** @var \phpbb\config\config */ + /** @var config */ protected $config; - /** @var \phpbb\db\driver\driver_interface */ + /** @var driver_interface */ protected $db; - /** @var \phpbb\db\tools\tools_interface */ + /** @var tools_interface */ protected $db_tools; - /** @var \phpbb\db\migration\helper */ + /** @var helper */ protected $helper; /** @var string */ protected $table_prefix; + /** @var array */ + protected $tables; + /** @var string */ protected $phpbb_root_path; @@ -92,9 +99,20 @@ class migrator protected $output_handler; /** - * Constructor of the database migrator - */ - public function __construct(ContainerInterface $container, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\db\tools\tools_interface $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools, \phpbb\db\migration\helper $helper) + * Constructor of the database migrator + * @param ContainerInterface $container + * @param config $config + * @param driver\driver_interface $db + * @param tools\tools_interface $db_tools + * @param $migrations_table + * @param $phpbb_root_path + * @param $php_ext + * @param $table_prefix + * @param $tables + * @param $tools + * @param migration\helper $helper + */ + public function __construct(ContainerInterface $container, config $config, driver_interface $db, tools_interface $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tables, $tools, helper $helper) { $this->container = $container; $this->config = $config; @@ -108,6 +126,7 @@ class migrator $this->php_ext = $php_ext; $this->table_prefix = $table_prefix; + $this->tables = $tables; $this->output_handler = new null_migrator_output_handler(); @@ -950,7 +969,7 @@ class migrator */ protected function get_migration($name) { - $migration = new $name($this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix); + $migration = new $name($this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix, $this->tables); if ($migration instanceof ContainerAwareInterface) {