aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/console/command/reparser/reparse.php
blob: f2bbe9c7d11a9671b6c279b6c80b06de6ac26921 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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;
		}
	}
}