diff options
author | JoshyPHP <s9e.dev@gmail.com> | 2015-07-06 01:57:54 +0200 |
---|---|---|
committer | JoshyPHP <s9e.dev@gmail.com> | 2015-07-06 23:45:38 +0200 |
commit | cf4cdcda586a2371aa92ae452951f9660737ae09 (patch) | |
tree | 15cab3410c1a38bf7520f9dc7745d8c4056f16b9 | |
parent | 7ccb6389124c5e990abaa917a6684fc3f4d072db (diff) | |
download | forums-cf4cdcda586a2371aa92ae452951f9660737ae09.tar forums-cf4cdcda586a2371aa92ae452951f9660737ae09.tar.gz forums-cf4cdcda586a2371aa92ae452951f9660737ae09.tar.bz2 forums-cf4cdcda586a2371aa92ae452951f9660737ae09.tar.xz forums-cf4cdcda586a2371aa92ae452951f9660737ae09.zip |
[ticket/13987] Replaced optional parameter with explicit API
Added disable_save() and enable_save() to toggle a dry run
PHPBB3-13987
-rw-r--r-- | phpBB/phpbb/console/command/reparser/reparse.php | 17 | ||||
-rw-r--r-- | phpBB/phpbb/textreparser/base.php | 32 | ||||
-rw-r--r-- | phpBB/phpbb/textreparser/reparser_interface.php | 7 | ||||
-rw-r--r-- | tests/text_reparser/plugins/contact_admin_info_test.php | 4 | ||||
-rw-r--r-- | tests/text_reparser/plugins/poll_option_test.php | 4 | ||||
-rw-r--r-- | tests/text_reparser/plugins/test_row_based_plugin.php | 3 |
6 files changed, 49 insertions, 18 deletions
diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 8352c523de..151e196358 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -130,12 +130,19 @@ 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'); - $min = $input->getOption('range-min'); - $size = $input->getOption('range-size'); - $dry_run = $input->getOption('dry-run'); + $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'); if ($max === 0) { @@ -183,7 +190,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, $dry_run); + $reparser->reparse_range($start, $end); $current = $start - 1; $progress->setProgress($max + 1 - $start); 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 @@ -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 @@ -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); } diff --git a/tests/text_reparser/plugins/contact_admin_info_test.php b/tests/text_reparser/plugins/contact_admin_info_test.php index e3df1ee2b8..1dc03834b6 100644 --- a/tests/text_reparser/plugins/contact_admin_info_test.php +++ b/tests/text_reparser/plugins/contact_admin_info_test.php @@ -62,7 +62,8 @@ class phpbb_textreparser_contact_admin_info_test extends phpbb_database_test_cas { $old_rows = $this->get_rows(); $reparser = $this->get_reparser(); - $reparser->reparse_range(1, 1, true); + $reparser->disable_save(); + $reparser->reparse_range(1, 1); $new_rows = $this->get_rows(); $this->assertEquals($old_rows, $new_rows); } @@ -70,6 +71,7 @@ class phpbb_textreparser_contact_admin_info_test extends phpbb_database_test_cas public function test_reparse() { $reparser = $this->get_reparser(); + $reparser->enable_save(); $reparser->reparse_range(1, 1); $expected = array( array( diff --git a/tests/text_reparser/plugins/poll_option_test.php b/tests/text_reparser/plugins/poll_option_test.php index cc6163a81b..dfa3a030ed 100644 --- a/tests/text_reparser/plugins/poll_option_test.php +++ b/tests/text_reparser/plugins/poll_option_test.php @@ -62,7 +62,8 @@ class phpbb_textreparser_poll_option_test extends phpbb_database_test_case { $old_rows = $this->get_rows(); $reparser = $this->get_reparser(); - $reparser->reparse_range(1, 1, true); + $reparser->disable_save(); + $reparser->reparse_range(1, 1); $new_rows = $this->get_rows(); $this->assertEquals($old_rows, $new_rows); } @@ -70,6 +71,7 @@ class phpbb_textreparser_poll_option_test extends phpbb_database_test_case public function testReparse() { $reparser = $this->get_reparser(); + $reparser->enable_save(); $reparser->reparse_range(2, 13); $expected = array( array( diff --git a/tests/text_reparser/plugins/test_row_based_plugin.php b/tests/text_reparser/plugins/test_row_based_plugin.php index 9f9ecc609a..bbae44c8e0 100644 --- a/tests/text_reparser/plugins/test_row_based_plugin.php +++ b/tests/text_reparser/plugins/test_row_based_plugin.php @@ -57,7 +57,8 @@ abstract class phpbb_textreparser_test_row_based_plugin extends phpbb_database_t { $old_rows = $this->get_rows(array(1)); $reparser = $this->get_reparser(); - $reparser->reparse_range(1, 1, true); + $reparser->disable_save(); + $reparser->reparse_range(1, 1); $new_rows = $this->get_rows(array(1)); $this->assertEquals($old_rows, $new_rows); } |