diff options
-rw-r--r-- | phpBB/config/default/container/services.yml | 2 | ||||
-rw-r--r-- | phpBB/config/default/container/services_console.yml | 9 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_extensions.php | 46 | ||||
-rw-r--r-- | phpBB/language/en/acp/common.php | 4 | ||||
-rw-r--r-- | phpBB/language/en/cli.php | 29 | ||||
-rw-r--r-- | phpBB/phpbb/console/command/update/check.php | 302 | ||||
-rw-r--r-- | phpBB/phpbb/extension/manager.php | 38 | ||||
-rw-r--r-- | phpBB/phpbb/extension/metadata_manager.php | 18 | ||||
-rw-r--r-- | phpBB/phpbb/finder.php | 4 | ||||
-rw-r--r-- | tests/console/update/check_test.php | 99 | ||||
-rw-r--r-- | tests/extension/manager_test.php | 2 | ||||
-rw-r--r-- | tests/extension/metadata_manager_test.php | 5 | ||||
-rw-r--r-- | tests/pagination/pagination_test.php | 3 | ||||
-rw-r--r-- | tests/test_framework/phpbb_functional_test_case.php | 2 |
14 files changed, 491 insertions, 72 deletions
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; @@ -534,34 +534,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. */ protected function sort_extension_meta_data_table($val1, $val2) 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 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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('<error>' . $e->getMessage() . '</error>'); + + return 2; + } + + $metadata = $md_manager->get_metadata('all'); + if ($input->getOption('verbose')) + { + $output->writeln('<info>' . $md_manager->get_metadata('display-name') . '</info>'); + $output->writeln(''); + + $output->writeln('<comment>' . $this->user->lang('CURRENT_VERSION') . $this->user->lang('COLON') . '</comment> ' . $metadata['version']); + } + + if (!empty($updates_available)) + { + $output->writeln(''); + $output->writeln('<question>' . $this->user->lang('NOT_UP_TO_DATE', $metadata['name']) . '</question>'); + + if ($input->getOption('verbose')) + { + $this->display_versions($output, $updates_available); + } + + return 1; + } + else + { + $output->writeln(''); + $output->writeln('<question>' . $this->user->lang('NOT_UP_TO_DATE', $metadata['name']) . '</question>'); + + if ($input->getOption('verbose')) + { + $output->writeln('<info>' . $this->user->lang('UPDATE_NOT_NEEDED') . '</info>'); + } + + 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('<error>' . $this->user->lang('VERSIONCHECK_FAIL') . '</error>'); + + return 2; + } + + if ($input->getOption('verbose')) + { + $output->writeln('<info>phpBB core</info>'); + $output->writeln(''); + + $output->writeln('<comment>' . $this->user->lang('CURRENT_VERSION') . $this->user->lang('COLON') . '</comment> ' . $this->config['version']); + } + + if (!empty($updates_available)) + { + $output->writeln(''); + $output->writeln('<question>' . $this->user->lang('UPDATE_NEEDED') . '</question>'); + + if ($input->getOption('verbose')) + { + $this->display_versions($output, $updates_available); + } + + return 1; + } + else + { + if ($input->getOption('verbose')) + { + $output->writeln(''); + $output->writeln('<question>' . $this->user->lang('UPDATE_NOT_NEEDED') . '</question>'); + } + + 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("<info>%-{$ext_name_length}s</info>", $ext_name); + $md_manager = $ext_manager->create_extension_metadata_manager($ext_name, null); + try + { + $metadata = $md_manager->get_metadata('all'); + $message .= sprintf(" | <info>%-{$current_version_length}s</info>", $metadata['version']); + try + { + $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); + $message .= sprintf(" | <comment>%s</comment>", implode(', ', array_keys($updates_available))); + } + catch (\RuntimeException $e) + { + $message .= ' | '; + } + } + catch (\RuntimeException $e) + { + $message .= ('<error>' . $e->getMessage() . '</error>'); + } + + $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('<comment>' . $this->user->lang('UPDATES_AVAILABLE') . '</comment>'); + 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); } /** @@ -566,6 +565,35 @@ class manager } /** + * 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 * * An extension is purged if it is available, not enabled and not disabled. 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 @@ -31,12 +31,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 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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; |