diff options
| author | Tristan Darricau <tristan.darricau@sensiolabs.com> | 2015-07-07 17:25:28 +0200 |
|---|---|---|
| committer | Tristan Darricau <tristan.darricau@sensiolabs.com> | 2015-07-07 17:25:28 +0200 |
| commit | 2fbfb0e00436acc090a55e1739cf8bdd3b5c4497 (patch) | |
| tree | 03bda2fcceca020ddc486ded2aafe32ae0c33d4b /phpBB | |
| parent | 39d3a026fe30c9ca3b276039e673cec0548e1eff (diff) | |
| parent | cf4cdcda586a2371aa92ae452951f9660737ae09 (diff) | |
| download | forums-2fbfb0e00436acc090a55e1739cf8bdd3b5c4497.tar forums-2fbfb0e00436acc090a55e1739cf8bdd3b5c4497.tar.gz forums-2fbfb0e00436acc090a55e1739cf8bdd3b5c4497.tar.bz2 forums-2fbfb0e00436acc090a55e1739cf8bdd3b5c4497.tar.xz forums-2fbfb0e00436acc090a55e1739cf8bdd3b5c4497.zip | |
Merge pull request #3744 from s9e/ticket/13987
[ticket/13987] Add --dry-run option to reparser CLI
Diffstat (limited to 'phpBB')
| -rw-r--r-- | phpBB/language/en/cli.php | 1 | ||||
| -rw-r--r-- | phpBB/phpbb/console/command/reparser/reparse.php | 14 | ||||
| -rw-r--r-- | phpBB/phpbb/textreparser/base.php | 27 |
3 files changed, 39 insertions, 3 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..151e196358 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, @@ -124,6 +130,14 @@ 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'); diff --git a/phpBB/phpbb/textreparser/base.php b/phpBB/phpbb/textreparser/base.php index ed6c2376c7..3e5ee248a1 100644 --- a/phpBB/phpbb/textreparser/base.php +++ b/phpBB/phpbb/textreparser/base.php @@ -16,6 +16,11 @@ namespace phpbb\textreparser; abstract class base implements reparser_interface { /** + * @var bool Whether to save changes to the database + */ + protected $save_changes = true; + + /** * {@inheritdoc} */ abstract public function get_max_id(); @@ -85,6 +90,22 @@ abstract class base implements reparser_interface } /** + * Disable saving changes to the database + */ + public function disable_save() + { + $this->save_changes = false; + } + + /** + * Enable saving changes to the database + */ + public function enable_save() + { + $this->save_changes = true; + } + + /** * Guess whether given BBCode is in use in given record * * @param array $record @@ -181,7 +202,7 @@ abstract class base implements reparser_interface /** * Reparse given record * - * @param array $record Associative array containing the record's data + * @param array $record Associative array containing the record's data */ protected function reparse_record(array $record) { @@ -212,8 +233,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'] && $this->save_changes) { $record['text'] = $text; $this->save_record($record); |
