mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-31 14:00:31 +02:00
[ticket/12610] Use exception_interface
PHPBB3-12610
This commit is contained in:
committed by
Tristan Darricau
parent
376042d845
commit
8481bd4e18
@@ -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(
|
||||
|
@@ -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 : '',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@@ -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>');
|
||||
|
@@ -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);
|
||||
|
@@ -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'];
|
||||
|
Reference in New Issue
Block a user