From 346f31a03156839d1b1931d2fc69cd2ab5656bc0 Mon Sep 17 00:00:00 2001 From: Etienne Baroux Date: Mon, 2 Jun 2014 10:12:18 +0200 Subject: [ticket/12610] Add command to check if the board is up to date. PHPBB3-12610 --- phpBB/phpbb/console/command/update/check.php | 302 +++++++++++++++++++++++++++ 1 file changed, 302 insertions(+) create mode 100644 phpBB/phpbb/console/command/update/check.php (limited to 'phpBB/phpbb/console/command/update/check.php') diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php new file mode 100644 index 0000000000..0ef3c970ac --- /dev/null +++ b/phpBB/phpbb/console/command/update/check.php @@ -0,0 +1,302 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\console\command\update; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +class check extends \phpbb\console\command\command +{ + /** @var \phpbb\config\config */ + protected $config; + + /** @var \Symfony\Component\DependencyInjection\ContainerBuilder */ + protected $phpbb_container; + + /** + * Construct method + */ + public function __construct(\phpbb\user $user, \phpbb\config\config $config, \Symfony\Component\DependencyInjection\ContainerInterface $phpbb_container) + { + parent::__construct($user); + + $this->config = $config; + $this->phpbb_container = $phpbb_container; + $this->user->add_lang(array('acp/common', 'acp/extensions')); + } + + /** + * Configures the service. + * + * Sets the name and description of the command. + * + * @return null + */ + protected function configure() + { + $this + ->setName('update:check') + ->setDescription($this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK')) + ->addArgument('ext-name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK_ARGUMENT_1')) + ->addOption('stability', null, InputOption::VALUE_REQUIRED, 'CLI_DESCRIPTION_CRON_RUN_OPTION_STABILITY') + ->addOption('cache', 'c', InputOption::VALUE_NONE, 'CLI_DESCRIPTION_CRON_RUN_OPTION_CACHE') + ; + } + + /** + * Executes the command. + * + * Checks if an update is available. + * If at least one is available, a message is printed and if verbose mode is set the list of possible updates is printed. + * If their is none, nothing is printed unless verbose mode is set. + * + * @param InputInterface $input Input stream, used to get the options. + * @param OutputInterface $output Output stream, used to print messages. + * @return int 0 if the board is up to date, 1 if it is not and 2 if an error occured. + * @throws \RuntimeException + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $recheck = true; + if ($input->getOption('cache')) + { + $recheck = false; + } + + $stability = null; + if ($input->getOption('stability')) + { + $stability = $input->getOption('stability'); + if (!($stability == 'stable') && !($stability == 'unstable')) + { + throw new \RuntimeException($this->user->lang('CLI_ERROR_INVALID_STABILITY', $stability)); + } + } + + $ext_name = $input->getArgument('ext-name'); + if ($ext_name != null) + { + if ($ext_name == 'all') + { + return $this->check_all_ext($input, $output, $stability, $recheck); + } + else + { + return $this->check_ext($input, $output, $stability, $recheck, $ext_name); + } + } + else + { + return $this->check_core($input, $output, $stability, $recheck); + } + } + + /** + * Check if a given extension is up to date + * + * @param InputInterface $input Input stream, used to get the options. + * @param OutputInterface $output Output stream, used to print messages. + * @param OutputInterface $stability Force a given stability + * @param bool $recheck Disallow the use of the cache + * @param string $ext_name The extension name + * @return int + */ + 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; + } + + $metadata = $md_manager->get_metadata('all'); + if ($input->getOption('verbose')) + { + $output->writeln('' . $md_manager->get_metadata('display-name') . ''); + $output->writeln(''); + + $output->writeln('' . $this->user->lang('CURRENT_VERSION') . $this->user->lang('COLON') . ' ' . $metadata['version']); + } + + if (!empty($updates_available)) + { + $output->writeln(''); + $output->writeln('' . $this->user->lang('NOT_UP_TO_DATE', $metadata['name']) . ''); + + if ($input->getOption('verbose')) + { + $this->display_versions($output, $updates_available); + } + + return 1; + } + else + { + $output->writeln(''); + $output->writeln('' . $this->user->lang('NOT_UP_TO_DATE', $metadata['name']) . ''); + + if ($input->getOption('verbose')) + { + $output->writeln('' . $this->user->lang('UPDATE_NOT_NEEDED') . ''); + } + + return 0; + } + } + + /** + * Check if the core is up to date + * + * @param InputInterface $input Input stream, used to get the options. + * @param OutputInterface $output Output stream, used to print messages. + * @param OutputInterface $stability Force a given stability + * @param bool $recheck Disallow the use of the cache + * @return int + */ + protected function check_core(InputInterface $input, OutputInterface $output, $stability, $recheck) + { + $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; + } + + if ($input->getOption('verbose')) + { + $output->writeln('phpBB core'); + $output->writeln(''); + + $output->writeln('' . $this->user->lang('CURRENT_VERSION') . $this->user->lang('COLON') . ' ' . $this->config['version']); + } + + if (!empty($updates_available)) + { + $output->writeln(''); + $output->writeln('' . $this->user->lang('UPDATE_NEEDED') . ''); + + if ($input->getOption('verbose')) + { + $this->display_versions($output, $updates_available); + } + + return 1; + } + else + { + if ($input->getOption('verbose')) + { + $output->writeln(''); + $output->writeln('' . $this->user->lang('UPDATE_NOT_NEEDED') . ''); + } + + return 0; + } + } + + /** + * Check if all the available extensions are up to date + * + * @param InputInterface $input Input stream, used to get the options. + * @param OutputInterface $output Output stream, used to print messages. + * @param OutputInterface $stability Force a given stability + * @param bool $recheck Disallow the use of the cache + * @return int + */ + protected function check_all_ext(InputInterface $input, OutputInterface $output, $stability, $recheck) + { + $ext_manager = $this->phpbb_container->get('ext.manager'); + + $ext_name_length = max(30, strlen($this->user->lang('EXTENSION_NAME'))); + $current_version_length = max(15, strlen($this->user->lang('CURRENT_VERSION'))); + $latest_version_length = max(15, strlen($this->user->lang('LATEST_VERSION'))); + + $output->writeln(sprintf("%-{$ext_name_length}s | %-{$current_version_length}s | %s", $this->user->lang('EXTENSION_NAME'), $this->user->lang('CURRENT_VERSION'), $this->user->lang('LATEST_VERSION'))); + $output->writeln(sprintf("%'-{$ext_name_length}s-+-%'-{$current_version_length}s-+-%'-{$latest_version_length}s", '', '', '')); + foreach ($ext_manager->all_available() as $ext_name => $ext_path) + { + $message = sprintf("%-{$ext_name_length}s", $ext_name); + $md_manager = $ext_manager->create_extension_metadata_manager($ext_name, null); + try + { + $metadata = $md_manager->get_metadata('all'); + $message .= sprintf(" | %-{$current_version_length}s", $metadata['version']); + try + { + $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); + $message .= sprintf(" | %s", implode(', ', array_keys($updates_available))); + } + catch (\RuntimeException $e) + { + $message .= ' | '; + } + } + catch (\RuntimeException $e) + { + $message .= ('' . $e->getMessage() . ''); + } + + $output->writeln($message); + } + + return 0; + } + + /** + * Display the details of the available updates + * + * @param OutputInterface $output Output stream, used to print messages. + * @param array $updates_available The list of the available updates + */ + protected function display_versions(OutputInterface $output, $updates_available) + { + $output->writeln(''); + $output->writeln('' . $this->user->lang('UPDATES_AVAILABLE') . ''); + foreach ($updates_available as $version_data) + { + $messages = array(); + $messages[] = sprintf("\t%-30s| %s", $this->user->lang('VERSION'), $version_data['current']); + + if (isset($version_data['announcement'])) + { + $messages[] = sprintf("\t%-30s| %s", $this->user->lang('ANNOUNCEMENT_TOPIC'), $version_data['announcement']); + } + + if (isset($version_data['download'])) + { + $messages[] = sprintf("\t%-30s| %s", $this->user->lang('DOWNLOAD_LATEST'), $version_data['download']); + } + + $messages[] = ''; + + $output->writeln(implode("\n", $messages)); + } + } +} -- cgit v1.2.1 From 8481bd4e1831e3f9911263957637f4095fb088b0 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 24 Aug 2015 12:33:32 +0200 Subject: [ticket/12610] Use exception_interface PHPBB3-12610 --- phpBB/phpbb/console/command/update/check.php | 32 +++++++++------------------- 1 file changed, 10 insertions(+), 22 deletions(-) (limited to 'phpBB/phpbb/console/command/update/check.php') 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() . ''); -- cgit v1.2.1 From 45dda53310bb618dce0813d61a85948cb334e4a9 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 26 Aug 2015 12:06:56 +0200 Subject: [ticket/12610] Improve output PHPBB3-12610 --- phpBB/phpbb/console/command/update/check.php | 32 +++++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'phpBB/phpbb/console/command/update/check.php') diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php index 982c86bf8c..03dd313291 100644 --- a/phpBB/phpbb/console/command/update/check.php +++ b/phpBB/phpbb/console/command/update/check.php @@ -52,8 +52,8 @@ class check extends \phpbb\console\command\command ->setName('update:check') ->setDescription($this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK')) ->addArgument('ext-name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK_ARGUMENT_1')) - ->addOption('stability', null, InputOption::VALUE_REQUIRED, 'CLI_DESCRIPTION_CRON_RUN_OPTION_STABILITY') - ->addOption('cache', 'c', InputOption::VALUE_NONE, 'CLI_DESCRIPTION_CRON_RUN_OPTION_CACHE') + ->addOption('stability', null, InputOption::VALUE_REQUIRED, $this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_STABILITY')) + ->addOption('cache', 'c', InputOption::VALUE_NONE, $this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_CACHE')) ; } @@ -215,6 +215,7 @@ class check extends \phpbb\console\command\command */ protected function check_all_ext(InputInterface $input, OutputInterface $output, $stability, $recheck) { + /** @var \phpbb\extension\manager $ext_manager */ $ext_manager = $this->phpbb_container->get('ext.manager'); $ext_name_length = max(30, strlen($this->user->lang('EXTENSION_NAME'))); @@ -230,15 +231,30 @@ class check extends \phpbb\console\command\command try { $metadata = $md_manager->get_metadata('all'); - $message .= sprintf(" | %-{$current_version_length}s", $metadata['version']); - try + if (isset($metadata['extra']['version-check'])) { - $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); - $message .= sprintf(" | %s", implode(', ', array_keys($updates_available))); + try { + $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); + if (!empty($updates_available)) + { + $message .= sprintf(" | %-{$current_version_length}s | %s", + $metadata['version'], + implode(', ', array_keys($updates_available)) + ); + } + else + { + $message .= sprintf(" | %-{$current_version_length}s | ", + $metadata['version'] + ); + } + } catch (\RuntimeException $e) { + $message .= ' | '; + } } - catch (\RuntimeException $e) + else { - $message .= ' | '; + $message .= sprintf(" | %-{$current_version_length}s | ", $metadata['version']); } } catch (exception_interface $e) -- cgit v1.2.1 From c9e493a911d8296ce1ccca5de8ec4c9f84e1983d Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 18 Feb 2016 22:33:39 +0100 Subject: [ticket/12610] Display the latest version and not the branch name in CLI PHPBB3-12610 --- phpBB/phpbb/console/command/update/check.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command/update/check.php') diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php index 03dd313291..7c1e52c955 100644 --- a/phpBB/phpbb/console/command/update/check.php +++ b/phpBB/phpbb/console/command/update/check.php @@ -237,9 +237,14 @@ class check extends \phpbb\console\command\command $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); if (!empty($updates_available)) { + $versions = array_map(function($entry) + { + return $entry['current']; + }, $updates_available); + $message .= sprintf(" | %-{$current_version_length}s | %s", $metadata['version'], - implode(', ', array_keys($updates_available)) + implode(', ', $versions) ); } else -- cgit v1.2.1 From 6c35ca80edd76906638326468b15aa9f355b477b Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 4 Dec 2016 10:37:17 +0100 Subject: [ticket/12610] Add a better error message when an extension is missing PHPBB3-12610 --- phpBB/phpbb/console/command/update/check.php | 107 ++++++++++++++++----------- 1 file changed, 63 insertions(+), 44 deletions(-) (limited to 'phpBB/phpbb/console/command/update/check.php') diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php index 7c1e52c955..19da2318ca 100644 --- a/phpBB/phpbb/console/command/update/check.php +++ b/phpBB/phpbb/console/command/update/check.php @@ -13,11 +13,15 @@ namespace phpbb\console\command\update; +use phpbb\config\config; use phpbb\exception\exception_interface; +use phpbb\language\language; +use phpbb\user; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; class check extends \phpbb\console\command\command { @@ -26,17 +30,23 @@ class check extends \phpbb\console\command\command /** @var \Symfony\Component\DependencyInjection\ContainerBuilder */ protected $phpbb_container; + /** + * @var language + */ + private $language; /** * Construct method */ - public function __construct(\phpbb\user $user, \phpbb\config\config $config, \Symfony\Component\DependencyInjection\ContainerInterface $phpbb_container) + public function __construct(user $user, config $config, ContainerInterface $phpbb_container, language $language) { parent::__construct($user); $this->config = $config; $this->phpbb_container = $phpbb_container; - $this->user->add_lang(array('acp/common', 'acp/extensions')); + $this->language = $language; + + $this->language->add_lang(array('acp/common', 'acp/extensions')); } /** @@ -50,10 +60,10 @@ class check extends \phpbb\console\command\command { $this ->setName('update:check') - ->setDescription($this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK')) - ->addArgument('ext-name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK_ARGUMENT_1')) - ->addOption('stability', null, InputOption::VALUE_REQUIRED, $this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_STABILITY')) - ->addOption('cache', 'c', InputOption::VALUE_NONE, $this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_CACHE')) + ->setDescription($this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK')) + ->addArgument('ext-name', InputArgument::OPTIONAL, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_ARGUMENT_1')) + ->addOption('stability', null, InputOption::VALUE_REQUIRED, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_STABILITY')) + ->addOption('cache', 'c', InputOption::VALUE_NONE, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_CACHE')) ; } @@ -83,7 +93,7 @@ class check extends \phpbb\console\command\command $stability = $input->getOption('stability'); if (!($stability == 'stable') && !($stability == 'unstable')) { - throw new \RuntimeException($this->user->lang('CLI_ERROR_INVALID_STABILITY', $stability)); + throw new \RuntimeException($this->language->lang('CLI_ERROR_INVALID_STABILITY', $stability)); } } @@ -117,42 +127,51 @@ class check extends \phpbb\console\command\command */ protected function check_ext(InputInterface $input, OutputInterface $output, $stability, $recheck, $ext_name) { - $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')) + try { - $output->writeln('' . $md_manager->get_metadata('display-name') . ''); - $output->writeln(''); - - $output->writeln('' . $this->user->lang('CURRENT_VERSION') . $this->user->lang('COLON') . ' ' . $metadata['version']); - } - - if (!empty($updates_available)) - { - $output->writeln(''); - $output->writeln('' . $this->user->lang('NOT_UP_TO_DATE', $metadata['name']) . ''); + $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')) { - $this->display_versions($output, $updates_available); + $output->writeln('' . $md_manager->get_metadata('display-name') . ''); + $output->writeln(''); + + $output->writeln('' . $this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $metadata['version']); } - return 1; - } - else - { - $output->writeln(''); - $output->writeln('' . $this->user->lang('NOT_UP_TO_DATE', $metadata['name']) . ''); + if (!empty($updates_available)) + { + $output->writeln(''); + $output->writeln('' . $this->language->lang('NOT_UP_TO_DATE', $metadata['name']) . ''); - if ($input->getOption('verbose')) + if ($input->getOption('verbose')) + { + $this->display_versions($output, $updates_available); + } + + return 1; + } + else { - $output->writeln('' . $this->user->lang('UPDATE_NOT_NEEDED') . ''); + $output->writeln(''); + $output->writeln('' . $this->language->lang('NOT_UP_TO_DATE', $metadata['name']) . ''); + + if ($input->getOption('verbose')) + { + $output->writeln('' . $this->language->lang('UPDATE_NOT_NEEDED') . ''); + } + + return 0; } + } + catch (\RuntimeException $e) + { + $output->writeln(''.$this->language->lang('EXTENSION_NOT_INSTALLED', $ext_name).''); - return 0; + return 1; } } @@ -177,13 +196,13 @@ class check extends \phpbb\console\command\command $output->writeln('phpBB core'); $output->writeln(''); - $output->writeln('' . $this->user->lang('CURRENT_VERSION') . $this->user->lang('COLON') . ' ' . $this->config['version']); + $output->writeln('' . $this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $this->config['version']); } if (!empty($updates_available)) { $output->writeln(''); - $output->writeln('' . $this->user->lang('UPDATE_NEEDED') . ''); + $output->writeln('' . $this->language->lang('UPDATE_NEEDED') . ''); if ($input->getOption('verbose')) { @@ -197,7 +216,7 @@ class check extends \phpbb\console\command\command if ($input->getOption('verbose')) { $output->writeln(''); - $output->writeln('' . $this->user->lang('UPDATE_NOT_NEEDED') . ''); + $output->writeln('' . $this->language->lang('UPDATE_NOT_NEEDED') . ''); } return 0; @@ -218,11 +237,11 @@ class check extends \phpbb\console\command\command /** @var \phpbb\extension\manager $ext_manager */ $ext_manager = $this->phpbb_container->get('ext.manager'); - $ext_name_length = max(30, strlen($this->user->lang('EXTENSION_NAME'))); - $current_version_length = max(15, strlen($this->user->lang('CURRENT_VERSION'))); - $latest_version_length = max(15, strlen($this->user->lang('LATEST_VERSION'))); + $ext_name_length = max(30, strlen($this->language->lang('EXTENSION_NAME'))); + $current_version_length = max(15, strlen($this->language->lang('CURRENT_VERSION'))); + $latest_version_length = max(15, strlen($this->language->lang('LATEST_VERSION'))); - $output->writeln(sprintf("%-{$ext_name_length}s | %-{$current_version_length}s | %s", $this->user->lang('EXTENSION_NAME'), $this->user->lang('CURRENT_VERSION'), $this->user->lang('LATEST_VERSION'))); + $output->writeln(sprintf("%-{$ext_name_length}s | %-{$current_version_length}s | %s", $this->language->lang('EXTENSION_NAME'), $this->language->lang('CURRENT_VERSION'), $this->language->lang('LATEST_VERSION'))); $output->writeln(sprintf("%'-{$ext_name_length}s-+-%'-{$current_version_length}s-+-%'-{$latest_version_length}s", '', '', '')); foreach ($ext_manager->all_available() as $ext_name => $ext_path) { @@ -287,20 +306,20 @@ class check extends \phpbb\console\command\command protected function display_versions(OutputInterface $output, $updates_available) { $output->writeln(''); - $output->writeln('' . $this->user->lang('UPDATES_AVAILABLE') . ''); + $output->writeln('' . $this->language->lang('UPDATES_AVAILABLE') . ''); foreach ($updates_available as $version_data) { $messages = array(); - $messages[] = sprintf("\t%-30s| %s", $this->user->lang('VERSION'), $version_data['current']); + $messages[] = sprintf("\t%-30s| %s", $this->language->lang('VERSION'), $version_data['current']); if (isset($version_data['announcement'])) { - $messages[] = sprintf("\t%-30s| %s", $this->user->lang('ANNOUNCEMENT_TOPIC'), $version_data['announcement']); + $messages[] = sprintf("\t%-30s| %s", $this->language->lang('ANNOUNCEMENT_TOPIC'), $version_data['announcement']); } if (isset($version_data['download'])) { - $messages[] = sprintf("\t%-30s| %s", $this->user->lang('DOWNLOAD_LATEST'), $version_data['download']); + $messages[] = sprintf("\t%-30s| %s", $this->language->lang('DOWNLOAD_LATEST'), $version_data['download']); } $messages[] = ''; -- cgit v1.2.1 From 32aa0596f3750ff19f3da799d649e7b2a3429c47 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 4 Dec 2016 17:43:51 +0100 Subject: [ticket/12610] Use Symfony style guide PHPBB3-12610 --- phpBB/phpbb/console/command/update/check.php | 173 +++++++++++++-------------- 1 file changed, 86 insertions(+), 87 deletions(-) (limited to 'phpBB/phpbb/console/command/update/check.php') diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php index 19da2318ca..aaccfa4983 100644 --- a/phpBB/phpbb/console/command/update/check.php +++ b/phpBB/phpbb/console/command/update/check.php @@ -21,6 +21,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\DependencyInjection\ContainerInterface; class check extends \phpbb\console\command\command @@ -40,13 +41,13 @@ class check extends \phpbb\console\command\command */ public function __construct(user $user, config $config, ContainerInterface $phpbb_container, language $language) { - parent::__construct($user); - $this->config = $config; $this->phpbb_container = $phpbb_container; $this->language = $language; $this->language->add_lang(array('acp/common', 'acp/extensions')); + + parent::__construct($user); } /** @@ -81,6 +82,8 @@ class check extends \phpbb\console\command\command */ protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + $recheck = true; if ($input->getOption('cache')) { @@ -93,7 +96,8 @@ class check extends \phpbb\console\command\command $stability = $input->getOption('stability'); if (!($stability == 'stable') && !($stability == 'unstable')) { - throw new \RuntimeException($this->language->lang('CLI_ERROR_INVALID_STABILITY', $stability)); + $io->error($this->language->lang('CLI_ERROR_INVALID_STABILITY', $stability)); + return 3; } } @@ -102,30 +106,29 @@ class check extends \phpbb\console\command\command { if ($ext_name == 'all') { - return $this->check_all_ext($input, $output, $stability, $recheck); + return $this->check_all_ext($io, $stability, $recheck); } else { - return $this->check_ext($input, $output, $stability, $recheck, $ext_name); + return $this->check_ext($io, $stability, $recheck, $ext_name); } } else { - return $this->check_core($input, $output, $stability, $recheck); + return $this->check_core($io,$stability, $recheck); } } /** - * Check if a given extension is up to date - * - * @param InputInterface $input Input stream, used to get the options. - * @param OutputInterface $output Output stream, used to print messages. - * @param OutputInterface $stability Force a given stability - * @param bool $recheck Disallow the use of the cache - * @param string $ext_name The extension name - * @return int - */ - protected function check_ext(InputInterface $input, OutputInterface $output, $stability, $recheck, $ext_name) + * Check if a given extension is up to date + * + * @param SymfonyStyle $io IO handler, for formatted and unified IO + * @param string $stability Force a given stability + * @param bool $recheck Disallow the use of the cache + * @param string $ext_name The extension name + * @return int + */ + protected function check_ext(SymfonyStyle $io, $stability, $recheck, $ext_name) { try { @@ -134,34 +137,29 @@ class check extends \phpbb\console\command\command $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); $metadata = $md_manager->get_metadata('all'); - if ($input->getOption('verbose')) + if ($io->isVerbose()) { - $output->writeln('' . $md_manager->get_metadata('display-name') . ''); - $output->writeln(''); + $io->title($md_manager->get_metadata('display-name')); - $output->writeln('' . $this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $metadata['version']); + $io->note($this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $metadata['version']); } if (!empty($updates_available)) { - $output->writeln(''); - $output->writeln('' . $this->language->lang('NOT_UP_TO_DATE', $metadata['name']) . ''); - - if ($input->getOption('verbose')) + if ($io->isVerbose()) { - $this->display_versions($output, $updates_available); + $io->caution($this->language->lang('NOT_UP_TO_DATE', $metadata['name'])); + + $this->display_versions($io, $updates_available); } return 1; } else { - $output->writeln(''); - $output->writeln('' . $this->language->lang('NOT_UP_TO_DATE', $metadata['name']) . ''); - - if ($input->getOption('verbose')) + if ($io->isVerbose()) { - $output->writeln('' . $this->language->lang('UPDATE_NOT_NEEDED') . ''); + $io->success($this->language->lang('UPDATE_NOT_NEEDED')); } return 0; @@ -169,54 +167,50 @@ class check extends \phpbb\console\command\command } catch (\RuntimeException $e) { - $output->writeln(''.$this->language->lang('EXTENSION_NOT_INSTALLED', $ext_name).''); + $io->error($this->language->lang('EXTENSION_NOT_INSTALLED', $ext_name)); return 1; } } /** - * Check if the core is up to date - * - * @param InputInterface $input Input stream, used to get the options. - * @param OutputInterface $output Output stream, used to print messages. - * @param OutputInterface $stability Force a given stability - * @param bool $recheck Disallow the use of the cache - * @return int - */ - protected function check_core(InputInterface $input, OutputInterface $output, $stability, $recheck) + * Check if the core is up to date + * + * @param SymfonyStyle $io IO handler, for formatted and unified IO + * @param string $stability Force a given stability + * @param bool $recheck Disallow the use of the cache + * @return int + */ + protected function check_core(SymfonyStyle $io, $stability, $recheck) { $version_helper = $this->phpbb_container->get('version_helper'); $version_helper->force_stability($stability); $updates_available = $version_helper->get_suggested_updates($recheck); - if ($input->getOption('verbose')) + if ($io->isVerbose()) { - $output->writeln('phpBB core'); - $output->writeln(''); + $io->title('phpBB core'); - $output->writeln('' . $this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $this->config['version']); + $io->note( $this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $this->config['version']); } if (!empty($updates_available)) { - $output->writeln(''); - $output->writeln('' . $this->language->lang('UPDATE_NEEDED') . ''); + $io->caution($this->language->lang('UPDATE_NEEDED')); - if ($input->getOption('verbose')) + if ($io->isVerbose()) { - $this->display_versions($output, $updates_available); + $this->display_versions($io, $updates_available); } return 1; } else { - if ($input->getOption('verbose')) + if ($io->isVerbose()) { - $output->writeln(''); - $output->writeln('' . $this->language->lang('UPDATE_NOT_NEEDED') . ''); + $io->success($this->language->lang('UPDATE_NOT_NEEDED')); } return 0; @@ -226,27 +220,22 @@ class check extends \phpbb\console\command\command /** * Check if all the available extensions are up to date * - * @param InputInterface $input Input stream, used to get the options. - * @param OutputInterface $output Output stream, used to print messages. - * @param OutputInterface $stability Force a given stability - * @param bool $recheck Disallow the use of the cache + * @param SymfonyStyle $io IO handler, for formatted and unified IO + * @param bool $recheck Disallow the use of the cache * @return int */ - protected function check_all_ext(InputInterface $input, OutputInterface $output, $stability, $recheck) + protected function check_all_ext(SymfonyStyle $io, $stability, $recheck) { /** @var \phpbb\extension\manager $ext_manager */ $ext_manager = $this->phpbb_container->get('ext.manager'); - $ext_name_length = max(30, strlen($this->language->lang('EXTENSION_NAME'))); - $current_version_length = max(15, strlen($this->language->lang('CURRENT_VERSION'))); - $latest_version_length = max(15, strlen($this->language->lang('LATEST_VERSION'))); + $rows = []; - $output->writeln(sprintf("%-{$ext_name_length}s | %-{$current_version_length}s | %s", $this->language->lang('EXTENSION_NAME'), $this->language->lang('CURRENT_VERSION'), $this->language->lang('LATEST_VERSION'))); - $output->writeln(sprintf("%'-{$ext_name_length}s-+-%'-{$current_version_length}s-+-%'-{$latest_version_length}s", '', '', '')); foreach ($ext_manager->all_available() as $ext_name => $ext_path) { - $message = sprintf("%-{$ext_name_length}s", $ext_name); - $md_manager = $ext_manager->create_extension_metadata_manager($ext_name, null); + $row = []; + $row[] = sprintf("%s", $ext_name); + $md_manager = $ext_manager->create_extension_metadata_manager($ext_name); try { $metadata = $md_manager->get_metadata('all'); @@ -261,70 +250,80 @@ class check extends \phpbb\console\command\command return $entry['current']; }, $updates_available); - $message .= sprintf(" | %-{$current_version_length}s | %s", - $metadata['version'], - implode(', ', $versions) - ); + $row[] = sprintf("%s", $metadata['version']); + $row[] = implode(', ', $versions); } else { - $message .= sprintf(" | %-{$current_version_length}s | ", - $metadata['version'] - ); + $row[] = sprintf("%s", $metadata['version']); + $row[] = ''; } } catch (\RuntimeException $e) { - $message .= ' | '; + $row[] = $metadata['version']; + $row[] = ''; } } else { - $message .= sprintf(" | %-{$current_version_length}s | ", $metadata['version']); + $row[] = $metadata['version']; + $row[] = ''; } } 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 . ''); + $row[] = '' . $exception_message . ''; } catch (\RuntimeException $e) { - $message .= ('' . $e->getMessage() . ''); + $row[] = '' . $e->getMessage() . ''; } - $output->writeln($message); + $rows[] = $row; } + $io->table([ + $this->language->lang('EXTENSION_NAME'), + $this->language->lang('CURRENT_VERSION'), + $this->language->lang('LATEST_VERSION'), + ], $rows); + return 0; } /** * Display the details of the available updates * - * @param OutputInterface $output Output stream, used to print messages. - * @param array $updates_available The list of the available updates + * @param SymfonyStyle $io IO handler, for formatted and unified IO + * @param array $updates_available The list of the available updates */ - protected function display_versions(OutputInterface $output, $updates_available) + protected function display_versions(SymfonyStyle $io, $updates_available) { - $output->writeln(''); - $output->writeln('' . $this->language->lang('UPDATES_AVAILABLE') . ''); + $io->section($this->language->lang('UPDATES_AVAILABLE')); + + $rows = []; foreach ($updates_available as $version_data) { - $messages = array(); - $messages[] = sprintf("\t%-30s| %s", $this->language->lang('VERSION'), $version_data['current']); + $row = ['', '', '']; + $row[0] = $version_data['current']; if (isset($version_data['announcement'])) { - $messages[] = sprintf("\t%-30s| %s", $this->language->lang('ANNOUNCEMENT_TOPIC'), $version_data['announcement']); + $row[1] = $version_data['announcement']; } if (isset($version_data['download'])) { - $messages[] = sprintf("\t%-30s| %s", $this->language->lang('DOWNLOAD_LATEST'), $version_data['download']); + $row[2] = $version_data['download']; } - $messages[] = ''; - - $output->writeln(implode("\n", $messages)); + $rows[] = $row; } + + $io->table([ + $this->language->lang('VERSION'), + $this->language->lang('ANNOUNCEMENT_TOPIC'), + $this->language->lang('DOWNLOAD_LATEST'), + ], $rows); } } -- cgit v1.2.1 From 103d344cd4476b452e42cd7ba0007b5a85caeaaf Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 5 Dec 2016 15:46:05 +0100 Subject: [ticket/12610] Fix tests and use getOption() for console PHPBB3-12610 --- phpBB/phpbb/console/command/update/check.php | 38 +++++++++++++++------------- 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'phpBB/phpbb/console/command/update/check.php') diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php index aaccfa4983..1f1cfa25d2 100644 --- a/phpBB/phpbb/console/command/update/check.php +++ b/phpBB/phpbb/console/command/update/check.php @@ -110,25 +110,26 @@ class check extends \phpbb\console\command\command } else { - return $this->check_ext($io, $stability, $recheck, $ext_name); + return $this->check_ext($input, $io, $stability, $recheck, $ext_name); } } else { - return $this->check_core($io,$stability, $recheck); + return $this->check_core($input, $io, $stability, $recheck); } } /** * Check if a given extension is up to date * - * @param SymfonyStyle $io IO handler, for formatted and unified IO - * @param string $stability Force a given stability - * @param bool $recheck Disallow the use of the cache - * @param string $ext_name The extension name + * @param InputInterface $input Input stream, used to get the options. + * @param SymfonyStyle $io IO handler, for formatted and unified IO + * @param string $stability Force a given stability + * @param bool $recheck Disallow the use of the cache + * @param string $ext_name The extension name * @return int */ - protected function check_ext(SymfonyStyle $io, $stability, $recheck, $ext_name) + protected function check_ext(InputInterface $input, SymfonyStyle $io, $stability, $recheck, $ext_name) { try { @@ -137,7 +138,7 @@ class check extends \phpbb\console\command\command $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); $metadata = $md_manager->get_metadata('all'); - if ($io->isVerbose()) + if ($input->getOption('verbose')) { $io->title($md_manager->get_metadata('display-name')); @@ -146,7 +147,7 @@ class check extends \phpbb\console\command\command if (!empty($updates_available)) { - if ($io->isVerbose()) + if ($input->getOption('verbose')) { $io->caution($this->language->lang('NOT_UP_TO_DATE', $metadata['name'])); @@ -157,7 +158,7 @@ class check extends \phpbb\console\command\command } else { - if ($io->isVerbose()) + if ($input->getOption('verbose')) { $io->success($this->language->lang('UPDATE_NOT_NEEDED')); } @@ -176,19 +177,20 @@ class check extends \phpbb\console\command\command /** * Check if the core is up to date * - * @param SymfonyStyle $io IO handler, for formatted and unified IO - * @param string $stability Force a given stability - * @param bool $recheck Disallow the use of the cache + * @param InputInterface $input Input stream, used to get the options. + * @param SymfonyStyle $io IO handler, for formatted and unified IO + * @param string $stability Force a given stability + * @param bool $recheck Disallow the use of the cache * @return int */ - protected function check_core(SymfonyStyle $io, $stability, $recheck) + protected function check_core(InputInterface $input, SymfonyStyle $io, $stability, $recheck) { $version_helper = $this->phpbb_container->get('version_helper'); $version_helper->force_stability($stability); $updates_available = $version_helper->get_suggested_updates($recheck); - if ($io->isVerbose()) + if ($input->getOption('verbose')) { $io->title('phpBB core'); @@ -199,7 +201,7 @@ class check extends \phpbb\console\command\command { $io->caution($this->language->lang('UPDATE_NEEDED')); - if ($io->isVerbose()) + if ($input->getOption('verbose')) { $this->display_versions($io, $updates_available); } @@ -208,7 +210,7 @@ class check extends \phpbb\console\command\command } else { - if ($io->isVerbose()) + if ($input->getOption('verbose')) { $io->success($this->language->lang('UPDATE_NOT_NEEDED')); } @@ -220,7 +222,7 @@ class check extends \phpbb\console\command\command /** * Check if all the available extensions are up to date * - * @param SymfonyStyle $io IO handler, for formatted and unified IO + * @param SymfonyStyle $io IO handler, for formatted and unified IO * @param bool $recheck Disallow the use of the cache * @return int */ -- cgit v1.2.1 From 2e3d90e05b7b08f6df89b9e3a98b1716d52cf340 Mon Sep 17 00:00:00 2001 From: javiexin Date: Sun, 12 Feb 2017 18:33:06 +0100 Subject: [ticket/15087] Optimize creation of metadata objects by caching Caching is done in ext_manager, and metadata_manager is further simplified by reducing the number of parameters needed. Also, move template output function from metadata_manager to acp_extensions, where it belongs. PHPBB3-15087 --- phpBB/phpbb/console/command/update/check.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command/update/check.php') diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php index 1f1cfa25d2..ed8ad79eea 100644 --- a/phpBB/phpbb/console/command/update/check.php +++ b/phpBB/phpbb/console/command/update/check.php @@ -134,7 +134,7 @@ class check extends \phpbb\console\command\command try { $ext_manager = $this->phpbb_container->get('ext.manager'); - $md_manager = $ext_manager->create_extension_metadata_manager($ext_name, null); + $md_manager = $ext_manager->create_extension_metadata_manager($ext_name); $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); $metadata = $md_manager->get_metadata('all'); -- cgit v1.2.1 From e2c0356f34bed706ca1dcf8fc0844109d764b935 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 3 Jun 2017 10:01:28 +0200 Subject: [ticket/15179] Replace spaces with a tab PHPBB3-15179 --- phpBB/phpbb/console/command/update/check.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command/update/check.php') diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php index ed8ad79eea..9ced651e8b 100644 --- a/phpBB/phpbb/console/command/update/check.php +++ b/phpBB/phpbb/console/command/update/check.php @@ -325,7 +325,7 @@ class check extends \phpbb\console\command\command $io->table([ $this->language->lang('VERSION'), $this->language->lang('ANNOUNCEMENT_TOPIC'), - $this->language->lang('DOWNLOAD_LATEST'), + $this->language->lang('DOWNLOAD_LATEST'), ], $rows); } } -- cgit v1.2.1