diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index ec88a4a392..5b9ee6c53e 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -11,6 +11,8 @@ * */ +use phpbb\exception\exception_interface; + /** * @ignore */ @@ -92,7 +94,7 @@ class acp_extensions { $md_manager->get_metadata('all'); } - catch (\phpbb\extension\exception $e) + catch (exception_interface $e) { $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); trigger_error($message, E_USER_WARNING); @@ -320,11 +322,13 @@ class acp_extensions $template->assign_block_vars('updates_available', $version_data); } } - catch (\RuntimeException $e) + catch (exception_interface $e) { + $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); + $template->assign_vars(array( 'S_VERSIONCHECK_STATUS' => $e->getCode(), - 'VERSIONCHECK_FAIL_REASON' => ($e->getMessage() !== $user->lang('VERSIONCHECK_FAIL')) ? $e->getMessage() : '', + 'VERSIONCHECK_FAIL_REASON' => ($e->getMessage() !== 'VERSIONCHECK_FAIL') ? $message : '', )); } @@ -367,7 +371,7 @@ class acp_extensions $enabled_extension_meta_data[$name]['S_VERSIONCHECK'] = true; $enabled_extension_meta_data[$name]['U_VERSIONCHECK_FORCE'] = $this->u_action . '&action=details&versioncheck_force=1&ext_name=' . urlencode($md_manager->get_metadata('name')); } - catch (\phpbb\extension\exception $e) + catch (exception_interface $e) { $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); $this->template->assign_block_vars('disabled', array( @@ -425,7 +429,7 @@ class acp_extensions $disabled_extension_meta_data[$name]['S_VERSIONCHECK'] = true; $disabled_extension_meta_data[$name]['U_VERSIONCHECK_FORCE'] = $this->u_action . '&action=details&versioncheck_force=1&ext_name=' . urlencode($md_manager->get_metadata('name')); } - catch (\phpbb\extension\exception $e) + catch (exception_interface $e) { $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); $this->template->assign_block_vars('disabled', array( @@ -486,7 +490,7 @@ class acp_extensions $available_extension_meta_data[$name]['S_VERSIONCHECK'] = true; $available_extension_meta_data[$name]['U_VERSIONCHECK_FORCE'] = $this->u_action . '&action=details&versioncheck_force=1&ext_name=' . urlencode($md_manager->get_metadata('name')); } - catch (\phpbb\extension\exception $e) + catch (exception_interface $e) { $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); $this->template->assign_block_vars('disabled', array( diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php index fe9657aecb..8dec7c69bd 100644 --- a/phpBB/includes/acp/acp_main.php +++ b/phpBB/includes/acp/acp_main.php @@ -450,9 +450,10 @@ class acp_main } catch (\RuntimeException $e) { + $message = call_user_func_array(array($user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); $template->assign_vars(array( 'S_VERSIONCHECK_FAIL' => true, - 'VERSIONCHECK_FAIL_REASON' => ($e->getMessage() !== $user->lang('VERSIONCHECK_FAIL')) ? $e->getMessage() : '', + 'VERSIONCHECK_FAIL_REASON' => ($e->getMessage() !== 'VERSIONCHECK_FAIL') ? $message : '', )); } } diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php index 0ef3c970ac..982c86bf8c 100644 --- a/phpBB/phpbb/console/command/update/check.php +++ b/phpBB/phpbb/console/command/update/check.php @@ -13,6 +13,7 @@ namespace phpbb\console\command\update; +use phpbb\exception\exception_interface; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; @@ -116,18 +117,9 @@ class check extends \phpbb\console\command\command */ protected function check_ext(InputInterface $input, OutputInterface $output, $stability, $recheck, $ext_name) { - try - { - $ext_manager = $this->phpbb_container->get('ext.manager'); - $md_manager = $ext_manager->create_extension_metadata_manager($ext_name, null); - $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); - } - catch (\RuntimeException $e) - { - $output->writeln('' . $e->getMessage() . ''); - - return 2; - } + $ext_manager = $this->phpbb_container->get('ext.manager'); + $md_manager = $ext_manager->create_extension_metadata_manager($ext_name, null); + $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); $metadata = $md_manager->get_metadata('all'); if ($input->getOption('verbose')) @@ -178,16 +170,7 @@ class check extends \phpbb\console\command\command $version_helper = $this->phpbb_container->get('version_helper'); $version_helper->force_stability($stability); - try - { - $updates_available = $version_helper->get_suggested_updates($recheck); - } - catch (\RuntimeException $e) - { - $output->writeln('' . $this->user->lang('VERSIONCHECK_FAIL') . ''); - - return 2; - } + $updates_available = $version_helper->get_suggested_updates($recheck); if ($input->getOption('verbose')) { @@ -258,6 +241,11 @@ class check extends \phpbb\console\command\command $message .= ' | '; } } + catch (exception_interface $e) + { + $exception_message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); + $message .= ('' . $exception_message . ''); + } catch (\RuntimeException $e) { $message .= ('' . $e->getMessage() . ''); diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php index 6cdc8c0cc7..da1f06c885 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -13,6 +13,8 @@ namespace phpbb\extension; +use phpbb\exception\runtime_exception; +use phpbb\file_downloader; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -572,7 +574,7 @@ class manager * @param bool $force_cache Force the use of the cache. Override $force_update. * @param string $stability Force the stability (null by default). * @return string - * @throws \RuntimeException + * @throws runtime_exception */ public function version_check(\phpbb\extension\metadata_manager $md_manager, $force_update = false, $force_cache = false, $stability = null) { @@ -580,12 +582,12 @@ class manager if (!isset($meta['extra']['version-check'])) { - throw new \RuntimeException($this->user->lang('NO_VERSIONCHECK'), 1); + throw new runtime_exception('NO_VERSIONCHECK'); } $version_check = $meta['extra']['version-check']; - $version_helper = new \phpbb\version_helper($this->cache, $this->config, $this->user); + $version_helper = new \phpbb\version_helper($this->cache, $this->config, new file_downloader()); $version_helper->set_current_version($meta['version']); $version_helper->set_file_location($version_check ['host'], $version_check ['directory'], $version_check ['filename']); $version_helper->force_stability($stability); diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index a1e66ba8fe..227bb72403 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -12,6 +12,7 @@ */ namespace phpbb; +use phpbb\exception\runtime_exception; /** * Class to handle version checking and comparison @@ -58,23 +59,18 @@ class version_helper /** @var \phpbb\file_downloader */ protected $file_downloader; - /** @var \phpbb\user */ - protected $user; - /** * Constructor * * @param \phpbb\cache\service $cache * @param \phpbb\config\config $config * @param \phpbb\file_downloader $file_downloader - * @param \phpbb\user $user */ - public function __construct(\phpbb\cache\service $cache, \phpbb\config\config $config, \phpbb\file_downloader $file_downloader, \phpbb\user $user) + public function __construct(\phpbb\cache\service $cache, \phpbb\config\config $config, \phpbb\file_downloader $file_downloader) { $this->cache = $cache; $this->config = $config; $this->file_downloader = $file_downloader; - $this->user = $user; if (defined('PHPBB_QA')) { @@ -175,7 +171,7 @@ class version_helper * @param bool $force_update Ignores cached data. Defaults to false. * @param bool $force_cache Force the use of the cache. Override $force_update. * @return string - * @throws \RuntimeException + * @throws runtime_exception */ public function get_latest_on_current_branch($force_update = false, $force_cache = false) { @@ -206,7 +202,7 @@ class version_helper * @param bool $force_update Ignores cached data. Defaults to false. * @param bool $force_cache Force the use of the cache. Override $force_update. * @return string - * @throws \RuntimeException + * @throws runtime_exception */ public function get_suggested_updates($force_update = false, $force_cache = false) { @@ -227,7 +223,7 @@ class version_helper * @param bool $force_update Ignores cached data. Defaults to false. * @param bool $force_cache Force the use of the cache. Override $force_update. * @return string Version info - * @throws \RuntimeException + * @throws runtime_exception */ public function get_versions_matching_stability($force_update = false, $force_cache = false) { @@ -247,7 +243,7 @@ class version_helper * @param bool $force_update Ignores cached data. Defaults to false. * @param bool $force_cache Force the use of the cache. Override $force_update. * @return string Version info, includes stable and unstable data - * @throws \RuntimeException + * @throws runtime_exception */ public function get_versions($force_update = false, $force_cache = false) { @@ -257,23 +253,16 @@ class version_helper if ($info === false && $force_cache) { - throw new \RuntimeException($this->user->lang('VERSIONCHECK_FAIL')); + throw new runtime_exception('VERSIONCHECK_FAIL'); } else if ($info === false || $force_update) { - try { - $info = $this->file_downloader->get($this->host, $this->path, $this->file, $this->use_ssl ? 443 : 80); - } - catch (\phpbb\exception\runtime_exception $exception) - { - $prepare_parameters = array_merge(array($exception->getMessage()), $exception->get_parameters()); - throw new \RuntimeException(call_user_func_array(array($this->user, 'lang'), $prepare_parameters)); - } + $info = $this->file_downloader->get($this->host, $this->path, $this->file, $this->use_ssl ? 443 : 80); $error_string = $this->file_downloader->get_error_string(); if (!empty($error_string)) { - throw new \RuntimeException($error_string); + throw new runtime_exception($error_string); } $info = json_decode($info, true); @@ -290,9 +279,7 @@ class version_helper if (empty($info['stable']) && empty($info['unstable'])) { - $this->user->add_lang('acp/common'); - - throw new \RuntimeException($this->user->lang('VERSIONCHECK_FAIL')); + throw new runtime_exception('VERSIONCHECK_FAIL'); } $info['stable'] = (empty($info['stable'])) ? array() : $info['stable']; diff --git a/tests/console/update/check_test.php b/tests/console/update/check_test.php index 2101a3f33a..de57e4df08 100644 --- a/tests/console/update/check_test.php +++ b/tests/console/update/check_test.php @@ -62,6 +62,9 @@ class phpbb_console_command_check_test extends phpbb_test_case $this->assertSame($status, 1); } + /** + * @expectedException phpbb\exception\runtime_exception + */ public function test_error() { $command_tester = $this->get_command_tester('1'); @@ -87,7 +90,7 @@ class phpbb_console_command_check_test extends phpbb_test_case ->getMock(); $config = new \phpbb\config\config(array('version' => $current_version)); - $this->version_helper = new \phpbb\version_helper($cache, $config, new \phpbb\file_downloader(), $user); + $this->version_helper = new \phpbb\version_helper($cache, $config, new \phpbb\file_downloader()); $container = new phpbb_mock_container_builder; $container->set('version_helper', $this->version_helper); diff --git a/tests/version/version_fetch_test.php b/tests/version/version_fetch_test.php index 6ecc9b7223..c44bd5514a 100644 --- a/tests/version/version_fetch_test.php +++ b/tests/version/version_fetch_test.php @@ -28,15 +28,12 @@ class phpbb_version_helper_fetch_test extends phpbb_test_case ->disableOriginalConstructor() ->getMock(); - $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); - $this->version_helper = new \phpbb\version_helper( $this->cache, new \phpbb\config\config(array( 'version' => '3.1.0', )), - new \phpbb\file_downloader(), - new \phpbb\user(new \phpbb\language\language($lang_loader), '\phpbb\datetime') + new \phpbb\file_downloader() ); } diff --git a/tests/version/version_helper_remote_test.php b/tests/version/version_helper_remote_test.php index 724c4c970c..fa383d487f 100644 --- a/tests/version/version_helper_remote_test.php +++ b/tests/version/version_helper_remote_test.php @@ -42,8 +42,7 @@ class version_helper_remote_test extends \phpbb_test_case $this->version_helper = new \phpbb\version_helper( $this->cache, $config, - $this->file_downloader, - new \phpbb\user(new \phpbb\language\language($lang_loader), '\phpbb\datetime') + $this->file_downloader ); $this->user = new \phpbb\user(new \phpbb\language\language($lang_loader), '\phpbb\datetime'); $this->user->add_lang('acp/common'); @@ -161,8 +160,8 @@ class version_helper_remote_test extends \phpbb_test_case { try { $return = $this->version_helper->get_versions(); - } catch (\RuntimeException $e) { - $this->assertEquals((string)$e->getMessage(), $this->user->lang('VERSIONCHECK_FAIL')); + } catch (\phpbb\exception\runtime_exception $e) { + $this->assertEquals((string)$e->getMessage(), 'VERSIONCHECK_FAIL'); } } else diff --git a/tests/version/version_test.php b/tests/version/version_test.php index 05577f6a18..93d47a40a6 100644 --- a/tests/version/version_test.php +++ b/tests/version/version_test.php @@ -25,15 +25,12 @@ class phpbb_version_helper_test extends phpbb_test_case ->disableOriginalConstructor() ->getMock(); - $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); - $this->version_helper = new \phpbb\version_helper( $this->cache, new \phpbb\config\config(array( 'version' => '3.1.0', )), - new \phpbb\file_downloader(), - new \phpbb\user(new \phpbb\language\language($lang_loader), '\phpbb\datetime') + new \phpbb\file_downloader() ); }