From 615ab099e228f2d7a35a76557095a65321425963 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 29 May 2015 19:33:17 +0200 Subject: [ticket/13891] Added reparser:list and reparser:reparse to CLI PHPBB3-13891 --- phpBB/phpbb/console/command/reparser/list_all.php | 70 ++++++++++++++ phpBB/phpbb/console/command/reparser/reparse.php | 106 ++++++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 phpBB/phpbb/console/command/reparser/list_all.php create mode 100644 phpBB/phpbb/console/command/reparser/reparse.php (limited to 'phpBB/phpbb/console/command/reparser') 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; + } + } +} -- cgit v1.2.1 From 119f90e36301463ffd01005a9390d3346be7774f Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 29 Jun 2015 22:15:08 +0200 Subject: [ticket/13891] Replaced ContainerBuilder with service_collection PHPBB3-13891 --- phpBB/phpbb/console/command/reparser/list_all.php | 7 +++---- phpBB/phpbb/console/command/reparser/reparse.php | 16 ++++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') 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) -- cgit v1.2.1 From fadb192c570db25fe4b36b1b3803fb923e6f9d4e Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 29 Jun 2015 23:05:52 +0200 Subject: [ticket/13891] Added command-line options PHPBB3-13891 --- phpBB/phpbb/console/command/reparser/reparse.php | 43 +++++++++++++++++++----- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') 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; } } } -- cgit v1.2.1 From 6de5e5cc36d4b934cfa4043faf12adb279f8a2c6 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 30 Jun 2015 00:28:02 +0200 Subject: [ticket/13891] Added a progress bar PHPBB3-13891 --- phpBB/phpbb/console/command/reparser/reparse.php | 26 ++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') 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(''); } } -- cgit v1.2.1 From c7f10ec4d455877b8df96c00f28ada0bcb84f17b Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 30 Jun 2015 09:55:23 +0200 Subject: [ticket/13891] Updated range description Does not count #0 as a potential record PHPBB3-13891 --- phpBB/phpbb/console/command/reparser/reparse.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') 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(); -- cgit v1.2.1 From 6b68544483fb8674949e1d3a69eae997cef6afbe Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 1 Jul 2015 15:49:32 +0200 Subject: [ticket/13891] Use the SymfonyStyle in the reparse command PHPBB3-13891 --- phpBB/phpbb/console/command/reparser/reparse.php | 39 +++++++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') 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); } } -- cgit v1.2.1 From dd131d74390a8c8766c28734efebede681e3b794 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 2 Jul 2015 12:22:51 +0200 Subject: [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(-) (limited to 'phpBB/phpbb/console/command/reparser') 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(''); -- cgit v1.2.1 From 5970d0360c5b60a5af7bbaef37ffb8bb9932f8a8 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 2 Jul 2015 13:40:02 +0200 Subject: [ticket/13891] Handle verbosity PHPBB3-13891 --- phpBB/phpbb/console/command/reparser/reparse.php | 26 ++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') 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')) { -- cgit v1.2.1 From b251d9831476754d6db4f0314cbc7607c57d7128 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 2 Jul 2015 15:26:49 +0200 Subject: [ticket/13891] Fix CS PHPBB3-13891 --- phpBB/phpbb/console/command/reparser/reparse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command/reparser') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index c261507a57..52075dd0ac 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -143,7 +143,7 @@ class reparse extends \phpbb\console\command\command $progress->setFormat('[%percent:3s%%] %message%'); $progress->setOverwrite(false); } - elseif ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) + else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) { $progress->setFormat('[%current:s%/%max:s%][%elapsed%/%estimated%][%memory%] %message%'); $progress->setOverwrite(false); -- cgit v1.2.1 From 7ccb6389124c5e990abaa917a6684fc3f4d072db Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 6 Jul 2015 01:43:43 +0200 Subject: [ticket/13987] Add --dry-run option to reparser CLI PHPBB3-13987 --- phpBB/phpbb/console/command/reparser/reparse.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 52075dd0ac..8352c523de 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -56,6 +56,12 @@ 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( + 'dry-run', + null, + InputOption::VALUE_NONE, + $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_DRY_RUN') + ) ->addOption( 'range-min', null, @@ -126,9 +132,10 @@ class reparse extends \phpbb\console\command\command $reparser = $this->reparsers[$name]; // Start at range-max if specified or at the highest ID otherwise - $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'); + $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'); + $dry_run = $input->getOption('dry-run'); if ($max === 0) { @@ -176,7 +183,7 @@ class reparse extends \phpbb\console\command\command $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, $dry_run); $current = $start - 1; $progress->setProgress($max + 1 - $start); -- cgit v1.2.1 From cf4cdcda586a2371aa92ae452951f9660737ae09 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 6 Jul 2015 01:57:54 +0200 Subject: [ticket/13987] Replaced optional parameter with explicit API Added disable_save() and enable_save() to toggle a dry run PHPBB3-13987 --- phpBB/phpbb/console/command/reparser/reparse.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 8352c523de..151e196358 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -130,12 +130,19 @@ class reparse extends \phpbb\console\command\command protected function reparse(InputInterface $input, OutputInterface $output, $name) { $reparser = $this->reparsers[$name]; + if ($input->getOption('dry-run')) + { + $reparser->disable_save(); + } + else + { + $reparser->enable_save(); + } // Start at range-max if specified or at the highest ID otherwise - $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'); - $dry_run = $input->getOption('dry-run'); + $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'); if ($max === 0) { @@ -183,7 +190,7 @@ class reparse extends \phpbb\console\command\command $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, $dry_run); + $reparser->reparse_range($start, $end); $current = $start - 1; $progress->setProgress($max + 1 - $start); -- cgit v1.2.1 From af7872473d41b4fd82a850e87f9e74a72a5b3230 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 16 Jul 2015 22:52:25 -0700 Subject: [ticket/14033] Fix errors in docblocks PHPBB3-14033 --- phpBB/phpbb/console/command/reparser/reparse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command/reparser') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 151e196358..a58bf20193 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -35,7 +35,7 @@ class reparse extends \phpbb\console\command\command * Constructor * * @param \phpbb\user $user - * @param \phpbb\di\service_collection $reparser_collection + * @param \phpbb\di\service_collection $reparsers */ public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers) { -- cgit v1.2.1 From e7763cd273a88e4b99c67e2a74b83ed3ef86727f Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 17 Jul 2015 08:26:14 +0200 Subject: [ticket/14034] Fix reparser names that contain "text_reparser" in the middle PHPBB3-14034 --- phpBB/phpbb/console/command/reparser/list_all.php | 2 +- phpBB/phpbb/console/command/reparser/reparse.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') diff --git a/phpBB/phpbb/console/command/reparser/list_all.php b/phpBB/phpbb/console/command/reparser/list_all.php index 1589836ddd..e42c3ac782 100644 --- a/phpBB/phpbb/console/command/reparser/list_all.php +++ b/phpBB/phpbb/console/command/reparser/list_all.php @@ -36,7 +36,7 @@ class list_all extends \phpbb\console\command\command foreach ($reparsers as $name => $reparser) { // Store the names without the "text_reparser." prefix - $this->reparser_names[] = str_replace('text_reparser.', '', $name); + $this->reparser_names[] = preg_replace('(^text_reparser\\.)', '', $name); } } diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 151e196358..81d1aa0421 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -149,7 +149,7 @@ class reparse extends \phpbb\console\command\command return; } - $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $min, $max)); + $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', preg_replace('(^text_reparser\\.)', '', $name), $min, $max)); $progress = $this->io->createProgressBar($max); if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) @@ -171,7 +171,7 @@ class reparse extends \phpbb\console\command\command $progress->setBarWidth(60); } - $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', str_replace('text_reparser.', '', $name))); + $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', preg_replace('(^text_reparser\\.)', '', $name))); if (!defined('PHP_WINDOWS_VERSION_BUILD')) { @@ -189,7 +189,7 @@ 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)); + $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', preg_replace('(^text_reparser\\.)', '', $name), $start, $end)); $reparser->reparse_range($start, $end); $current = $start - 1; -- cgit v1.2.1 From 903f100c5120ad516e248ee30b18dd9a64468656 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 17 Jul 2015 11:53:28 +0200 Subject: [ticket/13986] Add --resume option to reparser CLI PHPBB3-13986 --- phpBB/phpbb/console/command/reparser/reparse.php | 185 ++++++++++++++++++----- 1 file changed, 144 insertions(+), 41 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 50d4bd01d6..44a4691981 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -22,25 +22,47 @@ use Symfony\Component\Console\Style\SymfonyStyle; class reparse extends \phpbb\console\command\command { /** - * @var \phpbb\di\service_collection + * @var \phpbb\config\db_text */ - protected $reparsers; + protected $config_text; + + /** + * @var InputInterface + */ + protected $input; /** * @var SymfonyStyle */ protected $io; + /** + * @var OutputInterface + */ + protected $output; + + /** + * @var \phpbb\di\service_collection + */ + protected $reparsers; + + /** + * @var array Reparser names as keys, and their last $current ID as values + */ + protected $resume_data; + /** * Constructor * * @param \phpbb\user $user * @param \phpbb\di\service_collection $reparsers + * @param \phpbb\config\db_text $config_text */ - public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers) + public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers, \phpbb\config\db_text $config_text) { require_once __DIR__ . '/../../../../includes/functions_content.php'; + $this->config_text = $config_text; $this->reparsers = $reparsers; parent::__construct($user); } @@ -62,6 +84,12 @@ class reparse extends \phpbb\console\command\command InputOption::VALUE_NONE, $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_DRY_RUN') ) + ->addOption( + 'resume', + null, + InputOption::VALUE_NONE, + $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RESUME') + ) ->addOption( 'range-min', null, @@ -85,6 +113,44 @@ class reparse extends \phpbb\console\command\command ; } + /** + * Create a styled progress bar + * + * @param integer $max Max value for the progress bar + * @return \Symfony\Component\Console\Helper\ProgressBar + */ + protected function create_progress_bar($max) + { + $progress = $this->io->createProgressBar($max); + if ($this->output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) + { + $progress->setFormat('[%percent:3s%%] %message%'); + $progress->setOverwrite(false); + } + else if ($this->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); + } + + if (!defined('PHP_WINDOWS_VERSION_BUILD')) + { + $progress->setEmptyBarCharacter('░'); // light shade character \u2591 + $progress->setProgressCharacter(''); + $progress->setBarCharacter('▓'); // dark shade character \u2593 + } + + return $progress; + } + /** * Executes the command reparser:reparse * @@ -94,7 +160,10 @@ class reparse extends \phpbb\console\command\command */ protected function execute(InputInterface $input, OutputInterface $output) { + $this->input = $input; + $this->output = $output; $this->io = new SymfonyStyle($input, $output); + $this->load_resume_data(); $name = $input->getArgument('reparser-name'); if (isset($name)) @@ -104,13 +173,13 @@ class reparse extends \phpbb\console\command\command { $name = 'text_reparser.' . $name; } - $this->reparse($input, $output, $name); + $this->reparse($name); } else { foreach ($this->reparsers as $name => $service) { - $this->reparse($input, $output, $name); + $this->reparse($name); } } @@ -119,18 +188,53 @@ class reparse extends \phpbb\console\command\command return 0; } + /** + * Get an option value, adjusted for given reparser + * + * Will use the last saved value if --resume is set and the option was not specified + * on the command line + * + * @param string $reparser_name Reparser name + * @param string $option_name Option name + * @return integer + */ + protected function get_option($reparser_name, $option_name) + { + // Return the option from the resume_data if applicable + if ($this->input->getOption('resume') && isset($this->resume_data[$reparser_name][$option_name]) && !$this->input->hasParameterOption('--' . $option_name)) + { + return $this->resume_data[$reparser_name][$option_name]; + } + + $value = $this->input->getOption($option_name); + + // range-max has no default value, it must be computed for each reparser + if ($option_name === 'range-max' && $value === null) + { + $value = $this->reparsers[$reparser_name]->get_max_id(); + } + + return $value; + } + + /** + * Load the resume data from the database + */ + protected function load_resume_data() + { + $resume_data = $this->config_text->get('reparser_resume'); + $this->resume_data = (empty($resume_data)) ? array() : unserialize($resume_data); + } + /** * 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(InputInterface $input, OutputInterface $output, $name) + protected function reparse($name) { $reparser = $this->reparsers[$name]; - if ($input->getOption('dry-run')) + if ($this->input->getOption('dry-run')) { $reparser->disable_save(); } @@ -140,9 +244,9 @@ class reparse extends \phpbb\console\command\command } // Start at range-max if specified or at the highest ID otherwise - $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'); + $max = $this->get_option($name, 'range-max'); + $min = $this->get_option($name, 'range-min'); + $size = $this->get_option($name, 'range-size'); if ($max === 0) { @@ -151,35 +255,8 @@ class reparse extends \phpbb\console\command\command $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', preg_replace('(^text_reparser\\.)', '', $name), $min, $max)); - $progress = $this->io->createProgressBar($max); - if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) - { - $progress->setFormat('[%percent:3s%%] %message%'); - $progress->setOverwrite(false); - } - else if ($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 = $this->create_progress_bar($max); $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', preg_replace('(^text_reparser\\.)', '', $name))); - - if (!defined('PHP_WINDOWS_VERSION_BUILD')) - { - $progress->setEmptyBarCharacter('░'); // light shade character \u2591 - $progress->setProgressCharacter(''); - $progress->setBarCharacter('▓'); // dark shade character \u2593 - } - $progress->start(); // Start from $max and decrement $current by $size until we reach $min @@ -194,9 +271,35 @@ class reparse extends \phpbb\console\command\command $current = $start - 1; $progress->setProgress($max + 1 - $start); + + $this->update_resume_data($name, $current); } $progress->finish(); $this->io->newLine(2); } + + /** + * Save the resume data to the database + */ + protected function save_resume_data() + { + $this->config_text->set('reparser_resume', serialize($this->resume_data)); + } + + /** + * Save the resume data to the database + * + * @param string $name Reparser name + * @param string $current Current ID + */ + protected function update_resume_data($name, $current) + { + $this->resume_data[$name] = array( + 'range-min' => $this->input->getOption('range-min'), + 'range-max' => $current, + 'range-size' => $this->input->getOption('range-size'), + ); + $this->save_resume_data(); + } } -- cgit v1.2.1 From 9274bc4e3263b4aa9e278009fbc17f10985c439e Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 17 Jul 2015 14:00:47 +0200 Subject: [ticket/13986] Fixed resume data to carry through multiple runs Options restored from a previous execution should carry to the next resumed execution PHPBB3-13986 --- phpBB/phpbb/console/command/reparser/reparse.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 44a4691981..f81ebfa8ca 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -296,9 +296,9 @@ class reparse extends \phpbb\console\command\command protected function update_resume_data($name, $current) { $this->resume_data[$name] = array( - 'range-min' => $this->input->getOption('range-min'), + 'range-min' => $this->get_option($name, 'range-min'), 'range-max' => $current, - 'range-size' => $this->input->getOption('range-size'), + 'range-size' => $this->get_option($name, 'range-size'), ); $this->save_resume_data(); } -- cgit v1.2.1 From c8e209a2dee7548031b4d2b5137c2ef064d6f588 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 17 Jul 2015 16:52:52 +0200 Subject: [ticket/13986] Replaced hardcoded value PHPBB3-13986 --- phpBB/phpbb/console/command/reparser/reparse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command/reparser') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index f81ebfa8ca..63124b4b8c 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -248,7 +248,7 @@ class reparse extends \phpbb\console\command\command $min = $this->get_option($name, 'range-min'); $size = $this->get_option($name, 'range-size'); - if ($max === 0) + if ($max < $min) { return; } -- cgit v1.2.1 From c7ecb1310f7663e5fdaafb655381663b9410c31a Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Sat, 24 Oct 2015 20:10:16 +0200 Subject: [ticket/14257] Add reparse_lock to CLI command PHPBB3-14257 --- phpBB/phpbb/console/command/reparser/reparse.php | 50 ++++++++++++++++-------- 1 file changed, 34 insertions(+), 16 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 63124b4b8c..e77b384d8e 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 phpbb\exception\runtime_exception; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; @@ -41,6 +42,11 @@ class reparse extends \phpbb\console\command\command */ protected $output; + /** + * @var \phpbb\lock\db + */ + protected $reparse_lock; + /** * @var \phpbb\di\service_collection */ @@ -57,13 +63,15 @@ class reparse extends \phpbb\console\command\command * @param \phpbb\user $user * @param \phpbb\di\service_collection $reparsers * @param \phpbb\config\db_text $config_text + * @param \phpbb\lock\db $reparse_lock */ - public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers, \phpbb\config\db_text $config_text) + public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers, \phpbb\config\db_text $config_text, \phpbb\lock\db $reparse_lock) { require_once __DIR__ . '/../../../../includes/functions_content.php'; $this->config_text = $config_text; $this->reparsers = $reparsers; + $this->reparse_lock = $reparse_lock; parent::__construct($user); } @@ -163,29 +171,39 @@ class reparse extends \phpbb\console\command\command $this->input = $input; $this->output = $output; $this->io = new SymfonyStyle($input, $output); - $this->load_resume_data(); - $name = $input->getArgument('reparser-name'); - if (isset($name)) + if (!$this->reparse_lock->acquire()) { - // Allow "post_text" to be an alias for "text_reparser.post_text" - if (!isset($this->reparsers[$name])) + $this->load_resume_data(); + + $name = $input->getArgument('reparser-name'); + if (isset($name)) { - $name = 'text_reparser.' . $name; + // Allow "post_text" to be an alias for "text_reparser.post_text" + if (!isset($this->reparsers[$name])) + { + $name = 'text_reparser.' . $name; + } + $this->reparse($name); } - $this->reparse($name); - } - else - { - foreach ($this->reparsers as $name => $service) + else { - $this->reparse($name); + foreach ($this->reparsers as $name => $service) + { + $this->reparse($name); + } } - } - $this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS')); + $this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS')); - return 0; + $this->reparse_lock->release(); + + return 0; + } + else + { + throw new runtime_exception('REPARSE_LOCK_ERROR', array(), null, 1); + } } /** -- cgit v1.2.1 From 8b0f8d7b3cf7e7687f11c2fc0a15d4919c91b6c1 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Sun, 25 Oct 2015 02:31:22 +0200 Subject: [ticket/14257] Fix lock acquire in CLI command PHPBB3-14257 --- phpBB/phpbb/console/command/reparser/reparse.php | 42 +++++++++++------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index e77b384d8e..6fac3db854 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -174,36 +174,34 @@ class reparse extends \phpbb\console\command\command if (!$this->reparse_lock->acquire()) { - $this->load_resume_data(); + throw new runtime_exception('REPARSE_LOCK_ERROR', array(), null, 1); + } - $name = $input->getArgument('reparser-name'); - if (isset($name)) + $this->load_resume_data(); + + $name = $input->getArgument('reparser-name'); + if (isset($name)) + { + // Allow "post_text" to be an alias for "text_reparser.post_text" + if (!isset($this->reparsers[$name])) { - // Allow "post_text" to be an alias for "text_reparser.post_text" - if (!isset($this->reparsers[$name])) - { - $name = 'text_reparser.' . $name; - } - $this->reparse($name); + $name = 'text_reparser.' . $name; } - else + $this->reparse($name); + } + else + { + foreach ($this->reparsers as $name => $service) { - foreach ($this->reparsers as $name => $service) - { - $this->reparse($name); - } + $this->reparse($name); } + } - $this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS')); + $this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS')); - $this->reparse_lock->release(); + $this->reparse_lock->release(); - return 0; - } - else - { - throw new runtime_exception('REPARSE_LOCK_ERROR', array(), null, 1); - } + return 0; } /** -- cgit v1.2.1 From 25e2b17837f5b1c2330d07a86f88b25bb55d96c1 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Mon, 26 Oct 2015 01:39:52 +0100 Subject: [ticket/14257] Add text_reparser manager PHPBB3-14257 --- phpBB/phpbb/console/command/reparser/reparse.php | 54 +++++------------------- 1 file changed, 10 insertions(+), 44 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 6fac3db854..575e447a78 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -22,11 +22,6 @@ use Symfony\Component\Console\Style\SymfonyStyle; class reparse extends \phpbb\console\command\command { - /** - * @var \phpbb\config\db_text - */ - protected $config_text; - /** * @var InputInterface */ @@ -47,6 +42,11 @@ class reparse extends \phpbb\console\command\command */ protected $reparse_lock; + /** + * @var \phpbb\textreparser\manager + */ + protected $reparser_manager; + /** * @var \phpbb\di\service_collection */ @@ -65,13 +65,13 @@ class reparse extends \phpbb\console\command\command * @param \phpbb\config\db_text $config_text * @param \phpbb\lock\db $reparse_lock */ - public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers, \phpbb\config\db_text $config_text, \phpbb\lock\db $reparse_lock) + public function __construct(\phpbb\user $user, \phpbb\lock\db $reparse_lock, \phpbb\textreparser\manager $reparser_manager, \phpbb\di\service_collection $reparsers) { require_once __DIR__ . '/../../../../includes/functions_content.php'; - $this->config_text = $config_text; - $this->reparsers = $reparsers; $this->reparse_lock = $reparse_lock; + $this->reparser_manager = $reparser_manager; + $this->reparsers = $reparsers; parent::__construct($user); } @@ -177,8 +177,6 @@ class reparse extends \phpbb\console\command\command throw new runtime_exception('REPARSE_LOCK_ERROR', array(), null, 1); } - $this->load_resume_data(); - $name = $input->getArgument('reparser-name'); if (isset($name)) { @@ -233,15 +231,6 @@ class reparse extends \phpbb\console\command\command return $value; } - /** - * Load the resume data from the database - */ - protected function load_resume_data() - { - $resume_data = $this->config_text->get('reparser_resume'); - $this->resume_data = (empty($resume_data)) ? array() : unserialize($resume_data); - } - /** * Reparse all text handled by given reparser within given range * @@ -250,6 +239,7 @@ class reparse extends \phpbb\console\command\command protected function reparse($name) { $reparser = $this->reparsers[$name]; + $this->resume_data = $this->reparser_manager->get_resume_data($name); if ($this->input->getOption('dry-run')) { $reparser->disable_save(); @@ -288,34 +278,10 @@ class reparse extends \phpbb\console\command\command $current = $start - 1; $progress->setProgress($max + 1 - $start); - $this->update_resume_data($name, $current); + $this->reparser_manager->update_resume_data($name, $min, $current, $size, !$this->input->getOption('dry-run')); } $progress->finish(); $this->io->newLine(2); } - - /** - * Save the resume data to the database - */ - protected function save_resume_data() - { - $this->config_text->set('reparser_resume', serialize($this->resume_data)); - } - - /** - * Save the resume data to the database - * - * @param string $name Reparser name - * @param string $current Current ID - */ - protected function update_resume_data($name, $current) - { - $this->resume_data[$name] = array( - 'range-min' => $this->get_option($name, 'range-min'), - 'range-max' => $current, - 'range-size' => $this->get_option($name, 'range-size'), - ); - $this->save_resume_data(); - } } -- cgit v1.2.1 From c805fd2a7378bc431ff11f93efd74fb829f558d9 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Mon, 26 Oct 2015 01:49:11 +0100 Subject: [ticket/14257] Fix phpdoc in CLI command PHPBB3-14257 --- phpBB/phpbb/console/command/reparser/reparse.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 575e447a78..6137a79b89 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -61,9 +61,9 @@ class reparse extends \phpbb\console\command\command * Constructor * * @param \phpbb\user $user - * @param \phpbb\di\service_collection $reparsers - * @param \phpbb\config\db_text $config_text * @param \phpbb\lock\db $reparse_lock + * @param \phpbb\textreparser\manager $reparser_manager + * @param \phpbb\di\service_collection $reparsers */ public function __construct(\phpbb\user $user, \phpbb\lock\db $reparse_lock, \phpbb\textreparser\manager $reparser_manager, \phpbb\di\service_collection $reparsers) { -- cgit v1.2.1 From 900ccd79af816d8d54e6974e9163d9999a823513 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Sun, 1 Nov 2015 03:49:01 +0100 Subject: [ticket/14257] Fix CLI reparser and set cron interval PHPBB3-14257 --- phpBB/phpbb/console/command/reparser/reparse.php | 31 +++++++++++------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 6137a79b89..ddc97a1d1d 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -53,7 +53,7 @@ class reparse extends \phpbb\console\command\command protected $reparsers; /** - * @var array Reparser names as keys, and their last $current ID as values + * @var array The reparser's last $current ID as values */ protected $resume_data; @@ -208,27 +208,18 @@ class reparse extends \phpbb\console\command\command * Will use the last saved value if --resume is set and the option was not specified * on the command line * - * @param string $reparser_name Reparser name * @param string $option_name Option name * @return integer */ - protected function get_option($reparser_name, $option_name) + protected function get_option($option_name) { // Return the option from the resume_data if applicable - if ($this->input->getOption('resume') && isset($this->resume_data[$reparser_name][$option_name]) && !$this->input->hasParameterOption('--' . $option_name)) + if ($this->input->getOption('resume') && isset($this->resume_data[$option_name]) && !$this->input->hasParameterOption('--' . $option_name)) { - return $this->resume_data[$reparser_name][$option_name]; + return $this->resume_data[$option_name]; } - $value = $this->input->getOption($option_name); - - // range-max has no default value, it must be computed for each reparser - if ($option_name === 'range-max' && $value === null) - { - $value = $this->reparsers[$reparser_name]->get_max_id(); - } - - return $value; + return $this->input->getOption($option_name); } /** @@ -250,9 +241,15 @@ class reparse extends \phpbb\console\command\command } // Start at range-max if specified or at the highest ID otherwise - $max = $this->get_option($name, 'range-max'); - $min = $this->get_option($name, 'range-min'); - $size = $this->get_option($name, 'range-size'); + $max = $this->get_option('range-max'); + $min = $this->get_option('range-min'); + $size = $this->get_option('range-size'); + + // range-max has no default value, it must be computed for each reparser + if ($max == null) + { + $max = $reparser->get_max_id(); + } if ($max < $min) { -- cgit v1.2.1 From d713ce94ff218c2464823cb23dae1007354c60f3 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 12 Apr 2016 10:56:23 -0700 Subject: [ticket/14569] Extract CLI progress bar creation to a method PHPBB3-14569 --- phpBB/phpbb/console/command/reparser/reparse.php | 40 +----------------------- 1 file changed, 1 insertion(+), 39 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index ddc97a1d1d..b10bd56a58 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -121,44 +121,6 @@ class reparse extends \phpbb\console\command\command ; } - /** - * Create a styled progress bar - * - * @param integer $max Max value for the progress bar - * @return \Symfony\Component\Console\Helper\ProgressBar - */ - protected function create_progress_bar($max) - { - $progress = $this->io->createProgressBar($max); - if ($this->output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) - { - $progress->setFormat('[%percent:3s%%] %message%'); - $progress->setOverwrite(false); - } - else if ($this->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); - } - - if (!defined('PHP_WINDOWS_VERSION_BUILD')) - { - $progress->setEmptyBarCharacter('░'); // light shade character \u2591 - $progress->setProgressCharacter(''); - $progress->setBarCharacter('▓'); // dark shade character \u2593 - } - - return $progress; - } - /** * Executes the command reparser:reparse * @@ -258,7 +220,7 @@ class reparse extends \phpbb\console\command\command $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', preg_replace('(^text_reparser\\.)', '', $name), $min, $max)); - $progress = $this->create_progress_bar($max); + $progress = $this->create_progress_bar($max, $this->io, $this->output, true); $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', preg_replace('(^text_reparser\\.)', '', $name))); $progress->start(); -- cgit v1.2.1 From d90afa67d866e1be44d3a69c97497c8412695f8d Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 9 Oct 2016 21:37:30 +0200 Subject: [ticket/14814] Fix reparser cron PHPBB3-14814 --- phpBB/phpbb/console/command/reparser/reparse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command/reparser') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index b10bd56a58..cebeee0919 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -208,7 +208,7 @@ class reparse extends \phpbb\console\command\command $size = $this->get_option('range-size'); // range-max has no default value, it must be computed for each reparser - if ($max == null) + if ($max === null) { $max = $reparser->get_max_id(); } -- cgit v1.2.1 From 74cd513a8892285032a248322e3ce52b19645075 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 7 Dec 2016 10:13:09 -0800 Subject: [ticket/14895] CLI reparser:list should display proper list PHPBB3-14895 --- phpBB/phpbb/console/command/reparser/list_all.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') diff --git a/phpBB/phpbb/console/command/reparser/list_all.php b/phpBB/phpbb/console/command/reparser/list_all.php index e42c3ac782..7dd0571975 100644 --- a/phpBB/phpbb/console/command/reparser/list_all.php +++ b/phpBB/phpbb/console/command/reparser/list_all.php @@ -54,7 +54,7 @@ class list_all extends \phpbb\console\command\command } /** - * Executes the command reparser:reparse + * Executes the command reparser:list * * @param InputInterface $input * @param OutputInterface $output @@ -62,7 +62,11 @@ class list_all extends \phpbb\console\command\command */ protected function execute(InputInterface $input, OutputInterface $output) { - $output->writeln('' . implode(', ', $this->reparser_names) . ''); + $output->writeln('' . $this->user->lang('CLI_DESCRIPTION_REPARSER_AVAILABLE') . ''); + foreach ($this->reparser_names as $reparser_name) + { + $output->writeln($reparser_name); + } return 0; } -- cgit v1.2.1 From d275fefc69bae24f547802d824607c9a054ff6d2 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 7 Dec 2016 23:49:54 -0800 Subject: [ticket/14895] Use SymfonyIO styling PHPBB3-14895 --- phpBB/phpbb/console/command/reparser/list_all.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') diff --git a/phpBB/phpbb/console/command/reparser/list_all.php b/phpBB/phpbb/console/command/reparser/list_all.php index 7dd0571975..028468649d 100644 --- a/phpBB/phpbb/console/command/reparser/list_all.php +++ b/phpBB/phpbb/console/command/reparser/list_all.php @@ -15,6 +15,7 @@ namespace phpbb\console\command\reparser; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class list_all extends \phpbb\console\command\command { @@ -62,11 +63,9 @@ class list_all extends \phpbb\console\command\command */ protected function execute(InputInterface $input, OutputInterface $output) { - $output->writeln('' . $this->user->lang('CLI_DESCRIPTION_REPARSER_AVAILABLE') . ''); - foreach ($this->reparser_names as $reparser_name) - { - $output->writeln($reparser_name); - } + $io = new SymfonyStyle($input, $output); + $io->section($this->user->lang('CLI_DESCRIPTION_REPARSER_AVAILABLE')); + $io->listing($this->reparser_names); return 0; } -- cgit v1.2.1 From b4748a5d1ee31084da7e78f8ffaf5b036f2e5314 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 18 Dec 2016 01:28:51 -0800 Subject: [ticket/14925] Set reparser names in service definitions PHPBB3-14925 --- phpBB/phpbb/console/command/reparser/list_all.php | 4 ++-- phpBB/phpbb/console/command/reparser/reparse.php | 16 ++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) (limited to 'phpBB/phpbb/console/command/reparser') diff --git a/phpBB/phpbb/console/command/reparser/list_all.php b/phpBB/phpbb/console/command/reparser/list_all.php index 028468649d..a79578abf0 100644 --- a/phpBB/phpbb/console/command/reparser/list_all.php +++ b/phpBB/phpbb/console/command/reparser/list_all.php @@ -34,10 +34,10 @@ class list_all extends \phpbb\console\command\command { parent::__construct($user); $this->reparser_names = array(); - foreach ($reparsers as $name => $reparser) + foreach ($reparsers as $reparser) { // Store the names without the "text_reparser." prefix - $this->reparser_names[] = preg_replace('(^text_reparser\\.)', '', $name); + $this->reparser_names[] = $reparser->get_name(); } } diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index cebeee0919..f285977ea2 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -140,13 +140,9 @@ class reparse extends \phpbb\console\command\command } $name = $input->getArgument('reparser-name'); - if (isset($name)) + if ($name) { - // Allow "post_text" to be an alias for "text_reparser.post_text" - if (!isset($this->reparsers[$name])) - { - $name = 'text_reparser.' . $name; - } + $name = $this->reparser_manager->find_reparser($name); $this->reparse($name); } else @@ -187,7 +183,7 @@ class reparse extends \phpbb\console\command\command /** * Reparse all text handled by given reparser within given range * - * @param string $name Reparser name + * @param string $name Reparser service name */ protected function reparse($name) { @@ -218,10 +214,10 @@ class reparse extends \phpbb\console\command\command return; } - $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', preg_replace('(^text_reparser\\.)', '', $name), $min, $max)); + $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $reparser->get_name(), $min, $max)); $progress = $this->create_progress_bar($max, $this->io, $this->output, true); - $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', preg_replace('(^text_reparser\\.)', '', $name))); + $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', $reparser->get_name())); $progress->start(); // Start from $max and decrement $current by $size until we reach $min @@ -231,7 +227,7 @@ 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', preg_replace('(^text_reparser\\.)', '', $name), $start, $end)); + $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $reparser->get_name(), $start, $end)); $reparser->reparse_range($start, $end); $current = $start - 1; -- cgit v1.2.1