From 7ccb6389124c5e990abaa917a6684fc3f4d072db Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 6 Jul 2015 01:43:43 +0200 Subject: [ticket/13987] Add --dry-run option to reparser CLI PHPBB3-13987 --- phpBB/phpbb/textreparser/base.php | 13 +++++++------ phpBB/phpbb/textreparser/reparser_interface.php | 7 ++++--- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'phpBB/phpbb/textreparser') 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); } -- cgit v1.2.1 From cf4cdcda586a2371aa92ae452951f9660737ae09 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 6 Jul 2015 01:57:54 +0200 Subject: [ticket/13987] Replaced optional parameter with explicit API Added disable_save() and enable_save() to toggle a dry run PHPBB3-13987 --- phpBB/phpbb/textreparser/base.php | 32 ++++++++++++++++++++----- phpBB/phpbb/textreparser/reparser_interface.php | 7 +++--- 2 files changed, 29 insertions(+), 10 deletions(-) (limited to 'phpBB/phpbb/textreparser') diff --git a/phpBB/phpbb/textreparser/base.php b/phpBB/phpbb/textreparser/base.php index 6a366d659b..3e5ee248a1 100644 --- a/phpBB/phpbb/textreparser/base.php +++ b/phpBB/phpbb/textreparser/base.php @@ -15,6 +15,11 @@ namespace phpbb\textreparser; abstract class base implements reparser_interface { + /** + * @var bool Whether to save changes to the database + */ + protected $save_changes = true; + /** * {@inheritdoc} */ @@ -84,6 +89,22 @@ abstract class base implements reparser_interface return $record; } + /** + * 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 * @@ -170,21 +191,20 @@ abstract class base implements reparser_interface /** * {@inheritdoc} */ - public function reparse_range($min_id, $max_id, $dry_run = false) + public function reparse_range($min_id, $max_id) { foreach ($this->get_records_by_range($min_id, $max_id) as $record) { - $this->reparse_record($record, $dry_run); + $this->reparse_record($record); } } /** * Reparse given record * - * @param array $record Associative array containing the record's data - * @param integer $dry_run If TRUE, do not save the changes + * @param array $record Associative array containing the record's data */ - protected function reparse_record(array $record, $dry_run) + protected function reparse_record(array $record) { $record = $this->add_missing_fields($record); $flags = ($record['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0; @@ -214,7 +234,7 @@ abstract class base implements reparser_interface ); // Save the new text if it has changed and it's not a dry run - if ($text !== $record['text'] && !$dry_run) + if ($text !== $record['text'] && $this->save_changes) { $record['text'] = $text; $this->save_record($record); diff --git a/phpBB/phpbb/textreparser/reparser_interface.php b/phpBB/phpbb/textreparser/reparser_interface.php index e201a77882..9ea1732870 100644 --- a/phpBB/phpbb/textreparser/reparser_interface.php +++ b/phpBB/phpbb/textreparser/reparser_interface.php @@ -25,9 +25,8 @@ interface reparser_interface /** * Reparse all records in given range * - * @param integer $min_id Lower bound - * @param integer $max_id Upper bound - * @param integer $dry_run If TRUE, do not save the changes + * @param integer $min_id Lower bound + * @param integer $max_id Upper bound */ - public function reparse_range($min_id, $max_id, $dry_run = false); + public function reparse_range($min_id, $max_id); } -- cgit v1.2.1