Merge branch '3.2.x'

This commit is contained in:
Marc Alexander 2016-12-18 19:34:19 +01:00
commit 1ccc214afb
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
7 changed files with 87 additions and 14 deletions

View file

@ -24,6 +24,8 @@ services:
class: phpbb\textreparser\plugins\contact_admin_info class: phpbb\textreparser\plugins\contact_admin_info
arguments: arguments:
- '@config_text' - '@config_text'
calls:
- [set_name, [contact_admin_info]]
tags: tags:
- { name: text_reparser.plugin } - { name: text_reparser.plugin }
@ -32,6 +34,8 @@ services:
arguments: arguments:
- '@dbal.conn' - '@dbal.conn'
- '%tables.forums%' - '%tables.forums%'
calls:
- [set_name, [forum_description]]
tags: tags:
- { name: text_reparser.plugin } - { name: text_reparser.plugin }
@ -40,6 +44,8 @@ services:
arguments: arguments:
- '@dbal.conn' - '@dbal.conn'
- '%tables.forums%' - '%tables.forums%'
calls:
- [set_name, [forum_rules]]
tags: tags:
- { name: text_reparser.plugin } - { name: text_reparser.plugin }
@ -48,6 +54,8 @@ services:
arguments: arguments:
- '@dbal.conn' - '@dbal.conn'
- '%tables.groups%' - '%tables.groups%'
calls:
- [set_name, [group_description]]
tags: tags:
- { name: text_reparser.plugin } - { name: text_reparser.plugin }
@ -56,6 +64,8 @@ services:
arguments: arguments:
- '@dbal.conn' - '@dbal.conn'
- '%tables.privmsgs%' - '%tables.privmsgs%'
calls:
- [set_name, [pm_text]]
tags: tags:
- { name: text_reparser.plugin } - { name: text_reparser.plugin }
@ -63,6 +73,8 @@ services:
class: phpbb\textreparser\plugins\poll_option class: phpbb\textreparser\plugins\poll_option
arguments: arguments:
- '@dbal.conn' - '@dbal.conn'
calls:
- [set_name, [poll_option]]
tags: tags:
- { name: text_reparser.plugin } - { name: text_reparser.plugin }
@ -71,6 +83,8 @@ services:
arguments: arguments:
- '@dbal.conn' - '@dbal.conn'
- '%tables.topics%' - '%tables.topics%'
calls:
- [set_name, [poll_title]]
tags: tags:
- { name: text_reparser.plugin } - { name: text_reparser.plugin }
@ -79,6 +93,8 @@ services:
arguments: arguments:
- '@dbal.conn' - '@dbal.conn'
- '%tables.posts%' - '%tables.posts%'
calls:
- [set_name, [post_text]]
tags: tags:
- { name: text_reparser.plugin } - { name: text_reparser.plugin }
@ -87,5 +103,7 @@ services:
arguments: arguments:
- '@dbal.conn' - '@dbal.conn'
- '%tables.users%' - '%tables.users%'
calls:
- [set_name, [user_signature]]
tags: tags:
- { name: text_reparser.plugin } - { name: text_reparser.plugin }

View file

@ -34,10 +34,10 @@ class list_all extends \phpbb\console\command\command
{ {
parent::__construct($user); parent::__construct($user);
$this->reparser_names = array(); $this->reparser_names = array();
foreach ($reparsers as $name => $reparser) foreach ($reparsers as $reparser)
{ {
// Store the names without the "text_reparser." prefix // Store the names without the "text_reparser." prefix
$this->reparser_names[] = preg_replace('(^text_reparser\\.)', '', $name); $this->reparser_names[] = $reparser->get_name();
} }
} }

View file

@ -140,13 +140,9 @@ class reparse extends \phpbb\console\command\command
} }
$name = $input->getArgument('reparser-name'); $name = $input->getArgument('reparser-name');
if (isset($name)) if ($name)
{ {
// Allow "post_text" to be an alias for "text_reparser.post_text" $name = $this->reparser_manager->find_reparser($name);
if (!isset($this->reparsers[$name]))
{
$name = 'text_reparser.' . $name;
}
$this->reparse($name); $this->reparse($name);
} }
else else
@ -187,7 +183,7 @@ class reparse extends \phpbb\console\command\command
/** /**
* Reparse all text handled by given reparser within given range * Reparse all text handled by given reparser within given range
* *
* @param string $name Reparser name * @param string $name Reparser service name
*/ */
protected function reparse($name) protected function reparse($name)
{ {
@ -218,10 +214,10 @@ class reparse extends \phpbb\console\command\command
return; return;
} }
$this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', preg_replace('(^text_reparser\\.)', '', $name), $min, $max)); $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $reparser->get_name(), $min, $max));
$progress = $this->create_progress_bar($max, $this->io, $this->output, true); $progress = $this->create_progress_bar($max, $this->io, $this->output, true);
$progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', preg_replace('(^text_reparser\\.)', '', $name))); $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', $reparser->get_name()));
$progress->start(); $progress->start();
// Start from $max and decrement $current by $size until we reach $min // Start from $max and decrement $current by $size until we reach $min
@ -231,7 +227,7 @@ class reparse extends \phpbb\console\command\command
$start = max($min, $current + 1 - $size); $start = max($min, $current + 1 - $size);
$end = max($min, $current); $end = max($min, $current);
$progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', preg_replace('(^text_reparser\\.)', '', $name), $start, $end)); $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $reparser->get_name(), $start, $end));
$reparser->reparse_range($start, $end); $reparser->reparse_range($start, $end);
$current = $start - 1; $current = $start - 1;

View file

@ -81,7 +81,7 @@ class reparser extends \phpbb\cron\task\base
*/ */
public function set_reparser($reparser) public function set_reparser($reparser)
{ {
$this->reparser_name = (!isset($this->reparsers[$reparser]) ? 'text_reparser.' : '') . $reparser; $this->reparser_name = !isset($this->reparsers[$reparser]) ? $this->reparser_manager->find_reparser($reparser) : $reparser;
if ($this->resume_data === null) if ($this->resume_data === null)
{ {

View file

@ -15,6 +15,11 @@ namespace phpbb\textreparser;
abstract class base implements reparser_interface abstract class base implements reparser_interface
{ {
/**
* @var string The reparser name
*/
protected $name;
/** /**
* @var bool Whether to save changes to the database * @var bool Whether to save changes to the database
*/ */
@ -89,6 +94,26 @@ abstract class base implements reparser_interface
return $record; return $record;
} }
/**
* Returns the name of the reparser
*
* @return string Name of reparser
*/
public function get_name()
{
return $this->name;
}
/**
* Sets the name of the reparser
*
* @param string $name The reparser name
*/
public function set_name($name)
{
$this->name = $name;
}
/** /**
* Disable saving changes to the database * Disable saving changes to the database
*/ */
@ -231,7 +256,7 @@ abstract class base implements reparser_interface
$unparsed['enable_flash_bbcode'], $unparsed['enable_flash_bbcode'],
$unparsed['enable_quote_bbcode'], $unparsed['enable_quote_bbcode'],
$unparsed['enable_url_bbcode'], $unparsed['enable_url_bbcode'],
'reparse' 'text_reparser.' . $this->get_name()
); );
// Save the new text if it has changed and it's not a dry run // Save the new text if it has changed and it's not a dry run

View file

@ -125,4 +125,24 @@ class manager
$this->schedule($reparser, $interval); $this->schedule($reparser, $interval);
} }
} }
/**
* Finds a reparser by name.
*
* If there is no reparser with the specified name, null is returned.
*
* @param string $name Name of the reparser to look up.
* @return string A reparser service name, or null.
*/
public function find_reparser($name)
{
foreach ($this->reparsers as $service => $reparser)
{
if ($reparser->get_name() == $name)
{
return $service;
}
}
return null;
}
} }

View file

@ -22,6 +22,20 @@ interface reparser_interface
*/ */
public function get_max_id(); public function get_max_id();
/**
* Returns the name of the reparser
*
* @return string Name of reparser
*/
public function get_name();
/**
* Sets the name of the reparser
*
* @param string $name The reparser name
*/
public function set_name($name);
/** /**
* Reparse all records in given range * Reparse all records in given range
* *