aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/console/command/reparser/reparse.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/console/command/reparser/reparse.php')
-rw-r--r--phpBB/phpbb/console/command/reparser/reparse.php195
1 files changed, 149 insertions, 46 deletions
diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php
index 151e196358..63124b4b8c 100644
--- a/phpBB/phpbb/console/command/reparser/reparse.php
+++ b/phpBB/phpbb/console/command/reparser/reparse.php
@@ -22,9 +22,14 @@ 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
@@ -32,15 +37,32 @@ class reparse extends \phpbb\console\command\command
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 $reparser_collection
+ * @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);
}
@@ -63,6 +85,12 @@ class reparse extends \phpbb\console\command\command
$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,
InputOption::VALUE_REQUIRED,
@@ -86,6 +114,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('<info>[%percent:3s%%]</info> %message%');
+ $progress->setOverwrite(false);
+ }
+ else if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE)
+ {
+ $progress->setFormat('<info>[%current:s%/%max:s%]</info><comment>[%elapsed%/%estimated%][%memory%]</comment> %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
*
* @param InputInterface $input
@@ -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);
}
}
@@ -120,66 +189,74 @@ class reparse extends \phpbb\console\command\command
}
/**
- * Reparse all text handled by given reparser within given range
+ * Get an option value, adjusted for given reparser
*
- * @param InputInterface $input
- * @param OutputInterface $output
- * @param string $name Reparser name
- * @return null
+ * 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 reparse(InputInterface $input, OutputInterface $output, $name)
+ protected function get_option($reparser_name, $option_name)
{
- $reparser = $this->reparsers[$name];
- if ($input->getOption('dry-run'))
- {
- $reparser->disable_save();
- }
- else
+ // 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))
{
- $reparser->enable_save();
+ return $this->resume_data[$reparser_name][$option_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');
+ $value = $this->input->getOption($option_name);
- if ($max === 0)
+ // range-max has no default value, it must be computed for each reparser
+ if ($option_name === 'range-max' && $value === null)
{
- return;
+ $value = $this->reparsers[$reparser_name]->get_max_id();
}
- $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $min, $max));
+ return $value;
+ }
- $progress = $this->io->createProgressBar($max);
- if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE)
- {
- $progress->setFormat('<info>[%percent:3s%%]</info> %message%');
- $progress->setOverwrite(false);
- }
- else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE)
+ /**
+ * 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 string $name Reparser name
+ */
+ protected function reparse($name)
+ {
+ $reparser = $this->reparsers[$name];
+ if ($this->input->getOption('dry-run'))
{
- $progress->setFormat('<info>[%current:s%/%max:s%]</info><comment>[%elapsed%/%estimated%][%memory%]</comment> %message%');
- $progress->setOverwrite(false);
+ $reparser->disable_save();
}
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);
+ $reparser->enable_save();
}
- $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', str_replace('text_reparser.', '', $name)));
+ // 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');
- if (!defined('PHP_WINDOWS_VERSION_BUILD'))
+ if ($max < $min)
{
- $progress->setEmptyBarCharacter('░'); // light shade character \u2591
- $progress->setProgressCharacter('');
- $progress->setBarCharacter('▓'); // dark shade character \u2593
+ return;
}
+ $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', preg_replace('(^text_reparser\\.)', '', $name), $min, $max));
+
+ $progress = $this->create_progress_bar($max);
+ $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', preg_replace('(^text_reparser\\.)', '', $name)));
$progress->start();
// Start from $max and decrement $current by $size until we reach $min
@@ -189,14 +266,40 @@ 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;
$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->get_option($name, 'range-min'),
+ 'range-max' => $current,
+ 'range-size' => $this->get_option($name, 'range-size'),
+ );
+ $this->save_resume_data();
+ }
}