[ticket/13891] Added command-line options

PHPBB3-13891
This commit is contained in:
JoshyPHP 2015-06-29 23:05:52 +02:00
parent 119f90e363
commit fadb192c57
2 changed files with 37 additions and 9 deletions

View file

@ -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_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' => '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_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_RECALCULATE_EMAIL_HASH' => 'Recalculates the user_email_hash column of the users table.',
'CLI_DESCRIPTION_SET_ATOMIC_CONFIG' => 'Sets a configuration options value only if the old matches the current value', 'CLI_DESCRIPTION_SET_ATOMIC_CONFIG' => 'Sets a configuration options value only if the old matches the current value',
'CLI_DESCRIPTION_SET_CONFIG' => 'Sets a configuration options value', 'CLI_DESCRIPTION_SET_CONFIG' => 'Sets a configuration options value',

View file

@ -15,6 +15,7 @@ namespace phpbb\console\command\reparser;
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\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
class reparse extends \phpbb\console\command\command class reparse extends \phpbb\console\command\command
@ -49,6 +50,26 @@ class reparse extends \phpbb\console\command\command
->setName('reparser:reparse') ->setName('reparser:reparse')
->setDescription($this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE')) ->setDescription($this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE'))
->addArgument('reparser-name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_ARG_1')) ->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; $name = 'text_reparser.' . $name;
} }
$this->reparse($output, $name); $this->reparse($input, $output, $name);
} }
else else
{ {
foreach ($this->reparsers as $name => $service) 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 OutputInterface $output
* @param string $name Reparser name * @param string $name Reparser name
* @return null * @return null
*/ */
protected function reparse(OutputInterface $output, $name) protected function reparse(InputInterface $input, OutputInterface $output, $name)
{ {
$reparser = $this->reparsers[$name]; $reparser = $this->reparsers[$name];
$id = $reparser->get_max_id();
$n = 100; // Start at range-max if specified or at the highest ID otherwise
while ($id > 0) $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; $end = $id;
$output->writeln('<info>' . $this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $name, $start, $end) . '</info>'); $output->writeln('<info>' . $this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $name, $start, $end) . '</info>');
$reparser->reparse_range($start, $end); $reparser->reparse_range($start, $end);
$id -= $n; $id -= $size;
} }
} }
} }