From 346f31a03156839d1b1931d2fc69cd2ab5656bc0 Mon Sep 17 00:00:00 2001 From: Etienne Baroux Date: Mon, 2 Jun 2014 10:12:18 +0200 Subject: [PATCH 01/12] [ticket/12610] Add command to check if the board is up to date. PHPBB3-12610 --- phpBB/config/default/container/services.yml | 2 +- .../default/container/services_console.yml | 9 + phpBB/includes/acp/acp_extensions.php | 46 +-- phpBB/language/en/acp/common.php | 4 + phpBB/language/en/cli.php | 29 +- phpBB/phpbb/console/command/update/check.php | 302 ++++++++++++++++++ phpBB/phpbb/extension/manager.php | 38 ++- phpBB/phpbb/extension/metadata_manager.php | 18 +- phpBB/phpbb/finder.php | 4 +- tests/console/update/check_test.php | 99 ++++++ tests/extension/manager_test.php | 2 +- tests/extension/metadata_manager_test.php | 5 +- tests/pagination/pagination_test.php | 3 +- .../phpbb_functional_test_case.php | 2 +- 14 files changed, 491 insertions(+), 72 deletions(-) create mode 100644 phpBB/phpbb/console/command/update/check.php create mode 100644 tests/console/update/check_test.php diff --git a/phpBB/config/default/container/services.yml b/phpBB/config/default/container/services.yml index 2ccda6a38e..9bb1d673f4 100644 --- a/phpBB/config/default/container/services.yml +++ b/phpBB/config/default/container/services.yml @@ -108,7 +108,7 @@ services: - '%tables.ext%' - '%core.root_path%' - '%core.php_ext%' - - '@cache.driver' + - '@cache' file_downloader: class: phpbb\file_downloader diff --git a/phpBB/config/default/container/services_console.yml b/phpBB/config/default/container/services_console.yml index 3f27ee666a..c3db4c29a5 100644 --- a/phpBB/config/default/container/services_console.yml +++ b/phpBB/config/default/container/services_console.yml @@ -220,6 +220,15 @@ services: tags: - { name: console.command } + console.command.update.check: + class: phpbb\console\command\update\check + arguments: + - @user + - @config + - @service_container + tags: + - { name: console.command } + console.command.user.activate: class: phpbb\console\command\user\activate arguments: diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index d2e01c80cc..ec88a4a392 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -86,7 +86,7 @@ class acp_extensions // If they've specified an extension, let's load the metadata manager and validate it. if ($ext_name) { - $md_manager = new \phpbb\extension\metadata_manager($ext_name, $config, $phpbb_extension_manager, $template, $phpbb_root_path); + $md_manager = new \phpbb\extension\metadata_manager($ext_name, $config, $phpbb_extension_manager, $phpbb_root_path); try { @@ -303,11 +303,11 @@ class acp_extensions case 'details': // Output it to the template - $md_manager->output_template_data(); + $md_manager->output_template_data($template); try { - $updates_available = $this->version_check($md_manager, $request->variable('versioncheck_force', false)); + $updates_available = $phpbb_extension_manager->version_check($md_manager, $request->variable('versioncheck_force', false), $this->config['extension_force_unstable'] ? 'unstable' : null); $template->assign_vars(array( 'S_UP_TO_DATE' => empty($updates_available), @@ -350,7 +350,7 @@ class acp_extensions foreach ($phpbb_extension_manager->all_enabled() as $name => $location) { - $md_manager = $phpbb_extension_manager->create_extension_metadata_manager($name, $this->template); + $md_manager = $phpbb_extension_manager->create_extension_metadata_manager($name); try { @@ -361,7 +361,7 @@ class acp_extensions ); $force_update = $this->request->variable('versioncheck_force', false); - $updates = $this->version_check($md_manager, $force_update, !$force_update); + $updates = $phpbb_extension_manager->version_check($md_manager, $force_update, !$force_update); $enabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates); $enabled_extension_meta_data[$name]['S_VERSIONCHECK'] = true; @@ -408,7 +408,7 @@ class acp_extensions foreach ($phpbb_extension_manager->all_disabled() as $name => $location) { - $md_manager = $phpbb_extension_manager->create_extension_metadata_manager($name, $this->template); + $md_manager = $phpbb_extension_manager->create_extension_metadata_manager($name); try { @@ -419,7 +419,7 @@ class acp_extensions ); $force_update = $this->request->variable('versioncheck_force', false); - $updates = $this->version_check($md_manager, $force_update, !$force_update); + $updates = $phpbb_extension_manager->version_check($md_manager, $force_update, !$force_update); $disabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates); $disabled_extension_meta_data[$name]['S_VERSIONCHECK'] = true; @@ -469,7 +469,7 @@ class acp_extensions foreach ($uninstalled as $name => $location) { - $md_manager = $phpbb_extension_manager->create_extension_metadata_manager($name, $this->template); + $md_manager = $phpbb_extension_manager->create_extension_metadata_manager($name); try { @@ -480,7 +480,7 @@ class acp_extensions ); $force_update = $this->request->variable('versioncheck_force', false); - $updates = $this->version_check($md_manager, $force_update, !$force_update); + $updates = $phpbb_extension_manager->version_check($md_manager, $force_update, !$force_update); $available_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates); $available_extension_meta_data[$name]['S_VERSIONCHECK'] = true; @@ -533,34 +533,6 @@ class acp_extensions } } - /** - * Check the version and return the available updates. - * - * @param \phpbb\extension\metadata_manager $md_manager The metadata manager for the version to check. - * @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 - */ - protected function version_check(\phpbb\extension\metadata_manager $md_manager, $force_update = false, $force_cache = false) - { - $meta = $md_manager->get_metadata('all'); - - if (!isset($meta['extra']['version-check'])) - { - throw new \RuntimeException($this->user->lang('NO_VERSIONCHECK'), 1); - } - - $version_check = $meta['extra']['version-check']; - - $version_helper = new \phpbb\version_helper($this->cache, $this->config, new \phpbb\file_downloader(), $this->user); - $version_helper->set_current_version($meta['version']); - $version_helper->set_file_location($version_check['host'], $version_check['directory'], $version_check['filename'], isset($version_check['ssl']) ? $version_check['ssl'] : false); - $version_helper->force_stability($this->config['extension_force_unstable'] ? 'unstable' : null); - - return $updates = $version_helper->get_suggested_updates($force_update, $force_cache); - } - /** * Sort helper for the table containing the metadata about the extensions. */ diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index 053671e1a2..acd9776dd7 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -328,6 +328,10 @@ $lang = array_merge($lang, array( 'USERNAMES_EXPLAIN' => 'Place each username on a separate line.', 'USER_CONTROL_PANEL' => 'User Control Panel', + 'UPDATE_NEEDED' => 'The board is not up to date.', + 'UPDATE_NOT_NEEDED' => 'The board is up to date.', + 'UPDATES_AVAILABLE' => 'Updates available:', + 'WARNING' => 'Warning', )); diff --git a/phpBB/language/en/cli.php b/phpBB/language/en/cli.php index 09f46a5cee..9198f9a653 100644 --- a/phpBB/language/en/cli.php +++ b/phpBB/language/en/cli.php @@ -50,6 +50,9 @@ $lang = array_merge($lang, array( 'CLI_DESCRIPTION_CRON_LIST' => 'Prints a list of ready and unready cron jobs.', 'CLI_DESCRIPTION_CRON_RUN' => 'Runs all ready cron tasks.', 'CLI_DESCRIPTION_CRON_RUN_ARGUMENT_1' => 'Name of the task to be run', + 'CLI_DESCRIPTION_CRON_RUN_OPTION_CACHE' => 'Run check command with cache.', + 'CLI_DESCRIPTION_CRON_RUN_OPTION_STABILITY' => 'Run command choosing to check only stable or unstable versions.', + 'CLI_DESCRIPTION_DB_LIST' => 'List all installed and available migrations.', 'CLI_DESCRIPTION_DB_MIGRATE' => 'Updates the database by applying migrations.', 'CLI_DESCRIPTION_DB_REVERT' => 'Revert a migration.', @@ -66,21 +69,29 @@ $lang = array_merge($lang, array( 'CLI_DESCRIPTION_OPTION_SHELL' => 'Launch the shell.', 'CLI_DESCRIPTION_PURGE_EXTENSION' => 'Purges the specified extension.', - 'CLI_DESCRIPTION_REPARSER_LIST' => 'Lists the types of text that can be reparsed.', - 'CLI_DESCRIPTION_REPARSER_REPARSE' => 'Reparses stored text with the current text_formatter services.', - 'CLI_DESCRIPTION_REPARSER_REPARSE_ARG_1' => 'Type of text to reparse. Leave blank to reparse everything.', + + 'CLI_DESCRIPTION_REPARSER_LIST' => 'Lists the types of text that can be reparsed.', + 'CLI_DESCRIPTION_REPARSER_REPARSE' => 'Reparses stored text with the current text_formatter services.', + 'CLI_DESCRIPTION_REPARSER_REPARSE_ARG_1' => 'Type of text to reparse. Leave blank to reparse everything.', 'CLI_DESCRIPTION_REPARSER_REPARSE_OPT_DRY_RUN' => 'Do not save any changes; just print what would happen', 'CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_MIN' => 'Lowest record ID to process', 'CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_MAX' => 'Highest record ID to process', 'CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_SIZE' => 'Approximate number of records to process at a time', 'CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RESUME' => 'Start reparsing where the last execution stopped', - 'CLI_DESCRIPTION_RECALCULATE_EMAIL_HASH' => 'Recalculates the user_email_hash column of the users table.', - 'CLI_DESCRIPTION_SET_ATOMIC_CONFIG' => 'Sets a configuration option’s value only if the old matches the current value', - 'CLI_DESCRIPTION_SET_CONFIG' => 'Sets a configuration option’s value', - 'CLI_DESCRIPTION_THUMBNAIL_DELETE' => 'Delete all existing thumbnails.', - 'CLI_DESCRIPTION_THUMBNAIL_GENERATE' => 'Generate all missing thumbnails.', - 'CLI_DESCRIPTION_THUMBNAIL_RECREATE' => 'Recreate all thumbnails.', + 'CLI_DESCRIPTION_RECALCULATE_EMAIL_HASH' => 'Recalculates the user_email_hash column of the users table.', + + 'CLI_DESCRIPTION_SET_ATOMIC_CONFIG' => 'Sets a configuration option’s value only if the old matches the current value', + 'CLI_DESCRIPTION_SET_CONFIG' => 'Sets a configuration option’s value', + + 'CLI_DESCRIPTION_THUMBNAIL_DELETE' => 'Delete all existing thumbnails.', + 'CLI_DESCRIPTION_THUMBNAIL_GENERATE' => 'Generate all missing thumbnails.', + 'CLI_DESCRIPTION_THUMBNAIL_RECREATE' => 'Recreate all thumbnails.', + + 'CLI_DESCRIPTION_UPDATE_CHECK' => 'Check if the board is up to date.', + 'CLI_DESCRIPTION_UPDATE_CHECK_ARGUMENT_1' => 'Name of the extension to check (if all, checks all the extensions)', + + 'CLI_ERROR_INVALID_STABILITY' => '"%s" is not a valid stability.', 'CLI_DESCRIPTION_USER_ACTIVATE' => 'Activate (or deactivate) a user account.', 'CLI_DESCRIPTION_USER_ACTIVATE_USERNAME' => 'Username of the account to activate.', 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)); + } + } +} diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php index 98d2d27278..6cdc8c0cc7 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -42,10 +42,10 @@ class manager * @param string $extension_table The name of the table holding extensions * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $php_ext php file extension, defaults to php - * @param \phpbb\cache\driver\driver_interface $cache A cache instance or null + * @param \phpbb\cache\service $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\driver_interface $db, \phpbb\config\config $config, \phpbb\filesystem\filesystem_interface $filesystem, $extension_table, $phpbb_root_path, $php_ext = 'php', \phpbb\cache\driver\driver_interface $cache = null, $cache_name = '_ext') + public function __construct(ContainerInterface $container, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\filesystem\filesystem_interface $filesystem, $extension_table, $phpbb_root_path, $php_ext = 'php', \phpbb\cache\service $cache = null, $cache_name = '_ext') { $this->cache = $cache; $this->cache_name = $cache_name; @@ -146,12 +146,11 @@ class manager * Instantiates the metadata manager for the extension with the given name * * @param string $name The extension name - * @param \phpbb\template\template $template The template manager * @return \phpbb\extension\metadata_manager Instance of the metadata manager */ - public function create_extension_metadata_manager($name, \phpbb\template\template $template) + public function create_extension_metadata_manager($name) { - return new \phpbb\extension\metadata_manager($name, $this->config, $this, $template, $this->phpbb_root_path); + return new \phpbb\extension\metadata_manager($name, $this->config, $this, $this->phpbb_root_path); } /** @@ -565,6 +564,35 @@ class manager return isset($this->extensions[$name]); } + /** + * Check the version and return the available updates (for an extension). + * + * @param \phpbb\extension\metadata_manager $md_manager The metadata manager for the version to check. + * @param bool $force_update Ignores cached data. Defaults to false. + * @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 + */ + public function version_check(\phpbb\extension\metadata_manager $md_manager, $force_update = false, $force_cache = false, $stability = null) + { + $meta = $md_manager->get_metadata('all'); + + if (!isset($meta['extra']['version-check'])) + { + throw new \RuntimeException($this->user->lang('NO_VERSIONCHECK'), 1); + } + + $version_check = $meta['extra']['version-check']; + + $version_helper = new \phpbb\version_helper($this->cache, $this->config, $this->user); + $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); + + return $updates = $version_helper->get_suggested_updates($force_update, $force_cache); + } + /** * Check to see if a given extension is purged * diff --git a/phpBB/phpbb/extension/metadata_manager.php b/phpBB/phpbb/extension/metadata_manager.php index 4f080647c8..fe64c92ee1 100644 --- a/phpBB/phpbb/extension/metadata_manager.php +++ b/phpBB/phpbb/extension/metadata_manager.php @@ -30,12 +30,6 @@ class metadata_manager */ protected $extension_manager; - /** - * phpBB Template instance - * @var \phpbb\template\template - */ - protected $template; - /** * phpBB root path * @var string @@ -66,14 +60,12 @@ class metadata_manager * @param string $ext_name Name (including vendor) of the extension * @param \phpbb\config\config $config phpBB Config instance * @param \phpbb\extension\manager $extension_manager An instance of the phpBB extension manager - * @param \phpbb\template\template $template phpBB Template instance * @param string $phpbb_root_path Path to the phpbb includes directory. */ - public function __construct($ext_name, \phpbb\config\config $config, \phpbb\extension\manager $extension_manager, \phpbb\template\template $template, $phpbb_root_path) + public function __construct($ext_name, \phpbb\config\config $config, \phpbb\extension\manager $extension_manager, $phpbb_root_path) { $this->config = $config; $this->extension_manager = $extension_manager; - $this->template = $template; $this->phpbb_root_path = $phpbb_root_path; $this->ext_name = $ext_name; @@ -336,11 +328,11 @@ class metadata_manager /** * Outputs the metadata into the template * - * @return null + * @param \phpbb\template\template $template phpBB Template instance */ - public function output_template_data() + public function output_template_data(\phpbb\template\template $template) { - $this->template->assign_vars(array( + $template->assign_vars(array( 'META_NAME' => $this->metadata['name'], 'META_TYPE' => $this->metadata['type'], 'META_DESCRIPTION' => (isset($this->metadata['description'])) ? $this->metadata['description'] : '', @@ -360,7 +352,7 @@ class metadata_manager foreach ($this->metadata['authors'] as $author) { - $this->template->assign_block_vars('meta_authors', array( + $template->assign_block_vars('meta_authors', array( 'AUTHOR_NAME' => $author['name'], 'AUTHOR_EMAIL' => (isset($author['email'])) ? $author['email'] : '', 'AUTHOR_HOMEPAGE' => (isset($author['homepage'])) ? $author['homepage'] : '', diff --git a/phpBB/phpbb/finder.php b/phpBB/phpbb/finder.php index 58bc27084e..1f1d931880 100644 --- a/phpBB/phpbb/finder.php +++ b/phpBB/phpbb/finder.php @@ -50,12 +50,12 @@ class finder * * @param \phpbb\filesystem\filesystem_interface $filesystem Filesystem instance * @param string $phpbb_root_path Path to the phpbb root directory - * @param \phpbb\cache\driver\driver_interface $cache A cache instance or null + * @param \phpbb\cache\service $cache A cache instance or null * @param string $php_ext php file extension * @param string $cache_name The name of the cache variable, defaults to * _ext_finder */ - public function __construct(\phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path = '', \phpbb\cache\driver\driver_interface $cache = null, $php_ext = 'php', $cache_name = '_ext_finder') + public function __construct(\phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path = '', \phpbb\cache\service $cache = null, $php_ext = 'php', $cache_name = '_ext_finder') { $this->filesystem = $filesystem; $this->phpbb_root_path = $phpbb_root_path; diff --git a/tests/console/update/check_test.php b/tests/console/update/check_test.php new file mode 100644 index 0000000000..d257ef6c0a --- /dev/null +++ b/tests/console/update/check_test.php @@ -0,0 +1,99 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Tester\CommandTester; +use phpbb\console\command\update\check; + +require_once dirname(__FILE__) . '/../../../phpBB/includes/functions_admin.php'; +require_once dirname(__FILE__) . '/../../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../../phpBB/includes/utf/utf_tools.php'; + +/** +* @slow +*/ +class phpbb_console_command_check_test extends phpbb_test_case +{ + protected $command_name; + + protected $version_helper; + + public function test_up_to_date() + { + $command_tester = $this->get_command_tester('100000'); + $status = $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); + $this->assertSame('', $command_tester->getDisplay()); + $this->assertSame($status, 0); + } + + public function test_up_to_date_verbose() + { + $command_tester = $this->get_command_tester('100000'); + $status = $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true, '--verbose' => true)); + $this->assertContains('UPDATE_NOT_NEEDED', $command_tester->getDisplay()); + $this->assertSame($status, 0); + } + + + public function test_not_up_to_date() + { + $command_tester = $this->get_command_tester('0'); + $status = $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); + $this->assertContains('UPDATE_NEEDED', $command_tester->getDisplay()); + $this->assertSame($status, 1); + } + + public function test_not_up_to_date_verbose() + { + $command_tester = $this->get_command_tester('0'); + $status = $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true, '--verbose' => true)); + $this->assertContains('UPDATE_NEEDED', $command_tester->getDisplay()); + $this->assertContains('UPDATES_AVAILABLE', $command_tester->getDisplay()); + $this->assertSame($status, 1); + } + + public function test_error() + { + $command_tester = $this->get_command_tester('1'); + $this->version_helper->set_file_location('acme.corp','foo', 'bar.json'); + + $status = $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); + $this->assertContains('VERSIONCHECK_FAIL', $command_tester->getDisplay()); + $this->assertSame($status, 2); + } + + public function get_command_tester($current_version) + { + global $user; + + $user = $this->getMock('\phpbb\user'); + $user->method('lang')->will($this->returnArgument(0)); + + $cache = $this->getMockBuilder('\phpbb\cache\service') + ->disableOriginalConstructor() + ->getMock(); + + $config = new \phpbb\config\config(array('version' => $current_version)); + $this->version_helper = new \phpbb\version_helper($cache, $config, $user); + + $container = new phpbb_mock_container_builder; + $container->set('version_helper', $this->version_helper); + + $application = new Application(); + $application->add(new check($user, $config, $container)); + + $command = $application->find('update:check'); + $this->command_name = $command->getName(); + return new CommandTester($command); + } +} diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index a24b0cf178..f619d4c19d 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -180,7 +180,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case 'phpbb_ext', dirname(__FILE__) . '/', $php_ext, - ($with_cache) ? new phpbb_mock_cache() : null + ($with_cache) ? new \phpbb\cache\service(new phpbb_mock_cache(), $config, $db, $phpbb_root_path, $php_ext) : null ); } } diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 19b99ee0ce..ce675f0d36 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -36,7 +36,6 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case { parent::setUp(); - $this->cache = new phpbb_mock_cache(); $this->config = new \phpbb\config\config(array( 'version' => '3.1.0', )); @@ -45,6 +44,9 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->db_tools = $factory->get($this->db); $this->phpbb_root_path = dirname(__FILE__) . '/'; $this->phpEx = 'php'; + + $this->cache = new \phpbb\cache\service(new phpbb_mock_cache(), $this->config, $this->db, $this->phpbb_root_path, $this->phpEx); + $this->table_prefix = 'phpbb_'; $container = new phpbb_mock_container_builder(); @@ -364,7 +366,6 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $ext_name, $this->config, $this->extension_manager, - $this->template, $this->phpbb_root_path ); } diff --git a/tests/pagination/pagination_test.php b/tests/pagination/pagination_test.php index 024b6fc02d..30b25913f7 100644 --- a/tests/pagination/pagination_test.php +++ b/tests/pagination/pagination_test.php @@ -37,10 +37,11 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case ->method('lang') ->will($this->returnCallback(array($this, 'return_callback_implode'))); + $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); + $filesystem = new \phpbb\filesystem\filesystem(); $manager = new phpbb_mock_extension_manager(dirname(__FILE__) . '/', array()); - $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); $loader = new \Symfony\Component\Routing\Loader\YamlFileLoader( new \phpbb\routing\file_locator($filesystem, dirname(__FILE__) . '/') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 2a37ca0e53..d5e78d1d60 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -263,7 +263,7 @@ class phpbb_functional_test_case extends phpbb_test_case self::$config['table_prefix'] . 'ext', dirname(__FILE__) . '/', $phpEx, - $this->get_cache_driver() + new \phpbb\cache\service($this->get_cache_driver(), $config, $this->db, $phpbb_root_path, $phpEx) ); return $extension_manager; From 376042d845a18058d93d289a1227096794da06d2 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 24 Aug 2015 10:26:05 +0200 Subject: [PATCH 02/12] [ticket/12610] Fix tests PHPBB3-12610 --- tests/console/update/check_test.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/console/update/check_test.php b/tests/console/update/check_test.php index d257ef6c0a..2101a3f33a 100644 --- a/tests/console/update/check_test.php +++ b/tests/console/update/check_test.php @@ -76,7 +76,10 @@ class phpbb_console_command_check_test extends phpbb_test_case { global $user; - $user = $this->getMock('\phpbb\user'); + $user = $this->getMock('\phpbb\user', array(), array( + new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), + '\phpbb\datetime' + )); $user->method('lang')->will($this->returnArgument(0)); $cache = $this->getMockBuilder('\phpbb\cache\service') @@ -84,7 +87,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, $user); + $this->version_helper = new \phpbb\version_helper($cache, $config, new \phpbb\file_downloader(), $user); $container = new phpbb_mock_container_builder; $container->set('version_helper', $this->version_helper); From 8481bd4e1831e3f9911263957637f4095fb088b0 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 24 Aug 2015 12:33:32 +0200 Subject: [PATCH 03/12] [ticket/12610] Use exception_interface PHPBB3-12610 --- phpBB/includes/acp/acp_extensions.php | 16 ++++++---- phpBB/includes/acp/acp_main.php | 3 +- phpBB/phpbb/console/command/update/check.php | 32 ++++++------------- phpBB/phpbb/extension/manager.php | 8 +++-- phpBB/phpbb/version_helper.php | 33 ++++++-------------- tests/console/update/check_test.php | 5 ++- tests/version/version_fetch_test.php | 5 +-- tests/version/version_helper_remote_test.php | 7 ++--- tests/version/version_test.php | 5 +-- 9 files changed, 46 insertions(+), 68 deletions(-) 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() ); } From 1f305e40252d6b13f30c6243f24864f534037b93 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 26 Aug 2015 11:38:23 +0200 Subject: [PATCH 04/12] [ticket/12610] Skip extensions with no update info PHPBB3-12610 --- phpBB/includes/acp/acp_extensions.php | 51 +++++++++++++++++++-------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 5b9ee6c53e..6fc4b6c617 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -364,12 +364,19 @@ class acp_extensions 'META_VERSION' => $meta['version'], ); - $force_update = $this->request->variable('versioncheck_force', false); - $updates = $phpbb_extension_manager->version_check($md_manager, $force_update, !$force_update); + if (isset($meta['extra']['version-check'])) + { + $force_update = $this->request->variable('versioncheck_force', false); + $updates = $phpbb_extension_manager->version_check($md_manager, $force_update, !$force_update); - $enabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates); - $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')); + $enabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates); + $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')); + } + else + { + $enabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false; + } } catch (exception_interface $e) { @@ -422,12 +429,19 @@ class acp_extensions 'META_VERSION' => $meta['version'], ); - $force_update = $this->request->variable('versioncheck_force', false); - $updates = $phpbb_extension_manager->version_check($md_manager, $force_update, !$force_update); + if (isset($meta['extra']['version-check'])) + { + $force_update = $this->request->variable('versioncheck_force', false); + $updates = $phpbb_extension_manager->version_check($md_manager, $force_update, !$force_update); - $disabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates); - $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')); + $disabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates); + $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')); + } + else + { + $disabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false; + } } catch (exception_interface $e) { @@ -483,12 +497,19 @@ class acp_extensions 'META_VERSION' => $meta['version'], ); - $force_update = $this->request->variable('versioncheck_force', false); - $updates = $phpbb_extension_manager->version_check($md_manager, $force_update, !$force_update); + if (isset($meta['extra']['version-check'])) + { + $force_update = $this->request->variable('versioncheck_force', false); + $updates = $phpbb_extension_manager->version_check($md_manager, $force_update, !$force_update); - $available_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates); - $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')); + $available_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates); + $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')); + } + else + { + $available_extension_meta_data[$name]['S_VERSIONCHECK'] = false; + } } catch (exception_interface $e) { From 45dda53310bb618dce0813d61a85948cb334e4a9 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 26 Aug 2015 12:06:56 +0200 Subject: [PATCH 05/12] [ticket/12610] Improve output PHPBB3-12610 --- phpBB/bin/phpbbcli.php | 10 +++--- phpBB/language/en/cli.php | 9 +++--- phpBB/phpbb/console/command/update/check.php | 32 +++++++++++++++----- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/phpBB/bin/phpbbcli.php b/phpBB/bin/phpbbcli.php index 2bca6e7b89..2c3675bbf1 100755 --- a/phpBB/bin/phpbbcli.php +++ b/phpBB/bin/phpbbcli.php @@ -71,16 +71,16 @@ require($phpbb_root_path . 'includes/compatibility_globals.' . $phpEx); register_compatibility_globals(); +/** @var \phpbb\language\language $language */ +$language = $phpbb_container->get('language'); +$language->add_lang(array('common', 'acp/common', 'cli')); + /* @var $user \phpbb\user */ $user = $phpbb_container->get('user'); $user->data['user_id'] = ANONYMOUS; $user->ip = '127.0.0.1'; -$user->add_lang('acp/common'); -$user->add_lang('cli'); - -/* @var $lang \phpbb\language\language */ -$lang = $phpbb_container->get('language'); +$application = new \phpbb\console\application('phpBB Console', PHPBB_VERSION, $language); $application = new \phpbb\console\application('phpBB Console', PHPBB_VERSION, $lang); $application->setDispatcher($phpbb_container->get('dispatcher')); $application->register_container_commands($phpbb_container->get('console.command_collection')); diff --git a/phpBB/language/en/cli.php b/phpBB/language/en/cli.php index 9198f9a653..6e86c75ec0 100644 --- a/phpBB/language/en/cli.php +++ b/phpBB/language/en/cli.php @@ -50,9 +50,6 @@ $lang = array_merge($lang, array( 'CLI_DESCRIPTION_CRON_LIST' => 'Prints a list of ready and unready cron jobs.', 'CLI_DESCRIPTION_CRON_RUN' => 'Runs all ready cron tasks.', 'CLI_DESCRIPTION_CRON_RUN_ARGUMENT_1' => 'Name of the task to be run', - 'CLI_DESCRIPTION_CRON_RUN_OPTION_CACHE' => 'Run check command with cache.', - 'CLI_DESCRIPTION_CRON_RUN_OPTION_STABILITY' => 'Run command choosing to check only stable or unstable versions.', - 'CLI_DESCRIPTION_DB_LIST' => 'List all installed and available migrations.', 'CLI_DESCRIPTION_DB_MIGRATE' => 'Updates the database by applying migrations.', 'CLI_DESCRIPTION_DB_REVERT' => 'Revert a migration.', @@ -88,8 +85,10 @@ $lang = array_merge($lang, array( 'CLI_DESCRIPTION_THUMBNAIL_GENERATE' => 'Generate all missing thumbnails.', 'CLI_DESCRIPTION_THUMBNAIL_RECREATE' => 'Recreate all thumbnails.', - 'CLI_DESCRIPTION_UPDATE_CHECK' => 'Check if the board is up to date.', - 'CLI_DESCRIPTION_UPDATE_CHECK_ARGUMENT_1' => 'Name of the extension to check (if all, checks all the extensions)', + 'CLI_DESCRIPTION_UPDATE_CHECK' => 'Check if the board is up to date.', + 'CLI_DESCRIPTION_UPDATE_CHECK_ARGUMENT_1' => 'Name of the extension to check (if all, checks all the extensions)', + 'CLI_DESCRIPTION_UPDATE_CHECK_OPTION_CACHE' => 'Run check command with cache.', + 'CLI_DESCRIPTION_UPDATE_CHECK_OPTION_STABILITY' => 'Run command choosing to check only stable or unstable versions.', 'CLI_ERROR_INVALID_STABILITY' => '"%s" is not a valid stability.', 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) From 0256c69191db7b2102d5fb338401ab3f58b118c6 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 26 Aug 2015 13:33:38 +0200 Subject: [PATCH 06/12] [ticket/12610] CS PHPBB3-12610 --- phpBB/bin/phpbbcli.php | 1 - phpBB/phpbb/extension/manager.php | 2 +- phpBB/phpbb/version_helper.php | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/bin/phpbbcli.php b/phpBB/bin/phpbbcli.php index 2c3675bbf1..6bd217ec07 100755 --- a/phpBB/bin/phpbbcli.php +++ b/phpBB/bin/phpbbcli.php @@ -81,7 +81,6 @@ $user->data['user_id'] = ANONYMOUS; $user->ip = '127.0.0.1'; $application = new \phpbb\console\application('phpBB Console', PHPBB_VERSION, $language); -$application = new \phpbb\console\application('phpBB Console', PHPBB_VERSION, $lang); $application->setDispatcher($phpbb_container->get('dispatcher')); $application->register_container_commands($phpbb_container->get('console.command_collection')); $application->run($input); diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php index da1f06c885..b2b60aaa9b 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -589,7 +589,7 @@ class manager $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->set_file_location($version_check['host'], $version_check['directory'], $version_check['filename']); $version_helper->force_stability($stability); return $updates = $version_helper->get_suggested_updates($force_update, $force_cache); diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 227bb72403..b1dcdf10d9 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -12,6 +12,7 @@ */ namespace phpbb; + use phpbb\exception\runtime_exception; /** From c9e493a911d8296ce1ccca5de8ec4c9f84e1983d Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 18 Feb 2016 22:33:39 +0100 Subject: [PATCH 07/12] [ticket/12610] Display the latest version and not the branch name in CLI PHPBB3-12610 --- phpBB/ext/index.htm | 10 ---------- phpBB/phpbb/console/command/update/check.php | 7 ++++++- 2 files changed, 6 insertions(+), 11 deletions(-) delete mode 100644 phpBB/ext/index.htm diff --git a/phpBB/ext/index.htm b/phpBB/ext/index.htm deleted file mode 100644 index ee1f723a7d..0000000000 --- a/phpBB/ext/index.htm +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - 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 From ab58bb8744b98478437cefd7af362aea1274621e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 18 Feb 2016 22:42:25 +0100 Subject: [PATCH 08/12] [ticket/12610] Ignor exception due to the version check in extensions list PHPBB3-12610 --- phpBB/includes/acp/acp_extensions.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 6fc4b6c617..904dd2e960 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -366,12 +366,19 @@ class acp_extensions if (isset($meta['extra']['version-check'])) { - $force_update = $this->request->variable('versioncheck_force', false); - $updates = $phpbb_extension_manager->version_check($md_manager, $force_update, !$force_update); + try + { + $force_update = $this->request->variable('versioncheck_force', false); + $updates = $phpbb_extension_manager->version_check($md_manager, $force_update, !$force_update); - $enabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates); - $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')); + $enabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates); + $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 (exception_interface $e) + { + // Ignore exceptions due to the version check + } } else { From 57915a8aaa842064d42fee419c9e0eaf7288140a Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 1 Sep 2016 16:12:04 +0200 Subject: [PATCH 09/12] [ticket/12610] Correctly handle empty cache PHPBB3-12610 --- .../default/container/services_console.yml | 6 +++--- phpBB/ext/index.htm | 10 +++++++++ phpBB/includes/acp/acp_extensions.php | 9 ++++---- .../exception/version_check_exception.php | 21 +++++++++++++++++++ phpBB/phpbb/version_helper.php | 16 +++++++------- 5 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 phpBB/ext/index.htm create mode 100644 phpBB/phpbb/exception/version_check_exception.php diff --git a/phpBB/config/default/container/services_console.yml b/phpBB/config/default/container/services_console.yml index c3db4c29a5..4420b6e345 100644 --- a/phpBB/config/default/container/services_console.yml +++ b/phpBB/config/default/container/services_console.yml @@ -223,9 +223,9 @@ services: console.command.update.check: class: phpbb\console\command\update\check arguments: - - @user - - @config - - @service_container + - '@user' + - '@config' + - '@service_container' tags: - { name: console.command } diff --git a/phpBB/ext/index.htm b/phpBB/ext/index.htm new file mode 100644 index 0000000000..ee1f723a7d --- /dev/null +++ b/phpBB/ext/index.htm @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 904dd2e960..ea6feb3e6a 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -12,6 +12,7 @@ */ use phpbb\exception\exception_interface; +use phpbb\exception\version_check_exception; /** * @ignore @@ -518,6 +519,10 @@ class acp_extensions $available_extension_meta_data[$name]['S_VERSIONCHECK'] = false; } } + catch (version_check_exception $e) + { + $available_extension_meta_data[$name]['S_VERSIONCHECK'] = false; + } catch (exception_interface $e) { $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); @@ -526,10 +531,6 @@ class acp_extensions 'S_VERSIONCHECK' => false, )); } - catch (\RuntimeException $e) - { - $available_extension_meta_data[$name]['S_VERSIONCHECK'] = false; - } } uasort($available_extension_meta_data, array($this, 'sort_extension_meta_data_table')); diff --git a/phpBB/phpbb/exception/version_check_exception.php b/phpBB/phpbb/exception/version_check_exception.php new file mode 100644 index 0000000000..0810263ade --- /dev/null +++ b/phpBB/phpbb/exception/version_check_exception.php @@ -0,0 +1,21 @@ + +* @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\exception; + +/** + * Define an exception related to the version checker. + */ +class version_check_exception extends runtime_exception +{ +} diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index b1dcdf10d9..17caaa4a60 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -13,7 +13,7 @@ namespace phpbb; -use phpbb\exception\runtime_exception; +use phpbb\exception\version_check_exception; /** * Class to handle version checking and comparison @@ -172,7 +172,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 runtime_exception + * @throws version_check_exception */ public function get_latest_on_current_branch($force_update = false, $force_cache = false) { @@ -203,7 +203,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 runtime_exception + * @throws version_check_exception */ public function get_suggested_updates($force_update = false, $force_cache = false) { @@ -224,7 +224,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 runtime_exception + * @throws version_check_exception */ public function get_versions_matching_stability($force_update = false, $force_cache = false) { @@ -244,7 +244,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 runtime_exception + * @throws version_check_exception */ public function get_versions($force_update = false, $force_cache = false) { @@ -254,7 +254,7 @@ class version_helper if ($info === false && $force_cache) { - throw new runtime_exception('VERSIONCHECK_FAIL'); + throw new version_check_exception('VERSIONCHECK_FAIL'); } else if ($info === false || $force_update) { @@ -263,7 +263,7 @@ class version_helper if (!empty($error_string)) { - throw new runtime_exception($error_string); + throw new version_check_exception($error_string); } $info = json_decode($info, true); @@ -280,7 +280,7 @@ class version_helper if (empty($info['stable']) && empty($info['unstable'])) { - throw new runtime_exception('VERSIONCHECK_FAIL'); + throw new version_check_exception('VERSIONCHECK_FAIL'); } $info['stable'] = (empty($info['stable'])) ? array() : $info['stable']; From 6c35ca80edd76906638326468b15aa9f355b477b Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 4 Dec 2016 10:37:17 +0100 Subject: [PATCH 10/12] [ticket/12610] Add a better error message when an extension is missing PHPBB3-12610 --- phpBB/language/en/acp/extensions.php | 1 + phpBB/phpbb/console/command/update/check.php | 113 +++++++++++-------- 2 files changed, 67 insertions(+), 47 deletions(-) diff --git a/phpBB/language/en/acp/extensions.php b/phpBB/language/en/acp/extensions.php index e5d6789764..8d6f8ece84 100644 --- a/phpBB/language/en/acp/extensions.php +++ b/phpBB/language/en/acp/extensions.php @@ -43,6 +43,7 @@ $lang = array_merge($lang, array( 'EXTENSION_NOT_AVAILABLE' => 'The selected extension is not available for this board, please verify your phpBB and PHP versions are allowed (see the details page).', 'EXTENSION_DIR_INVALID' => 'The selected extension has an invalid directory structure and cannot be enabled.', 'EXTENSION_NOT_ENABLEABLE' => 'The selected extension cannot be enabled, please verify the extension’s requirements.', + 'EXTENSION_NOT_INSTALLED' => 'The extension %s is not available. PLease check that you have installed it correctly.', 'DETAILS' => 'Details', 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,43 +127,52 @@ 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']); } + if (!empty($updates_available)) + { + $output->writeln(''); + $output->writeln('' . $this->language->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->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 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; - } } /** @@ -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[] = ''; From 32aa0596f3750ff19f3da799d649e7b2a3429c47 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 4 Dec 2016 17:43:51 +0100 Subject: [PATCH 11/12] [ticket/12610] Use Symfony style guide PHPBB3-12610 --- .../default/container/services_console.yml | 1 + phpBB/phpbb/console/command/update/check.php | 173 +++++++++--------- 2 files changed, 87 insertions(+), 87 deletions(-) diff --git a/phpBB/config/default/container/services_console.yml b/phpBB/config/default/container/services_console.yml index 4420b6e345..0c609a8051 100644 --- a/phpBB/config/default/container/services_console.yml +++ b/phpBB/config/default/container/services_console.yml @@ -226,6 +226,7 @@ services: - '@user' - '@config' - '@service_container' + - '@language' tags: - { name: console.command } 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); } } From 103d344cd4476b452e42cd7ba0007b5a85caeaaf Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 5 Dec 2016 15:46:05 +0100 Subject: [PATCH 12/12] [ticket/12610] Fix tests and use getOption() for console PHPBB3-12610 --- phpBB/phpbb/console/command/update/check.php | 38 ++++++++++---------- tests/console/update/check_test.php | 19 ++++++---- 2 files changed, 32 insertions(+), 25 deletions(-) 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 */ diff --git a/tests/console/update/check_test.php b/tests/console/update/check_test.php index de57e4df08..5cadc5cc97 100644 --- a/tests/console/update/check_test.php +++ b/tests/console/update/check_test.php @@ -28,6 +28,9 @@ class phpbb_console_command_check_test extends phpbb_test_case protected $version_helper; + /** @var \phpbb\language\language */ + protected $language; + public function test_up_to_date() { $command_tester = $this->get_command_tester('100000'); @@ -40,7 +43,7 @@ class phpbb_console_command_check_test extends phpbb_test_case { $command_tester = $this->get_command_tester('100000'); $status = $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true, '--verbose' => true)); - $this->assertContains('UPDATE_NOT_NEEDED', $command_tester->getDisplay()); + $this->assertContains($this->language->lang('UPDATE_NOT_NEEDED'), $command_tester->getDisplay()); $this->assertSame($status, 0); } @@ -49,7 +52,7 @@ class phpbb_console_command_check_test extends phpbb_test_case { $command_tester = $this->get_command_tester('0'); $status = $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); - $this->assertContains('UPDATE_NEEDED', $command_tester->getDisplay()); + $this->assertContains($this->language->lang('UPDATE_NEEDED'), $command_tester->getDisplay()); $this->assertSame($status, 1); } @@ -57,8 +60,8 @@ class phpbb_console_command_check_test extends phpbb_test_case { $command_tester = $this->get_command_tester('0'); $status = $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true, '--verbose' => true)); - $this->assertContains('UPDATE_NEEDED', $command_tester->getDisplay()); - $this->assertContains('UPDATES_AVAILABLE', $command_tester->getDisplay()); + $this->assertContains($this->language->lang('UPDATE_NEEDED'), $command_tester->getDisplay()); + $this->assertContains($this->language->lang('UPDATES_AVAILABLE'), $command_tester->getDisplay()); $this->assertSame($status, 1); } @@ -77,10 +80,12 @@ class phpbb_console_command_check_test extends phpbb_test_case public function get_command_tester($current_version) { - global $user; + global $user, $phpbb_root_path, $phpEx; + + $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $user = $this->getMock('\phpbb\user', array(), array( - new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), + $this->language, '\phpbb\datetime' )); $user->method('lang')->will($this->returnArgument(0)); @@ -96,7 +101,7 @@ class phpbb_console_command_check_test extends phpbb_test_case $container->set('version_helper', $this->version_helper); $application = new Application(); - $application->add(new check($user, $config, $container)); + $application->add(new check($user, $config, $container, $this->language)); $command = $application->find('update:check'); $this->command_name = $command->getName();