From 615ab099e228f2d7a35a76557095a65321425963 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 29 May 2015 19:33:17 +0200 Subject: [PATCH 1/8] [ticket/13891] Added reparser:list and reparser:reparse to CLI PHPBB3-13891 --- .../default/container/services_console.yml | 16 +++ phpBB/language/en/cli.php | 5 + .../console/command/reparser/list_all.php | 70 ++++++++++++ .../console/command/reparser/reparse.php | 106 ++++++++++++++++++ 4 files changed, 197 insertions(+) create mode 100644 phpBB/phpbb/console/command/reparser/list_all.php create mode 100644 phpBB/phpbb/console/command/reparser/reparse.php diff --git a/phpBB/config/default/container/services_console.yml b/phpBB/config/default/container/services_console.yml index f0ae6c8ab4..98a26b10e8 100644 --- a/phpBB/config/default/container/services_console.yml +++ b/phpBB/config/default/container/services_console.yml @@ -140,3 +140,19 @@ services: - @dbal.conn tags: - { name: console.command } + + console.command.reparser.list: + class: phpbb\console\command\reparser\list_all + arguments: + - @user + - @service_container + tags: + - { name: console.command } + + console.command.reparser.reparse: + class: phpbb\console\command\reparser\reparse + arguments: + - @user + - @text_reparser_collection + tags: + - { name: console.command } diff --git a/phpBB/language/en/cli.php b/phpBB/language/en/cli.php index 0e7dc39b95..bbcc736143 100644 --- a/phpBB/language/en/cli.php +++ b/phpBB/language/en/cli.php @@ -61,6 +61,9 @@ $lang = array_merge($lang, array( 'CLI_DESCRIPTION_OPTION_SAFE_MODE' => 'Run in Safe Mode (without extensions).', '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_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', @@ -78,4 +81,6 @@ $lang = array_merge($lang, array( 'CLI_EXTENSIONS_ENABLED' => 'Enabled', 'CLI_FIXUP_RECALCULATE_EMAIL_HASH_SUCCESS' => 'Successfully recalculated all email hashes.', + + 'CLI_REPARSER_REPARSE_REPARSING' => 'Reparsing %1$s with range %2$d..%3$d', )); diff --git a/phpBB/phpbb/console/command/reparser/list_all.php b/phpBB/phpbb/console/command/reparser/list_all.php new file mode 100644 index 0000000000..10db568386 --- /dev/null +++ b/phpBB/phpbb/console/command/reparser/list_all.php @@ -0,0 +1,70 @@ + +* @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\reparser; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; + +class list_all extends \phpbb\console\command\command +{ + /** + * @var string[] Names of the reparser services + */ + protected $reparser_names; + + /** + * Constructor + * + * @param \phpbb\user $user + * @param ContainerBuilder $container Container used to locate the reparsers + */ + public function __construct(\phpbb\user $user, ContainerBuilder $container) + { + parent::__construct($user); + $this->reparser_names = array(); + foreach (array_keys($container->findTaggedServiceIds('text_reparser.plugin')) as $name) + { + // Store the names without the "text_reparser." prefix + $this->reparser_names[] = str_replace('text_reparser.', '', $name); + } + } + + /** + * Sets the command name and description + * + * @return null + */ + protected function configure() + { + $this + ->setName('reparser:list') + ->setDescription($this->user->lang('CLI_DESCRIPTION_REPARSER_LIST')) + ; + } + + /** + * Executes the command reparser:reparse + * + * @param InputInterface $input + * @param OutputInterface $output + * @return integer + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $output->writeln('' . implode(', ', $this->reparser_names) . ''); + + return 0; + } +} diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php new file mode 100644 index 0000000000..f2bbe9c7d1 --- /dev/null +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -0,0 +1,106 @@ + +* @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\reparser; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Output\OutputInterface; + +class reparse extends \phpbb\console\command\command +{ + /** + * @var \phpbb\textreparser\reparser_collection + */ + protected $reparser_collection; + + /** + * Constructor + * + * @param \phpbb\user $user + * @param \phpbb\textreparser\reparser_collection $reparser_collection + */ + public function __construct(\phpbb\user $user, \phpbb\textreparser\reparser_collection $reparser_collection) + { + require_once __DIR__ . '/../../../../includes/functions_content.php'; + + $this->reparser_collection = $reparser_collection; + parent::__construct($user); + } + + /** + * Sets the command name and description + * + * @return null + */ + protected function configure() + { + $this + ->setName('reparser:reparse') + ->setDescription($this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE')) + ->addArgument('reparser-name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_ARG_1')) + ; + } + + /** + * Executes the command reparser:reparse + * + * @param InputInterface $input + * @param OutputInterface $output + * @return integer + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $name = $input->getArgument('reparser-name'); + if (isset($name)) + { + // Allow "post_text" to be an alias for "text_reparser.post_text" + if (!isset($this->reparser_collection[$name])) + { + $name = 'text_reparser.' . $name; + } + $this->reparse($output, $name); + } + else + { + foreach ($this->reparser_collection as $name => $service) + { + $this->reparse($output, $name); + } + } + + return 0; + } + + /** + * Reparse all text handled by given reparser + * + * @param OutputInterface $output + * @param string $name Reparser name + * @return null + */ + protected function reparse(OutputInterface $output, $name) + { + $reparser = $this->reparser_collection[$name]; + $id = $reparser->get_max_id(); + $n = 100; + while ($id > 0) + { + $start = max(0, $id + 1 - $n); + $end = $id; + $output->writeln('' . $this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $name, $start, $end) . ''); + $reparser->reparse_range($start, $end); + $id -= $n; + } + } +} From 119f90e36301463ffd01005a9390d3346be7774f Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 29 Jun 2015 22:15:08 +0200 Subject: [PATCH 2/8] [ticket/13891] Replaced ContainerBuilder with service_collection PHPBB3-13891 --- .../default/container/services_console.yml | 2 +- .../phpbb/console/command/reparser/list_all.php | 7 +++---- phpBB/phpbb/console/command/reparser/reparse.php | 16 ++++++++-------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/phpBB/config/default/container/services_console.yml b/phpBB/config/default/container/services_console.yml index 98a26b10e8..f39218ed9c 100644 --- a/phpBB/config/default/container/services_console.yml +++ b/phpBB/config/default/container/services_console.yml @@ -145,7 +145,7 @@ services: class: phpbb\console\command\reparser\list_all arguments: - @user - - @service_container + - @text_reparser_collection tags: - { name: console.command } diff --git a/phpBB/phpbb/console/command/reparser/list_all.php b/phpBB/phpbb/console/command/reparser/list_all.php index 10db568386..1589836ddd 100644 --- a/phpBB/phpbb/console/command/reparser/list_all.php +++ b/phpBB/phpbb/console/command/reparser/list_all.php @@ -15,7 +15,6 @@ namespace phpbb\console\command\reparser; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\DependencyInjection\ContainerBuilder; class list_all extends \phpbb\console\command\command { @@ -28,13 +27,13 @@ class list_all extends \phpbb\console\command\command * Constructor * * @param \phpbb\user $user - * @param ContainerBuilder $container Container used to locate the reparsers + * @param \phpbb\di\service_collection $reparsers */ - public function __construct(\phpbb\user $user, ContainerBuilder $container) + public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers) { parent::__construct($user); $this->reparser_names = array(); - foreach (array_keys($container->findTaggedServiceIds('text_reparser.plugin')) as $name) + foreach ($reparsers as $name => $reparser) { // Store the names without the "text_reparser." prefix $this->reparser_names[] = str_replace('text_reparser.', '', $name); diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index f2bbe9c7d1..8cefee837f 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -20,21 +20,21 @@ use Symfony\Component\Console\Output\OutputInterface; class reparse extends \phpbb\console\command\command { /** - * @var \phpbb\textreparser\reparser_collection + * @var \phpbb\di\service_collection */ - protected $reparser_collection; + protected $reparsers; /** * Constructor * * @param \phpbb\user $user - * @param \phpbb\textreparser\reparser_collection $reparser_collection + * @param \phpbb\di\service_collection $reparser_collection */ - public function __construct(\phpbb\user $user, \phpbb\textreparser\reparser_collection $reparser_collection) + public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers) { require_once __DIR__ . '/../../../../includes/functions_content.php'; - $this->reparser_collection = $reparser_collection; + $this->reparsers = $reparsers; parent::__construct($user); } @@ -65,7 +65,7 @@ class reparse extends \phpbb\console\command\command if (isset($name)) { // Allow "post_text" to be an alias for "text_reparser.post_text" - if (!isset($this->reparser_collection[$name])) + if (!isset($this->reparsers[$name])) { $name = 'text_reparser.' . $name; } @@ -73,7 +73,7 @@ class reparse extends \phpbb\console\command\command } else { - foreach ($this->reparser_collection as $name => $service) + foreach ($this->reparsers as $name => $service) { $this->reparse($output, $name); } @@ -91,7 +91,7 @@ class reparse extends \phpbb\console\command\command */ protected function reparse(OutputInterface $output, $name) { - $reparser = $this->reparser_collection[$name]; + $reparser = $this->reparsers[$name]; $id = $reparser->get_max_id(); $n = 100; while ($id > 0) From fadb192c570db25fe4b36b1b3803fb923e6f9d4e Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 29 Jun 2015 23:05:52 +0200 Subject: [PATCH 3/8] [ticket/13891] Added command-line options PHPBB3-13891 --- phpBB/language/en/cli.php | 3 ++ .../console/command/reparser/reparse.php | 43 +++++++++++++++---- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/phpBB/language/en/cli.php b/phpBB/language/en/cli.php index bbcc736143..c301f98261 100644 --- a/phpBB/language/en/cli.php +++ b/phpBB/language/en/cli.php @@ -64,6 +64,9 @@ $lang = array_merge($lang, array( '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_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_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', diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 8cefee837f..5e1993d44c 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -15,6 +15,7 @@ namespace phpbb\console\command\reparser; 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 reparse extends \phpbb\console\command\command @@ -49,6 +50,26 @@ class reparse extends \phpbb\console\command\command ->setName('reparser:reparse') ->setDescription($this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE')) ->addArgument('reparser-name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_ARG_1')) + ->addOption( + 'range-min', + null, + InputOption::VALUE_REQUIRED, + $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_MIN'), + 0 + ) + ->addOption( + 'range-max', + null, + InputOption::VALUE_REQUIRED, + $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_MAX') + ) + ->addOption( + 'range-size', + null, + InputOption::VALUE_REQUIRED, + $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_SIZE'), + 100 + ); ; } @@ -69,13 +90,13 @@ class reparse extends \phpbb\console\command\command { $name = 'text_reparser.' . $name; } - $this->reparse($output, $name); + $this->reparse($input, $output, $name); } else { foreach ($this->reparsers as $name => $service) { - $this->reparse($output, $name); + $this->reparse($input, $output, $name); } } @@ -83,24 +104,28 @@ class reparse extends \phpbb\console\command\command } /** - * Reparse all text handled by given reparser + * Reparse all text handled by given reparser within given range * + * @param InputInterface $input * @param OutputInterface $output * @param string $name Reparser name * @return null */ - protected function reparse(OutputInterface $output, $name) + protected function reparse(InputInterface $input, OutputInterface $output, $name) { $reparser = $this->reparsers[$name]; - $id = $reparser->get_max_id(); - $n = 100; - while ($id > 0) + + // Start at range-max if specified or at the highest ID otherwise + $id = (is_null($input->getOption('range-max'))) ? $reparser->get_max_id() : $input->getOption('range-max'); + $min = $input->getOption('range-min'); + $size = $input->getOption('range-size'); + while ($id > $min) { - $start = max(0, $id + 1 - $n); + $start = max($min, $id + 1 - $size); $end = $id; $output->writeln('' . $this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $name, $start, $end) . ''); $reparser->reparse_range($start, $end); - $id -= $n; + $id -= $size; } } } From 6de5e5cc36d4b934cfa4043faf12adb279f8a2c6 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 30 Jun 2015 00:28:02 +0200 Subject: [PATCH 4/8] [ticket/13891] Added a progress bar PHPBB3-13891 --- phpBB/language/en/cli.php | 2 +- .../console/command/reparser/reparse.php | 26 ++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/phpBB/language/en/cli.php b/phpBB/language/en/cli.php index c301f98261..d1f229272c 100644 --- a/phpBB/language/en/cli.php +++ b/phpBB/language/en/cli.php @@ -85,5 +85,5 @@ $lang = array_merge($lang, array( 'CLI_FIXUP_RECALCULATE_EMAIL_HASH_SUCCESS' => 'Successfully recalculated all email hashes.', - 'CLI_REPARSER_REPARSE_REPARSING' => 'Reparsing %1$s with range %2$d..%3$d', + 'CLI_REPARSER_REPARSE_REPARSING' => 'Reparsing %1$s from %2$d to %3$d', )); diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 5e1993d44c..a2b8b71818 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -13,6 +13,7 @@ namespace phpbb\console\command\reparser; +use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; @@ -116,16 +117,29 @@ class reparse extends \phpbb\console\command\command $reparser = $this->reparsers[$name]; // Start at range-max if specified or at the highest ID otherwise - $id = (is_null($input->getOption('range-max'))) ? $reparser->get_max_id() : $input->getOption('range-max'); + $max = (is_null($input->getOption('range-max'))) ? $reparser->get_max_id() : $input->getOption('range-max'); $min = $input->getOption('range-min'); $size = $input->getOption('range-size'); - while ($id > $min) + + $output->writeLn($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $min, $max) . ''); + + $progress = new ProgressBar($output, $max - $min); + $progress->start(); + + // Start from $max and decrement $current by $size until we reach $min + $current = $max; + while ($current > $min) { - $start = max($min, $id + 1 - $size); - $end = $id; - $output->writeln('' . $this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $name, $start, $end) . ''); + $start = max($min, $current + 1 - $size); + $end = $current; $reparser->reparse_range($start, $end); - $id -= $size; + + $current = max($min, $start - 1); + $progress->setProgress($max - $current); } + $progress->finish(); + + // The progress bar does not seem to end with a newline so we add one manually + $output->writeLn(''); } } From c7f10ec4d455877b8df96c00f28ada0bcb84f17b Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 30 Jun 2015 09:55:23 +0200 Subject: [PATCH 5/8] [ticket/13891] Updated range description Does not count #0 as a potential record PHPBB3-13891 --- phpBB/language/en/cli.php | 2 +- phpBB/phpbb/console/command/reparser/reparse.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/phpBB/language/en/cli.php b/phpBB/language/en/cli.php index d1f229272c..b8e7d25f60 100644 --- a/phpBB/language/en/cli.php +++ b/phpBB/language/en/cli.php @@ -85,5 +85,5 @@ $lang = array_merge($lang, array( 'CLI_FIXUP_RECALCULATE_EMAIL_HASH_SUCCESS' => 'Successfully recalculated all email hashes.', - 'CLI_REPARSER_REPARSE_REPARSING' => 'Reparsing %1$s from %2$d to %3$d', + 'CLI_REPARSER_REPARSE_REPARSING' => 'Reparsing %1$s (range %2$d..%3$d)', )); diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index a2b8b71818..e922ea90e3 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -56,7 +56,7 @@ class reparse extends \phpbb\console\command\command null, InputOption::VALUE_REQUIRED, $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_MIN'), - 0 + 1 ) ->addOption( 'range-max', @@ -123,19 +123,19 @@ class reparse extends \phpbb\console\command\command $output->writeLn($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $min, $max) . ''); - $progress = new ProgressBar($output, $max - $min); + $progress = new ProgressBar($output, $max + 1 - $min); $progress->start(); // Start from $max and decrement $current by $size until we reach $min $current = $max; - while ($current > $min) + while ($current >= $min) { $start = max($min, $current + 1 - $size); - $end = $current; + $end = max($min, $current); $reparser->reparse_range($start, $end); - $current = max($min, $start - 1); - $progress->setProgress($max - $current); + $current = $start - 1; + $progress->setProgress($max + 1 - $start); } $progress->finish(); From 6b68544483fb8674949e1d3a69eae997cef6afbe Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 1 Jul 2015 15:49:32 +0200 Subject: [PATCH 6/8] [ticket/13891] Use the SymfonyStyle in the reparse command PHPBB3-13891 --- phpBB/language/en/cli.php | 1 + .../console/command/reparser/reparse.php | 39 ++++++++++++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/phpBB/language/en/cli.php b/phpBB/language/en/cli.php index b8e7d25f60..8c0d6bf6c3 100644 --- a/phpBB/language/en/cli.php +++ b/phpBB/language/en/cli.php @@ -86,4 +86,5 @@ $lang = array_merge($lang, array( '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_SUCCESS' => 'Reparsing ended with success', )); diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index e922ea90e3..2220e53193 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -13,11 +13,11 @@ namespace phpbb\console\command\reparser; -use Symfony\Component\Console\Helper\ProgressBar; 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; class reparse extends \phpbb\console\command\command { @@ -26,6 +26,11 @@ class reparse extends \phpbb\console\command\command */ protected $reparsers; + /** + * @var SymfonyStyle + */ + protected $io; + /** * Constructor * @@ -83,6 +88,8 @@ class reparse extends \phpbb\console\command\command */ protected function execute(InputInterface $input, OutputInterface $output) { + $this->io = new SymfonyStyle($input, $output); + $name = $input->getArgument('reparser-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; } @@ -121,9 +130,28 @@ class reparse extends \phpbb\console\command\command $min = $input->getOption('range-min'); $size = $input->getOption('range-size'); - $output->writeLn($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $min, $max) . ''); + 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(); // 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); $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); $current = $start - 1; @@ -139,7 +169,6 @@ class reparse extends \phpbb\console\command\command } $progress->finish(); - // The progress bar does not seem to end with a newline so we add one manually - $output->writeLn(''); + $this->io->newLine(2); } } From dd131d74390a8c8766c28734efebede681e3b794 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 2 Jul 2015 12:22:51 +0200 Subject: [PATCH 7/8] [ticket/13891] Added elapsed/estimated time and memory to the progress bar Also fixed some extra whitespace. PHPBB3-13891 --- phpBB/phpbb/console/command/reparser/reparse.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 2220e53193..3aac0e3e93 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -27,8 +27,8 @@ class reparse extends \phpbb\console\command\command protected $reparsers; /** - * @var SymfonyStyle - */ + * @var SymfonyStyle + */ protected $io; /** @@ -141,7 +141,7 @@ class reparse extends \phpbb\console\command\command $progress = $this->io->createProgressBar($max); $progress->setFormat( " %current:s%/%max:s% %bar% %percent:3s%%\n" . - " %message%\n"); + " %message% %elapsed:6s%/%estimated:-6s% %memory:6s%\n"); $progress->setBarWidth(60); $progress->setMessage(''); From 5970d0360c5b60a5af7bbaef37ffb8bb9932f8a8 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 2 Jul 2015 13:40:02 +0200 Subject: [PATCH 8/8] [ticket/13891] Handle verbosity PHPBB3-13891 --- phpBB/language/en/cli.php | 5 ++-- .../console/command/reparser/reparse.php | 26 ++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/phpBB/language/en/cli.php b/phpBB/language/en/cli.php index 8c0d6bf6c3..9eca60fb68 100644 --- a/phpBB/language/en/cli.php +++ b/phpBB/language/en/cli.php @@ -85,6 +85,7 @@ $lang = array_merge($lang, array( '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_SUCCESS' => 'Reparsing ended with success', + 'CLI_REPARSER_REPARSE_REPARSING' => 'Reparsing %1$s (range %2$d..%3$d)', + 'CLI_REPARSER_REPARSE_REPARSING_START' => 'Reparsing %s...', + 'CLI_REPARSER_REPARSE_SUCCESS' => 'Reparsing ended with success', )); diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 3aac0e3e93..c261507a57 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -136,14 +136,28 @@ class reparse extends \phpbb\console\command\command } $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% %elapsed:6s%/%estimated:-6s% %memory:6s%\n"); - $progress->setBarWidth(60); - $progress->setMessage(''); + if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) + { + $progress->setFormat('[%percent:3s%%] %message%'); + $progress->setOverwrite(false); + } + elseif ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) + { + $progress->setFormat('[%current:s%/%max:s%][%elapsed%/%estimated%][%memory%] %message%'); + $progress->setOverwrite(false); + } + else + { + $this->io->newLine(2); + $progress->setFormat( + " %current:s%/%max:s% %bar% %percent:3s%%\n" . + " %message% %elapsed:6s%/%estimated:-6s% %memory:6s%\n"); + $progress->setBarWidth(60); + } + + $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', str_replace('text_reparser.', '', $name))); if (!defined('PHP_WINDOWS_VERSION_BUILD')) {