From 8d3a82a4fa8ced50fbc1d1019ef439d1d5c81e71 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 19:32:39 -0600 Subject: [PATCH 1/9] [feature/migrations] Make the container available to extension installers This allows extensions to load and install migrations easily as per their needs. PHPBB3-11318 --- phpBB/config/services.yml | 1 + phpBB/includes/extension/base.php | 15 +++++++++++++++ phpBB/includes/extension/manager.php | 13 ++++++++++--- phpBB/install/database_update.php | 4 ++-- phpBB/install/install_install.php | 4 ++-- tests/extension/manager_test.php | 2 ++ tests/extension/metadata_manager_test.php | 1 + .../test_framework/phpbb_functional_test_case.php | 1 + 8 files changed, 34 insertions(+), 7 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index ee52ca2800..028ab88229 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -112,6 +112,7 @@ services: ext.manager: class: phpbb_extension_manager arguments: + - @service_container - @dbal.conn - @config - %tables.ext% diff --git a/phpBB/includes/extension/base.php b/phpBB/includes/extension/base.php index 9d076eb6c5..d51589d719 100644 --- a/phpBB/includes/extension/base.php +++ b/phpBB/includes/extension/base.php @@ -15,6 +15,8 @@ if (!defined('IN_PHPBB')) exit; } +use Symfony\Component\DependencyInjection\ContainerInterface; + /** * A base class for extensions without custom enable/disable/purge code. * @@ -22,6 +24,19 @@ if (!defined('IN_PHPBB')) */ class phpbb_extension_base implements phpbb_extension_interface { + /** @var ContainerInterface */ + protected $container; + + /** + * Constructor + * + * @param ContainerInterface $container Container object + */ + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + /** * Single enable step that does nothing * diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index de6f364320..8136dfa90b 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -15,6 +15,8 @@ if (!defined('IN_PHPBB')) exit; } +use Symfony\Component\DependencyInjection\ContainerInterface; + /** * The extension manager provides means to activate/deactivate extensions. * @@ -22,6 +24,9 @@ if (!defined('IN_PHPBB')) */ class phpbb_extension_manager { + /** @var ContainerInterface */ + protected $container; + protected $db; protected $config; protected $cache; @@ -34,6 +39,7 @@ class phpbb_extension_manager /** * Creates a manager and loads information from database * + * @param ContainerInterface $container A container * @param phpbb_db_driver $db A database connection * @param phpbb_config $config phpbb_config * @param string $extension_table The name of the table holding extensions @@ -42,8 +48,9 @@ class phpbb_extension_manager * @param phpbb_cache_driver_interface $cache A cache instance or null * @param string $cache_name The name of the cache variable, defaults to _ext */ - public function __construct(phpbb_db_driver $db, phpbb_config $config, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') + public function __construct(ContainerInterface $container, phpbb_db_driver $db, phpbb_config $config, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') { + $this->container = $container; $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; $this->config = $config; @@ -126,11 +133,11 @@ class phpbb_extension_manager if (class_exists($extension_class_name)) { - return new $extension_class_name; + return new $extension_class_name($this->container); } else { - return new phpbb_extension_base; + return new phpbb_extension_base($this->container); } } diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 4e17a1429c..0a065573bf 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -685,12 +685,12 @@ function _write_result($no_updates, $errored, $error_ary) function _add_modules($modules_to_install) { - global $phpbb_root_path, $phpEx, $db, $phpbb_extension_manager, $config; + global $phpbb_root_path, $phpEx, $db, $phpbb_extension_manager, $config, $phpbb_container; // modules require an extension manager if (empty($phpbb_extension_manager)) { - $phpbb_extension_manager = new phpbb_extension_manager($db, $config, EXT_TABLE, $phpbb_root_path, ".$phpEx"); + $phpbb_extension_manager = $phpbb_container->get('ext.manager'); } include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index 1ab9caee0a..dd90335480 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -1456,12 +1456,12 @@ class install_install extends module */ function add_modules($mode, $sub) { - global $db, $lang, $phpbb_root_path, $phpEx, $phpbb_extension_manager, $config; + global $db, $lang, $phpbb_root_path, $phpEx, $phpbb_extension_manager, $config, $phpbb_container; // modules require an extension manager if (empty($phpbb_extension_manager)) { - $phpbb_extension_manager = new phpbb_extension_manager($db, $config, EXT_TABLE, $phpbb_root_path, ".$phpEx"); + $phpbb_extension_manager = $phpbb_container->get('ext.manager'); } include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 5cde5bccdb..5c0b419540 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -26,6 +26,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case parent::setUp(); $this->extension_manager = new phpbb_extension_manager( + new phpbb_mock_container_builder(), $this->new_dbal(), new phpbb_config(array()), 'phpbb_ext', @@ -90,6 +91,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case public function test_enabled_no_cache() { $extension_manager = new phpbb_extension_manager( + new phpbb_mock_container_builder(), $this->new_dbal(), new phpbb_config(array()), 'phpbb_ext', diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index ce7be0dea5..7a04229a9c 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -48,6 +48,7 @@ class metadata_manager_test extends phpbb_database_test_case ); $this->extension_manager = new phpbb_extension_manager( + new phpbb_mock_container_builder(), $this->db, $this->config, 'phpbb_ext', diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index e346223a4b..cb0a475278 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -137,6 +137,7 @@ class phpbb_functional_test_case extends phpbb_test_case if (!$this->extension_manager) { $this->extension_manager = new phpbb_extension_manager( + new phpbb_mock_container_builder(), $this->get_db(), new phpbb_config(array()), self::$config['table_prefix'] . 'ext', From aa67fa6dd83e329c3b6edbb356eae3eeda1ba69f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 31 Jan 2013 13:53:33 -0600 Subject: [PATCH 2/9] [feature/migrations] Automatically install/revert migrations for extensions Migrations from ext/ext_name/migrations/ are automatically installed when enabling the extension and automatically reverted when the extension is purged. PHPBB3-11318 --- phpBB/includes/extension/manager.php | 62 ++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 8136dfa90b..018324d5d6 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -173,6 +173,12 @@ class phpbb_extension_manager $old_state = (isset($this->extensions[$name]['ext_state'])) ? unserialize($this->extensions[$name]['ext_state']) : false; + // Returns false if not completed + if (!$this->handle_migrations($name, 'enable')) + { + return true; + } + $extension = $this->get_extension($name); $state = $extension->enable_step($old_state); @@ -324,6 +330,12 @@ class phpbb_extension_manager $old_state = unserialize($this->extensions[$name]['ext_state']); + // Returns false if not completed + if (!$this->handle_migrations($name, 'purge')) + { + return true; + } + $extension = $this->get_extension($name); $state = $extension->purge_step($old_state); @@ -497,4 +509,54 @@ class phpbb_extension_manager { return new phpbb_extension_finder($this, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder'); } + + /** + * Handle installing/reverting migrations + * + * @param string $extension_name Name of the extension + * @param string $mode enable or purge + * @return bool True if completed, False if not completed + */ + protected function handle_migrations($extension_name, $mode) + { + $migrator = $this->container->get('migrator'); + $migrations_path = $this->get_extension_path($extension_name) . 'migrations'; + if (file_exists($migrations_path) && is_dir($migrations_path)) + { + $migrator->load_migrations($migrations_path); + } + + // What is a safe limit of execution time? Half the max execution time should be safe. + $safe_time_limit = (ini_get('max_execution_time') / 2); + $start_time = time(); + + if ($mode == 'enable') + { + while (!$migrator->finished()) + { + $migrator->update(); + + // Are we approaching the time limit? If so we want to pause the update and continue after refreshing + if ((time() - $start_time) >= $safe_time_limit) + { + return false; + } + } + } + else if ($mode == 'purge') + { + while ($migrator->migration_state() !== false) + { + $migrator->revert(); + + // Are we approaching the time limit? If so we want to pause the update and continue after refreshing + if ((time() - $start_time) >= $safe_time_limit) + { + return false; + } + } + } + + return true; + } } From 5705c3d377d097ef8bf7b99863eabc08fe3276e7 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 6 Feb 2013 13:14:40 -0600 Subject: [PATCH 3/9] [feature/migrations] Fix path to extension migrations PHPBB3-11318 --- phpBB/includes/extension/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 018324d5d6..008bd35376 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -520,7 +520,7 @@ class phpbb_extension_manager protected function handle_migrations($extension_name, $mode) { $migrator = $this->container->get('migrator'); - $migrations_path = $this->get_extension_path($extension_name) . 'migrations'; + $migrations_path = $this->phpbb_root_path . $this->get_extension_path($extension_name) . 'migrations/'; if (file_exists($migrations_path) && is_dir($migrations_path)) { $migrator->load_migrations($migrations_path); From a8da6b89e9da1d3b4e16317c21fc88fa1173d0f1 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 9 Feb 2013 20:01:40 -0600 Subject: [PATCH 4/9] [feature/migrations] Inject Migrator instead of using the container to fetch PHPBB3-11318 --- phpBB/config/services.yml | 1 + phpBB/includes/extension/manager.php | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 028ab88229..ef5359129f 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -115,6 +115,7 @@ services: - @service_container - @dbal.conn - @config + - @migrator - %tables.ext% - %core.root_path% - .%core.php_ext% diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 008bd35376..926cc015de 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -29,6 +29,7 @@ class phpbb_extension_manager protected $db; protected $config; + protected $migrator; protected $cache; protected $php_ext; protected $extensions; @@ -48,12 +49,13 @@ class phpbb_extension_manager * @param phpbb_cache_driver_interface $cache A cache instance or null * @param string $cache_name The name of the cache variable, defaults to _ext */ - public function __construct(ContainerInterface $container, phpbb_db_driver $db, phpbb_config $config, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') + public function __construct(ContainerInterface $container, phpbb_db_driver $db, phpbb_config $config, phpbb_db_migrator $migrator, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') { $this->container = $container; $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; $this->config = $config; + $this->migrator = $migrator; $this->cache = $cache; $this->php_ext = $php_ext; $this->extension_table = $extension_table; @@ -519,11 +521,10 @@ class phpbb_extension_manager */ protected function handle_migrations($extension_name, $mode) { - $migrator = $this->container->get('migrator'); $migrations_path = $this->phpbb_root_path . $this->get_extension_path($extension_name) . 'migrations/'; if (file_exists($migrations_path) && is_dir($migrations_path)) { - $migrator->load_migrations($migrations_path); + $this->migrator->load_migrations($migrations_path); } // What is a safe limit of execution time? Half the max execution time should be safe. @@ -532,9 +533,9 @@ class phpbb_extension_manager if ($mode == 'enable') { - while (!$migrator->finished()) + while (!$this->migrator->finished()) { - $migrator->update(); + $this->migrator->update(); // Are we approaching the time limit? If so we want to pause the update and continue after refreshing if ((time() - $start_time) >= $safe_time_limit) @@ -545,9 +546,9 @@ class phpbb_extension_manager } else if ($mode == 'purge') { - while ($migrator->migration_state() !== false) + while ($this->migrator->migration_state() !== false) { - $migrator->revert(); + $this->migrator->revert(); // Are we approaching the time limit? If so we want to pause the update and continue after refreshing if ((time() - $start_time) >= $safe_time_limit) From fc4d5f74c0b82989370e899939d6f31e9a85723d Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 9 Feb 2013 20:05:39 -0600 Subject: [PATCH 5/9] [feature/migrations] Call revert correctly when purging an extension PHPBB3-11318 --- phpBB/includes/extension/manager.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 926cc015de..21a9ec1370 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -522,11 +522,13 @@ class phpbb_extension_manager protected function handle_migrations($extension_name, $mode) { $migrations_path = $this->phpbb_root_path . $this->get_extension_path($extension_name) . 'migrations/'; - if (file_exists($migrations_path) && is_dir($migrations_path)) + if (!file_exists($migrations_path) || !is_dir($migrations_path)) { - $this->migrator->load_migrations($migrations_path); + return true; } + $migrations = $this->migrator->load_migrations($migrations_path); + // What is a safe limit of execution time? Half the max execution time should be safe. $safe_time_limit = (ini_get('max_execution_time') / 2); $start_time = time(); @@ -546,14 +548,17 @@ class phpbb_extension_manager } else if ($mode == 'purge') { - while ($this->migrator->migration_state() !== false) + foreach ($migrations as $migration) { - $this->migrator->revert(); - - // Are we approaching the time limit? If so we want to pause the update and continue after refreshing - if ((time() - $start_time) >= $safe_time_limit) + while ($this->migrator->migration_state($migration) !== false) { - return false; + $this->migrator->revert($migration); + + // Are we approaching the time limit? If so we want to pause the update and continue after refreshing + if ((time() - $start_time) >= $safe_time_limit) + { + return false; + } } } } From b398fa2050ab720d9a3ae2b809bb3cdf4f153dc6 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 9 Feb 2013 21:09:29 -0600 Subject: [PATCH 6/9] [feature/migrations] Catch and display errors from the migrator PHPBB3-11318 --- phpBB/adm/style/acp_ext_enable.html | 8 +++++++- phpBB/adm/style/acp_ext_purge.html | 8 +++++++- phpBB/includes/acp/acp_extensions.php | 28 ++++++++++++++++++++------- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/phpBB/adm/style/acp_ext_enable.html b/phpBB/adm/style/acp_ext_enable.html index 3f7be2c847..35585207eb 100644 --- a/phpBB/adm/style/acp_ext_enable.html +++ b/phpBB/adm/style/acp_ext_enable.html @@ -7,7 +7,13 @@

{L_EXTENSIONS_EXPLAIN}

{L_ENABLE_EXPLAIN}

- + +
+

{L_MIGRATION_EXCEPTION_ERROR}

+

{MIGRATOR_ERROR}

+

{L_RETURN}

+
+

{L_ENABLE_CONFIRM}

diff --git a/phpBB/adm/style/acp_ext_purge.html b/phpBB/adm/style/acp_ext_purge.html index 00a58721cb..94bef82ca5 100644 --- a/phpBB/adm/style/acp_ext_purge.html +++ b/phpBB/adm/style/acp_ext_purge.html @@ -7,7 +7,13 @@

{L_EXTENSIONS_EXPLAIN}

{L_PURGE_EXPLAIN}

- + +
+

{L_MIGRATION_EXCEPTION_ERROR}

+

{MIGRATOR_ERROR}

+

{L_RETURN}

+
+

{L_PURGE_CONFIRM}

diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index a0bcf62ecc..17ab4f3169 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -37,7 +37,7 @@ class acp_extensions $this->template = $template; $this->user = $user; - $user->add_lang(array('install', 'acp/extensions')); + $user->add_lang(array('install', 'acp/extensions', 'migrator')); $this->page_title = 'ACP_EXTENSIONS'; @@ -103,11 +103,18 @@ class acp_extensions trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action)); } - if ($phpbb_extension_manager->enable_step($ext_name)) + try { - $template->assign_var('S_NEXT_STEP', true); + if ($phpbb_extension_manager->enable_step($ext_name)) + { + $template->assign_var('S_NEXT_STEP', true); - meta_refresh(0, $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name)); + meta_refresh(0, $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name)); + } + } + catch (phpbb_db_migration_exception $e) + { + $template->assign_var('MIGRATOR_ERROR', $user->lang($e->getMessage(), $e->getParameters())); } $this->tpl_name = 'acp_ext_enable'; @@ -156,11 +163,18 @@ class acp_extensions break; case 'purge': - if ($phpbb_extension_manager->purge_step($ext_name)) + try { - $template->assign_var('S_NEXT_STEP', true); + if ($phpbb_extension_manager->purge_step($ext_name)) + { + $template->assign_var('S_NEXT_STEP', true); - meta_refresh(0, $this->u_action . '&action=purge&ext_name=' . urlencode($ext_name)); + meta_refresh(0, $this->u_action . '&action=purge&ext_name=' . urlencode($ext_name)); + } + } + catch (phpbb_db_migration_exception $e) + { + $template->assign_var('MIGRATOR_ERROR', $user->lang($e->getMessage(), $e->getParameters())); } $this->tpl_name = 'acp_ext_purge'; From 3a68bba2fbfe8416884ac5230876cc73c3ba30bd Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Mon, 11 Feb 2013 21:31:34 -0600 Subject: [PATCH 7/9] [feature/migrations] Fix failing tests PHPBB3-11318 --- tests/extension/manager_test.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 5c0b419540..e31e27ef83 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -25,14 +25,22 @@ class phpbb_extension_manager_test extends phpbb_database_test_case { parent::setUp(); + $config = new phpbb_config(array()); + $db = $this->new_dbal(); + $db_tools = new phpbb_db_tools($db); + $phpbb_root_path = __DIR__ . './../../phpBB/'; + $php_ext = 'php'; + $table_prefix = 'phpbb_'; + $this->extension_manager = new phpbb_extension_manager( new phpbb_mock_container_builder(), - $this->new_dbal(), - new phpbb_config(array()), + $db, + $config, + new phpbb_db_migrator($config, $db, $db_tools, 'phpbb_migrations', $phpbb_root_path, $php_ext, $table_prefix, array()), 'phpbb_ext', dirname(__FILE__) . '/', - '.php', - new phpbb_mock_cache + '.' . $php_ext, + new phpbb_mock_cache() ); } From 193a3beb8f75e17b09a0e66d2815bc2bf8d4dce4 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 13 Feb 2013 21:12:50 -0600 Subject: [PATCH 8/9] [feature/migrations] Fix failing tests (again) PHPBB3-11318 --- tests/extension/manager_test.php | 48 +++++++++---------- tests/extension/metadata_manager_test.php | 3 ++ .../phpbb_functional_test_case.php | 26 +++++----- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index e31e27ef83..9032afbd73 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -25,23 +25,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case { parent::setUp(); - $config = new phpbb_config(array()); - $db = $this->new_dbal(); - $db_tools = new phpbb_db_tools($db); - $phpbb_root_path = __DIR__ . './../../phpBB/'; - $php_ext = 'php'; - $table_prefix = 'phpbb_'; - - $this->extension_manager = new phpbb_extension_manager( - new phpbb_mock_container_builder(), - $db, - $config, - new phpbb_db_migrator($config, $db, $db_tools, 'phpbb_migrations', $phpbb_root_path, $php_ext, $table_prefix, array()), - 'phpbb_ext', - dirname(__FILE__) . '/', - '.' . $php_ext, - new phpbb_mock_cache() - ); + $this->extension_manager = $this->create_extension_manager(); } public function test_available() @@ -98,16 +82,30 @@ class phpbb_extension_manager_test extends phpbb_database_test_case public function test_enabled_no_cache() { - $extension_manager = new phpbb_extension_manager( - new phpbb_mock_container_builder(), - $this->new_dbal(), - new phpbb_config(array()), - 'phpbb_ext', - dirname(__FILE__) . '/', - '.php' - ); + $extension_manager = $this->create_extension_manager(false); $this->assertEquals(array('foo'), array_keys($extension_manager->all_enabled())); } + protected function create_extension_manager($with_cache = true) + { + + $config = new phpbb_config(array()); + $db = $this->new_dbal(); + $db_tools = new phpbb_db_tools($db); + $phpbb_root_path = __DIR__ . './../../phpBB/'; + $php_ext = 'php'; + $table_prefix = 'phpbb_'; + + return new phpbb_extension_manager( + new phpbb_mock_container_builder(), + $db, + $config, + new phpbb_db_migrator($config, $db, $db_tools, 'phpbb_migrations', $phpbb_root_path, $php_ext, $table_prefix, array()), + 'phpbb_ext', + dirname(__FILE__) . '/', + '.' . $php_ext, + ($with_cache) ? new phpbb_mock_cache() : null + ); + } } diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 7a04229a9c..cdea8d5258 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -34,9 +34,11 @@ class metadata_manager_test extends phpbb_database_test_case 'version' => '3.1.0', )); $this->db = $this->new_dbal(); + $this->db_tools = new phpbb_db_tools($this->db); $this->phpbb_root_path = dirname(__FILE__) . '/'; $this->phpEx = '.php'; $this->user = new phpbb_user(); + $this->table_prefix = 'phpbb_'; $this->template = new phpbb_template( $this->phpbb_root_path, @@ -51,6 +53,7 @@ class metadata_manager_test extends phpbb_database_test_case new phpbb_mock_container_builder(), $this->db, $this->config, + new phpbb_db_migrator($this->config, $this->db, $this->db_tools, 'phpbb_migrations', $this->phpbb_root_path, $this->php_ext, $this->table_prefix, array()), 'phpbb_ext', $this->phpbb_root_path, $this->phpEx, diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index cb0a475278..b570b464e6 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -134,20 +134,20 @@ class phpbb_functional_test_case extends phpbb_test_case { global $phpbb_root_path, $phpEx; - if (!$this->extension_manager) - { - $this->extension_manager = new phpbb_extension_manager( - new phpbb_mock_container_builder(), - $this->get_db(), - new phpbb_config(array()), - self::$config['table_prefix'] . 'ext', - $phpbb_root_path, - ".$phpEx", - $this->get_cache_driver() - ); - } + $config = new phpbb_config(array()); + $db = $this->get_db(); + $db_tools = new phpbb_db_tools($db); - return $this->extension_manager; + return new phpbb_extension_manager( + new phpbb_mock_container_builder(), + $db, + $config, + new phpbb_db_migrator($config, $db, $db_tools, self::$config['table_prefix'] . 'migrations', $phpbb_root_path, $php_ext, self::$config['table_prefix'], array()), + self::$config['table_prefix'] . 'ext', + dirname(__FILE__) . '/', + '.' . $php_ext, + $this->get_cache_driver() + ); } static protected function install_board() From 872773a21897ccad754a53d7c8ad7899bcc05796 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 15 Feb 2013 22:22:13 -0600 Subject: [PATCH 9/9] [feature/migrations] Use getLocalisedMessage() function to get error message PHPBB3-11318 --- phpBB/includes/acp/acp_extensions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 17ab4f3169..24211196bd 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -114,7 +114,7 @@ class acp_extensions } catch (phpbb_db_migration_exception $e) { - $template->assign_var('MIGRATOR_ERROR', $user->lang($e->getMessage(), $e->getParameters())); + $template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($user)); } $this->tpl_name = 'acp_ext_enable'; @@ -174,7 +174,7 @@ class acp_extensions } catch (phpbb_db_migration_exception $e) { - $template->assign_var('MIGRATOR_ERROR', $user->lang($e->getMessage(), $e->getParameters())); + $template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($user)); } $this->tpl_name = 'acp_ext_purge';