aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authorJoshyPHP <s9e.dev@gmail.com>2015-07-06 01:43:43 +0200
committerJoshyPHP <s9e.dev@gmail.com>2015-07-06 23:45:20 +0200
commit7ccb6389124c5e990abaa917a6684fc3f4d072db (patch)
tree41ed0ef6d95a77643f0499b34fdc81364e05505a /phpBB
parentca5d4fd31031a47cc3a485457473b82660b84ed1 (diff)
downloadforums-7ccb6389124c5e990abaa917a6684fc3f4d072db.tar
forums-7ccb6389124c5e990abaa917a6684fc3f4d072db.tar.gz
forums-7ccb6389124c5e990abaa917a6684fc3f4d072db.tar.bz2
forums-7ccb6389124c5e990abaa917a6684fc3f4d072db.tar.xz
forums-7ccb6389124c5e990abaa917a6684fc3f4d072db.zip
[ticket/13987] Add --dry-run option to reparser CLI
PHPBB3-13987
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/language/en/cli.php1
-rw-r--r--phpBB/phpbb/console/command/reparser/reparse.php15
-rw-r--r--phpBB/phpbb/textreparser/base.php13
-rw-r--r--phpBB/phpbb/textreparser/reparser_interface.php7
4 files changed, 23 insertions, 13 deletions
diff --git a/phpBB/language/en/cli.php b/phpBB/language/en/cli.php
index 9eca60fb68..d45c52ac5d 100644
--- a/phpBB/language/en/cli.php
+++ b/phpBB/language/en/cli.php
@@ -64,6 +64,7 @@ $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_DRY_RUN' => 'Do not save any changes; just print what would happen',
'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',
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
@@ -57,6 +57,12 @@ class reparse extends \phpbb\console\command\command
->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,
InputOption::VALUE_REQUIRED,
@@ -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);
diff --git a/phpBB/phpbb/textreparser/base.php b/phpBB/phpbb/textreparser/base.php
index ed6c2376c7..6a366d659b 100644
--- a/phpBB/phpbb/textreparser/base.php
+++ b/phpBB/phpbb/textreparser/base.php
@@ -170,20 +170,21 @@ abstract class base implements reparser_interface
/**
* {@inheritdoc}
*/
- public function reparse_range($min_id, $max_id)
+ public function reparse_range($min_id, $max_id, $dry_run = false)
{
foreach ($this->get_records_by_range($min_id, $max_id) as $record)
{
- $this->reparse_record($record);
+ $this->reparse_record($record, $dry_run);
}
}
/**
* Reparse given record
*
- * @param array $record Associative array containing the record's data
+ * @param array $record Associative array containing the record's data
+ * @param integer $dry_run If TRUE, do not save the changes
*/
- protected function reparse_record(array $record)
+ protected function reparse_record(array $record, $dry_run)
{
$record = $this->add_missing_fields($record);
$flags = ($record['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0;
@@ -212,8 +213,8 @@ abstract class base implements reparser_interface
$unparsed['enable_url_bbcode']
);
- // Save the new text if it has changed
- if ($text !== $record['text'])
+ // Save the new text if it has changed and it's not a dry run
+ if ($text !== $record['text'] && !$dry_run)
{
$record['text'] = $text;
$this->save_record($record);
diff --git a/phpBB/phpbb/textreparser/reparser_interface.php b/phpBB/phpbb/textreparser/reparser_interface.php
index 9ea1732870..e201a77882 100644
--- a/phpBB/phpbb/textreparser/reparser_interface.php
+++ b/phpBB/phpbb/textreparser/reparser_interface.php
@@ -25,8 +25,9 @@ interface reparser_interface
/**
* Reparse all records in given range
*
- * @param integer $min_id Lower bound
- * @param integer $max_id Upper bound
+ * @param integer $min_id Lower bound
+ * @param integer $max_id Upper bound
+ * @param integer $dry_run If TRUE, do not save the changes
*/
- public function reparse_range($min_id, $max_id);
+ public function reparse_range($min_id, $max_id, $dry_run = false);
}