[ticket/12610] Add a better error message when an extension is missing

PHPBB3-12610
This commit is contained in:
Tristan Darricau 2016-12-04 10:37:17 +01:00
parent 57915a8aaa
commit 6c35ca80ed
No known key found for this signature in database
GPG key ID: 817043C2E29DB881
2 changed files with 67 additions and 47 deletions

View file

@ -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_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_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 extensions requirements.', 'EXTENSION_NOT_ENABLEABLE' => 'The selected extension cannot be enabled, please verify the extensions requirements.',
'EXTENSION_NOT_INSTALLED' => 'The extension %s is not available. PLease check that you have installed it correctly.',
'DETAILS' => 'Details', 'DETAILS' => 'Details',

View file

@ -13,11 +13,15 @@
namespace phpbb\console\command\update; namespace phpbb\console\command\update;
use phpbb\config\config;
use phpbb\exception\exception_interface; use phpbb\exception\exception_interface;
use phpbb\language\language;
use phpbb\user;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class check extends \phpbb\console\command\command class check extends \phpbb\console\command\command
{ {
@ -26,17 +30,23 @@ class check extends \phpbb\console\command\command
/** @var \Symfony\Component\DependencyInjection\ContainerBuilder */ /** @var \Symfony\Component\DependencyInjection\ContainerBuilder */
protected $phpbb_container; protected $phpbb_container;
/**
* @var language
*/
private $language;
/** /**
* Construct method * 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); parent::__construct($user);
$this->config = $config; $this->config = $config;
$this->phpbb_container = $phpbb_container; $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 $this
->setName('update:check') ->setName('update:check')
->setDescription($this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK')) ->setDescription($this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK'))
->addArgument('ext-name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK_ARGUMENT_1')) ->addArgument('ext-name', InputArgument::OPTIONAL, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_ARGUMENT_1'))
->addOption('stability', null, InputOption::VALUE_REQUIRED, $this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_STABILITY')) ->addOption('stability', null, InputOption::VALUE_REQUIRED, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_STABILITY'))
->addOption('cache', 'c', InputOption::VALUE_NONE, $this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_CACHE')) ->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'); $stability = $input->getOption('stability');
if (!($stability == 'stable') && !($stability == 'unstable')) 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));
} }
} }
@ -116,6 +126,8 @@ class check extends \phpbb\console\command\command
* @return int * @return int
*/ */
protected function check_ext(InputInterface $input, OutputInterface $output, $stability, $recheck, $ext_name) protected function check_ext(InputInterface $input, OutputInterface $output, $stability, $recheck, $ext_name)
{
try
{ {
$ext_manager = $this->phpbb_container->get('ext.manager'); $ext_manager = $this->phpbb_container->get('ext.manager');
$md_manager = $ext_manager->create_extension_metadata_manager($ext_name, null); $md_manager = $ext_manager->create_extension_metadata_manager($ext_name, null);
@ -127,13 +139,13 @@ class check extends \phpbb\console\command\command
$output->writeln('<info>' . $md_manager->get_metadata('display-name') . '</info>'); $output->writeln('<info>' . $md_manager->get_metadata('display-name') . '</info>');
$output->writeln(''); $output->writeln('');
$output->writeln('<comment>' . $this->user->lang('CURRENT_VERSION') . $this->user->lang('COLON') . '</comment> ' . $metadata['version']); $output->writeln('<comment>' . $this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . '</comment> ' . $metadata['version']);
} }
if (!empty($updates_available)) if (!empty($updates_available))
{ {
$output->writeln(''); $output->writeln('');
$output->writeln('<question>' . $this->user->lang('NOT_UP_TO_DATE', $metadata['name']) . '</question>'); $output->writeln('<question>' . $this->language->lang('NOT_UP_TO_DATE', $metadata['name']) . '</question>');
if ($input->getOption('verbose')) if ($input->getOption('verbose'))
{ {
@ -145,16 +157,23 @@ class check extends \phpbb\console\command\command
else else
{ {
$output->writeln(''); $output->writeln('');
$output->writeln('<question>' . $this->user->lang('NOT_UP_TO_DATE', $metadata['name']) . '</question>'); $output->writeln('<question>' . $this->language->lang('NOT_UP_TO_DATE', $metadata['name']) . '</question>');
if ($input->getOption('verbose')) if ($input->getOption('verbose'))
{ {
$output->writeln('<info>' . $this->user->lang('UPDATE_NOT_NEEDED') . '</info>'); $output->writeln('<info>' . $this->language->lang('UPDATE_NOT_NEEDED') . '</info>');
} }
return 0; return 0;
} }
} }
catch (\RuntimeException $e)
{
$output->writeln('<error>'.$this->language->lang('EXTENSION_NOT_INSTALLED', $ext_name).'</error>');
return 1;
}
}
/** /**
* Check if the core is up to date * Check if the core is up to date
@ -177,13 +196,13 @@ class check extends \phpbb\console\command\command
$output->writeln('<info>phpBB core</info>'); $output->writeln('<info>phpBB core</info>');
$output->writeln(''); $output->writeln('');
$output->writeln('<comment>' . $this->user->lang('CURRENT_VERSION') . $this->user->lang('COLON') . '</comment> ' . $this->config['version']); $output->writeln('<comment>' . $this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . '</comment> ' . $this->config['version']);
} }
if (!empty($updates_available)) if (!empty($updates_available))
{ {
$output->writeln(''); $output->writeln('');
$output->writeln('<question>' . $this->user->lang('UPDATE_NEEDED') . '</question>'); $output->writeln('<question>' . $this->language->lang('UPDATE_NEEDED') . '</question>');
if ($input->getOption('verbose')) if ($input->getOption('verbose'))
{ {
@ -197,7 +216,7 @@ class check extends \phpbb\console\command\command
if ($input->getOption('verbose')) if ($input->getOption('verbose'))
{ {
$output->writeln(''); $output->writeln('');
$output->writeln('<question>' . $this->user->lang('UPDATE_NOT_NEEDED') . '</question>'); $output->writeln('<question>' . $this->language->lang('UPDATE_NOT_NEEDED') . '</question>');
} }
return 0; return 0;
@ -218,11 +237,11 @@ class check extends \phpbb\console\command\command
/** @var \phpbb\extension\manager $ext_manager */ /** @var \phpbb\extension\manager $ext_manager */
$ext_manager = $this->phpbb_container->get('ext.manager'); $ext_manager = $this->phpbb_container->get('ext.manager');
$ext_name_length = max(30, strlen($this->user->lang('EXTENSION_NAME'))); $ext_name_length = max(30, strlen($this->language->lang('EXTENSION_NAME')));
$current_version_length = max(15, strlen($this->user->lang('CURRENT_VERSION'))); $current_version_length = max(15, strlen($this->language->lang('CURRENT_VERSION')));
$latest_version_length = max(15, strlen($this->user->lang('LATEST_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", '', '', '')); $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) 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) protected function display_versions(OutputInterface $output, $updates_available)
{ {
$output->writeln(''); $output->writeln('');
$output->writeln('<comment>' . $this->user->lang('UPDATES_AVAILABLE') . '</comment>'); $output->writeln('<comment>' . $this->language->lang('UPDATES_AVAILABLE') . '</comment>');
foreach ($updates_available as $version_data) foreach ($updates_available as $version_data)
{ {
$messages = array(); $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'])) 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'])) 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[] = ''; $messages[] = '';