1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 22:10:45 +02:00

[ticket/12610] Use exception_interface

PHPBB3-12610
This commit is contained in:
Tristan Darricau
2015-08-24 12:33:32 +02:00
committed by Tristan Darricau
parent 376042d845
commit 8481bd4e18
9 changed files with 46 additions and 68 deletions

View File

@@ -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('<error>' . $e->getMessage() . '</error>');
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('<error>' . $this->user->lang('VERSIONCHECK_FAIL') . '</error>');
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 .= ('<error>' . $exception_message . '</error>');
}
catch (\RuntimeException $e)
{
$message .= ('<error>' . $e->getMessage() . '</error>');

View File

@@ -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);

View File

@@ -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'];