From 615ab099e228f2d7a35a76557095a65321425963 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 29 May 2015 19:33:17 +0200 Subject: [ticket/13891] Added reparser:list and reparser:reparse to CLI PHPBB3-13891 --- phpBB/phpbb/console/command/reparser/reparse.php | 106 +++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 phpBB/phpbb/console/command/reparser/reparse.php (limited to 'phpBB/phpbb/console/command/reparser/reparse.php') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php new file mode 100644 index 0000000000..f2bbe9c7d1 --- /dev/null +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -0,0 +1,106 @@ + +* @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('' . $this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $name, $start, $end) . ''); + $reparser->reparse_range($start, $end); + $id -= $n; + } + } +} -- cgit v1.2.1