[ticket/13891] Use the SymfonyStyle in the reparse command

PHPBB3-13891
This commit is contained in:
Tristan Darricau 2015-07-01 15:49:32 +02:00
parent c7f10ec4d4
commit 6b68544483
2 changed files with 35 additions and 5 deletions

View file

@ -86,4 +86,5 @@ $lang = array_merge($lang, array(
'CLI_FIXUP_RECALCULATE_EMAIL_HASH_SUCCESS' => 'Successfully recalculated all email hashes.', 'CLI_FIXUP_RECALCULATE_EMAIL_HASH_SUCCESS' => 'Successfully recalculated all email hashes.',
'CLI_REPARSER_REPARSE_REPARSING' => 'Reparsing %1$s (range %2$d..%3$d)', 'CLI_REPARSER_REPARSE_REPARSING' => 'Reparsing %1$s (range %2$d..%3$d)',
'CLI_REPARSER_REPARSE_SUCCESS' => 'Reparsing ended with success',
)); ));

View file

@ -13,11 +13,11 @@
namespace phpbb\console\command\reparser; namespace phpbb\console\command\reparser;
use Symfony\Component\Console\Helper\ProgressBar;
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\Console\Style\SymfonyStyle;
class reparse extends \phpbb\console\command\command class reparse extends \phpbb\console\command\command
{ {
@ -26,6 +26,11 @@ class reparse extends \phpbb\console\command\command
*/ */
protected $reparsers; protected $reparsers;
/**
* @var SymfonyStyle
*/
protected $io;
/** /**
* Constructor * Constructor
* *
@ -83,6 +88,8 @@ class reparse extends \phpbb\console\command\command
*/ */
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$this->io = new SymfonyStyle($input, $output);
$name = $input->getArgument('reparser-name'); $name = $input->getArgument('reparser-name');
if (isset($name)) if (isset($name))
{ {
@ -101,6 +108,8 @@ class reparse extends \phpbb\console\command\command
} }
} }
$this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS'));
return 0; return 0;
} }
@ -121,9 +130,28 @@ class reparse extends \phpbb\console\command\command
$min = $input->getOption('range-min'); $min = $input->getOption('range-min');
$size = $input->getOption('range-size'); $size = $input->getOption('range-size');
$output->writeLn($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $min, $max) . '</info>'); if ($max === 0)
{
return;
}
$this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $min, $max));
$this->io->newLine(2);
$progress = $this->io->createProgressBar($max);
$progress->setFormat(
" %current:s%/%max:s% %bar% %percent:3s%%\n" .
" %message%\n");
$progress->setBarWidth(60);
$progress->setMessage('');
if (!defined('PHP_WINDOWS_VERSION_BUILD'))
{
$progress->setEmptyBarCharacter('░'); // light shade character \u2591
$progress->setProgressCharacter('');
$progress->setBarCharacter('▓'); // dark shade character \u2593
}
$progress = new ProgressBar($output, $max + 1 - $min);
$progress->start(); $progress->start();
// Start from $max and decrement $current by $size until we reach $min // Start from $max and decrement $current by $size until we reach $min
@ -132,6 +160,8 @@ class reparse extends \phpbb\console\command\command
{ {
$start = max($min, $current + 1 - $size); $start = max($min, $current + 1 - $size);
$end = max($min, $current); $end = max($min, $current);
$progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $start, $end));
$reparser->reparse_range($start, $end); $reparser->reparse_range($start, $end);
$current = $start - 1; $current = $start - 1;
@ -139,7 +169,6 @@ class reparse extends \phpbb\console\command\command
} }
$progress->finish(); $progress->finish();
// The progress bar does not seem to end with a newline so we add one manually $this->io->newLine(2);
$output->writeLn('');
} }
} }