1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 22:10:45 +02:00

Merge pull request #3744 from s9e/ticket/13987

[ticket/13987] Add --dry-run option to reparser CLI
This commit is contained in:
Tristan Darricau
2015-07-07 17:25:28 +02:00
6 changed files with 117 additions and 34 deletions

View File

@@ -56,6 +56,12 @@ class reparse extends \phpbb\console\command\command
->setName('reparser:reparse')
->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,
@@ -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');

View File

@@ -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
*
@@ -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);