mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
Merge pull request #6728 from rxu/ticket/17402-master
[ticket/17402] Add CLI reparser option to force reparsing BBCode - master
This commit is contained in:
commit
072001de9c
4 changed files with 25 additions and 14 deletions
|
@ -75,6 +75,7 @@ $lang = array_merge($lang, array(
|
||||||
'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_DRY_RUN' => 'Do not save any changes; just print what would happen',
|
'CLI_DESCRIPTION_REPARSER_REPARSE_OPT_DRY_RUN' => 'Do not save any changes; just print what would happen',
|
||||||
|
'CLI_DESCRIPTION_REPARSER_REPARSE_OPT_FORCE_BBCODE' => 'Re-parse all BBCodes without exception. Note that any previously disabled BBCodes will be reprocessed, enabled, and fully rendered.',
|
||||||
'CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_MIN' => 'Lowest record ID to process',
|
'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_MAX' => 'Highest record ID to process',
|
||||||
'CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_SIZE' => 'Approximate number of records to process at a time',
|
'CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_SIZE' => 'Approximate number of records to process at a time',
|
||||||
|
|
|
@ -93,6 +93,12 @@ class reparse extends \phpbb\console\command\command
|
||||||
InputOption::VALUE_NONE,
|
InputOption::VALUE_NONE,
|
||||||
$this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_DRY_RUN')
|
$this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_DRY_RUN')
|
||||||
)
|
)
|
||||||
|
->addOption(
|
||||||
|
'force-bbcode-reparsing',
|
||||||
|
null,
|
||||||
|
InputOption::VALUE_NONE,
|
||||||
|
$this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_FORCE_BBCODE')
|
||||||
|
)
|
||||||
->addOption(
|
->addOption(
|
||||||
'resume',
|
'resume',
|
||||||
null,
|
null,
|
||||||
|
@ -223,13 +229,15 @@ class reparse extends \phpbb\console\command\command
|
||||||
|
|
||||||
// Start from $max and decrement $current by $size until we reach $min
|
// Start from $max and decrement $current by $size until we reach $min
|
||||||
$current = $max;
|
$current = $max;
|
||||||
|
|
||||||
|
$force_bbcode_reparsing = (bool) $this->get_option('force-bbcode-reparsing');
|
||||||
while ($current >= $min)
|
while ($current >= $min)
|
||||||
{
|
{
|
||||||
$start = max($min, $current + 1 - $size);
|
$start = max($min, $current + 1 - $size);
|
||||||
$end = max($min, $current);
|
$end = max($min, $current);
|
||||||
|
|
||||||
$progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $reparser->get_name(), $start, $end));
|
$progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $reparser->get_name(), $start, $end));
|
||||||
$reparser->reparse_range($start, $end);
|
$reparser->reparse_range($start, $end, $force_bbcode_reparsing);
|
||||||
|
|
||||||
$current = $start - 1;
|
$current = $start - 1;
|
||||||
$progress->setProgress($max + 1 - $start);
|
$progress->setProgress($max + 1 - $start);
|
||||||
|
|
|
@ -219,11 +219,11 @@ abstract class base implements reparser_interface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function reparse_range($min_id, $max_id)
|
public function reparse_range($min_id, $max_id, bool $force_bbcode_reparsing = false)
|
||||||
{
|
{
|
||||||
foreach ($this->get_records_by_range($min_id, $max_id) as $record)
|
foreach ($this->get_records_by_range($min_id, $max_id) as $record)
|
||||||
{
|
{
|
||||||
$this->reparse_record($record);
|
$this->reparse_record($record, $force_bbcode_reparsing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,16 +231,17 @@ abstract class base implements reparser_interface
|
||||||
* Reparse given record
|
* Reparse given record
|
||||||
*
|
*
|
||||||
* @param array $record Associative array containing the record's data
|
* @param array $record Associative array containing the record's data
|
||||||
|
* @param bool $force_bbcode_reparsing Flag indicating if BBCode should be reparsed unconditionally
|
||||||
*/
|
*/
|
||||||
protected function reparse_record(array $record)
|
protected function reparse_record(array $record, bool $force_bbcode_reparsing = false)
|
||||||
{
|
{
|
||||||
// Guess magic URL state based on actual record content before adding fields
|
// Guess magic URL state based on actual record content before adding fields
|
||||||
$record['enable_magic_url'] = $this->guess_magic_url($record);
|
$record['enable_magic_url'] = $this->guess_magic_url($record);
|
||||||
$record = $this->add_missing_fields($record);
|
$record = $this->add_missing_fields($record);
|
||||||
|
|
||||||
$flags = ($record['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0;
|
$flags = ($record['enable_bbcode'] || $force_bbcode_reparsing) ? OPTION_FLAG_BBCODE : 0;
|
||||||
$flags |= ($record['enable_smilies']) ? OPTION_FLAG_SMILIES : 0;
|
$flags |= ($record['enable_smilies'] || $force_bbcode_reparsing) ? OPTION_FLAG_SMILIES : 0;
|
||||||
$flags |= ($record['enable_magic_url']) ? OPTION_FLAG_LINKS : 0;
|
$flags |= ($record['enable_magic_url'] || $force_bbcode_reparsing) ? OPTION_FLAG_LINKS : 0;
|
||||||
$unparsed = array_merge(
|
$unparsed = array_merge(
|
||||||
$record,
|
$record,
|
||||||
generate_text_for_edit($record['text'], $record['bbcode_uid'], $flags)
|
generate_text_for_edit($record['text'], $record['bbcode_uid'], $flags)
|
||||||
|
@ -256,12 +257,12 @@ abstract class base implements reparser_interface
|
||||||
$unparsed['bbcode_uid'],
|
$unparsed['bbcode_uid'],
|
||||||
$bitfield,
|
$bitfield,
|
||||||
$flags,
|
$flags,
|
||||||
$unparsed['enable_bbcode'],
|
$unparsed['enable_bbcode'] || $force_bbcode_reparsing,
|
||||||
$unparsed['enable_magic_url'],
|
$unparsed['enable_magic_url'] || $force_bbcode_reparsing,
|
||||||
$unparsed['enable_smilies'],
|
$unparsed['enable_smilies'] || $force_bbcode_reparsing,
|
||||||
$unparsed['enable_img_bbcode'],
|
$unparsed['enable_img_bbcode'] || $force_bbcode_reparsing,
|
||||||
$unparsed['enable_quote_bbcode'],
|
$unparsed['enable_quote_bbcode'] || $force_bbcode_reparsing,
|
||||||
$unparsed['enable_url_bbcode'],
|
$unparsed['enable_url_bbcode'] || $force_bbcode_reparsing,
|
||||||
'text_reparser.' . $this->get_name()
|
'text_reparser.' . $this->get_name()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ interface reparser_interface
|
||||||
*
|
*
|
||||||
* @param integer $min_id Lower bound
|
* @param integer $min_id Lower bound
|
||||||
* @param integer $max_id Upper bound
|
* @param integer $max_id Upper bound
|
||||||
|
* @param bool $force_bbcode_reparsing Flag indicating if BBCode should be reparsed unconditionally
|
||||||
*/
|
*/
|
||||||
public function reparse_range($min_id, $max_id);
|
public function reparse_range($min_id, $max_id, bool $force_bbcode_reparsing = false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue