mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-29 06:38:52 +00:00
[ticket/13891] Added reparser:list and reparser:reparse to CLI
PHPBB3-13891
This commit is contained in:
parent
614f04b455
commit
615ab099e2
4 changed files with 197 additions and 0 deletions
|
@ -140,3 +140,19 @@ services:
|
||||||
- @dbal.conn
|
- @dbal.conn
|
||||||
tags:
|
tags:
|
||||||
- { name: console.command }
|
- { name: console.command }
|
||||||
|
|
||||||
|
console.command.reparser.list:
|
||||||
|
class: phpbb\console\command\reparser\list_all
|
||||||
|
arguments:
|
||||||
|
- @user
|
||||||
|
- @service_container
|
||||||
|
tags:
|
||||||
|
- { name: console.command }
|
||||||
|
|
||||||
|
console.command.reparser.reparse:
|
||||||
|
class: phpbb\console\command\reparser\reparse
|
||||||
|
arguments:
|
||||||
|
- @user
|
||||||
|
- @text_reparser_collection
|
||||||
|
tags:
|
||||||
|
- { name: console.command }
|
||||||
|
|
|
@ -61,6 +61,9 @@ $lang = array_merge($lang, array(
|
||||||
'CLI_DESCRIPTION_OPTION_SAFE_MODE' => 'Run in Safe Mode (without extensions).',
|
'CLI_DESCRIPTION_OPTION_SAFE_MODE' => 'Run in Safe Mode (without extensions).',
|
||||||
'CLI_DESCRIPTION_OPTION_SHELL' => 'Launch the shell.',
|
'CLI_DESCRIPTION_OPTION_SHELL' => 'Launch the shell.',
|
||||||
'CLI_DESCRIPTION_PURGE_EXTENSION' => 'Purges the specified extension.',
|
'CLI_DESCRIPTION_PURGE_EXTENSION' => 'Purges the specified extension.',
|
||||||
|
'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_RECALCULATE_EMAIL_HASH' => 'Recalculates the user_email_hash column of the users table.',
|
'CLI_DESCRIPTION_RECALCULATE_EMAIL_HASH' => 'Recalculates the user_email_hash column of the users table.',
|
||||||
'CLI_DESCRIPTION_SET_ATOMIC_CONFIG' => 'Sets a configuration option’s value only if the old matches the current value',
|
'CLI_DESCRIPTION_SET_ATOMIC_CONFIG' => 'Sets a configuration option’s value only if the old matches the current value',
|
||||||
'CLI_DESCRIPTION_SET_CONFIG' => 'Sets a configuration option’s value',
|
'CLI_DESCRIPTION_SET_CONFIG' => 'Sets a configuration option’s value',
|
||||||
|
@ -78,4 +81,6 @@ $lang = array_merge($lang, array(
|
||||||
'CLI_EXTENSIONS_ENABLED' => 'Enabled',
|
'CLI_EXTENSIONS_ENABLED' => 'Enabled',
|
||||||
|
|
||||||
'CLI_FIXUP_RECALCULATE_EMAIL_HASH_SUCCESS' => 'Successfully recalculated all email hashes.',
|
'CLI_FIXUP_RECALCULATE_EMAIL_HASH_SUCCESS' => 'Successfully recalculated all email hashes.',
|
||||||
|
|
||||||
|
'CLI_REPARSER_REPARSE_REPARSING' => 'Reparsing %1$s with range %2$d..%3$d',
|
||||||
));
|
));
|
||||||
|
|
70
phpBB/phpbb/console/command/reparser/list_all.php
Normal file
70
phpBB/phpbb/console/command/reparser/list_all.php
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is part of the phpBB Forum Software package.
|
||||||
|
*
|
||||||
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||||
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see
|
||||||
|
* the docs/CREDITS.txt file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace phpbb\console\command\reparser;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
|
class list_all extends \phpbb\console\command\command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string[] Names of the reparser services
|
||||||
|
*/
|
||||||
|
protected $reparser_names;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param \phpbb\user $user
|
||||||
|
* @param ContainerBuilder $container Container used to locate the reparsers
|
||||||
|
*/
|
||||||
|
public function __construct(\phpbb\user $user, ContainerBuilder $container)
|
||||||
|
{
|
||||||
|
parent::__construct($user);
|
||||||
|
$this->reparser_names = array();
|
||||||
|
foreach (array_keys($container->findTaggedServiceIds('text_reparser.plugin')) as $name)
|
||||||
|
{
|
||||||
|
// Store the names without the "text_reparser." prefix
|
||||||
|
$this->reparser_names[] = str_replace('text_reparser.', '', $name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the command name and description
|
||||||
|
*
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->setName('reparser:list')
|
||||||
|
->setDescription($this->user->lang('CLI_DESCRIPTION_REPARSER_LIST'))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the command reparser:reparse
|
||||||
|
*
|
||||||
|
* @param InputInterface $input
|
||||||
|
* @param OutputInterface $output
|
||||||
|
* @return integer
|
||||||
|
*/
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$output->writeln('<info>' . implode(', ', $this->reparser_names) . '</info>');
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
106
phpBB/phpbb/console/command/reparser/reparse.php
Normal file
106
phpBB/phpbb/console/command/reparser/reparse.php
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is part of the phpBB Forum Software package.
|
||||||
|
*
|
||||||
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||||
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see
|
||||||
|
* the docs/CREDITS.txt file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace phpbb\console\command\reparser;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
class reparse extends \phpbb\console\command\command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var \phpbb\textreparser\reparser_collection
|
||||||
|
*/
|
||||||
|
protected $reparser_collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param \phpbb\user $user
|
||||||
|
* @param \phpbb\textreparser\reparser_collection $reparser_collection
|
||||||
|
*/
|
||||||
|
public function __construct(\phpbb\user $user, \phpbb\textreparser\reparser_collection $reparser_collection)
|
||||||
|
{
|
||||||
|
require_once __DIR__ . '/../../../../includes/functions_content.php';
|
||||||
|
|
||||||
|
$this->reparser_collection = $reparser_collection;
|
||||||
|
parent::__construct($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the command name and description
|
||||||
|
*
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->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'))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the command reparser:reparse
|
||||||
|
*
|
||||||
|
* @param InputInterface $input
|
||||||
|
* @param OutputInterface $output
|
||||||
|
* @return integer
|
||||||
|
*/
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$name = $input->getArgument('reparser-name');
|
||||||
|
if (isset($name))
|
||||||
|
{
|
||||||
|
// Allow "post_text" to be an alias for "text_reparser.post_text"
|
||||||
|
if (!isset($this->reparser_collection[$name]))
|
||||||
|
{
|
||||||
|
$name = 'text_reparser.' . $name;
|
||||||
|
}
|
||||||
|
$this->reparse($output, $name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach ($this->reparser_collection as $name => $service)
|
||||||
|
{
|
||||||
|
$this->reparse($output, $name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reparse all text handled by given reparser
|
||||||
|
*
|
||||||
|
* @param OutputInterface $output
|
||||||
|
* @param string $name Reparser name
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
protected function reparse(OutputInterface $output, $name)
|
||||||
|
{
|
||||||
|
$reparser = $this->reparser_collection[$name];
|
||||||
|
$id = $reparser->get_max_id();
|
||||||
|
$n = 100;
|
||||||
|
while ($id > 0)
|
||||||
|
{
|
||||||
|
$start = max(0, $id + 1 - $n);
|
||||||
|
$end = $id;
|
||||||
|
$output->writeln('<info>' . $this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $name, $start, $end) . '</info>');
|
||||||
|
$reparser->reparse_range($start, $end);
|
||||||
|
$id -= $n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue