Skip to content

Commit b4bbc70

Browse files
author
Tristan Darricau
committed
Merge pull request phpbb#4005 from Elsensee/ticket/14257
[ticket/14257] Reparse after update * Elsensee/ticket/14257: [ticket/14257] Add tests for reparser manager [ticket/14257] Fix CLI reparser and set cron interval [ticket/14257] Fix CLI error message [ticket/14257] Fix phpdoc in CLI command [ticket/14257] Add text_reparser manager [ticket/14257] Use migrations instead of cron job for some reparsers [ticket/14257] Fix lock acquire in CLI command [ticket/14257] Fix if condition [ticket/14257] Add reparse_lock to CLI command [ticket/14257] Add cron tasks for reparsing text
2 parents cfd0ec7 + 762b383 commit b4bbc70

10 files changed

Lines changed: 647 additions & 61 deletions

File tree

phpBB/config/default/container/services_console.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,9 @@ services:
187187
class: phpbb\console\command\reparser\reparse
188188
arguments:
189189
- @user
190+
- @text_reparser.lock
190191
- @text_reparser_collection
191-
- @config_text
192+
- @text_reparser.manager
192193
tags:
193194
- { name: console.command }
194195

phpBB/config/default/container/services_cron.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,73 @@ services:
146146
- [set_name, [cron.task.core.tidy_warnings]]
147147
tags:
148148
- { name: cron.task }
149+
150+
cron.task.text_reparser.pm_text:
151+
class: phpbb\cron\task\text_reparser\reparser
152+
arguments:
153+
- @config
154+
- @config_text
155+
- @text_reparser.lock
156+
- @text_reparser.manager
157+
- @text_reparser_collection
158+
calls:
159+
- [set_name, [cron.task.text_reparser.pm_text]]
160+
- [set_reparser, [text_reparser.pm_text]]
161+
tags:
162+
- { name: cron.task }
163+
164+
cron.task.text_reparser.poll_option:
165+
class: phpbb\cron\task\text_reparser\reparser
166+
arguments:
167+
- @config
168+
- @config_text
169+
- @text_reparser.lock
170+
- @text_reparser.manager
171+
- @text_reparser_collection
172+
calls:
173+
- [set_name, [cron.task.text_reparser.poll_option]]
174+
- [set_reparser, [text_reparser.poll_option]]
175+
tags:
176+
- { name: cron.task }
177+
178+
cron.task.text_reparser.poll_title:
179+
class: phpbb\cron\task\text_reparser\reparser
180+
arguments:
181+
- @config
182+
- @config_text
183+
- @text_reparser.lock
184+
- @text_reparser.manager
185+
- @text_reparser_collection
186+
calls:
187+
- [set_name, [cron.task.text_reparser.poll_title]]
188+
- [set_reparser, [text_reparser.poll_title]]
189+
tags:
190+
- { name: cron.task }
191+
192+
cron.task.text_reparser.post_text:
193+
class: phpbb\cron\task\text_reparser\reparser
194+
arguments:
195+
- @config
196+
- @config_text
197+
- @text_reparser.lock
198+
- @text_reparser.manager
199+
- @text_reparser_collection
200+
calls:
201+
- [set_name, [cron.task.text_reparser.post_text]]
202+
- [set_reparser, [text_reparser.post_text]]
203+
tags:
204+
- { name: cron.task }
205+
206+
cron.task.text_reparser.user_signature:
207+
class: phpbb\cron\task\text_reparser\reparser
208+
arguments:
209+
- @config
210+
- @config_text
211+
- @text_reparser.lock
212+
- @text_reparser.manager
213+
- @text_reparser_collection
214+
calls:
215+
- [set_name, [cron.task.text_reparser.user_signature]]
216+
- [set_reparser, [text_reparser.user_signature]]
217+
tags:
218+
- { name: cron.task }

phpBB/config/default/container/services_text_reparser.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
services:
2+
text_reparser.manager:
3+
class: phpbb\textreparser\manager
4+
arguments:
5+
- @config
6+
- @config_text
7+
- @text_reparser_collection
8+
9+
text_reparser.lock:
10+
class: phpbb\lock\db
11+
arguments:
12+
- reparse_lock
13+
- @config
14+
- @dbal.conn
15+
216
text_reparser_collection:
317
class: phpbb\di\service_collection
418
arguments:

phpBB/language/en/acp/common.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@
292292

293293
'RELEASE_ANNOUNCEMENT' => 'Announcement',
294294
'REMIND' => 'Remind',
295+
'REPARSE_LOCK_ERROR' => 'Reparsing is already in progress by another process.',
295296
'RESYNC' => 'Resynchronise',
296297

297298
'RUNNING_TASK' => 'Running task: %s.',

phpBB/phpbb/console/command/reparser/reparse.php

Lines changed: 39 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace phpbb\console\command\reparser;
1515

16+
use phpbb\exception\runtime_exception;
1617
use Symfony\Component\Console\Input\InputInterface;
1718
use Symfony\Component\Console\Input\InputArgument;
1819
use Symfony\Component\Console\Input\InputOption;
@@ -21,11 +22,6 @@
2122

2223
class reparse extends \phpbb\console\command\command
2324
{
24-
/**
25-
* @var \phpbb\config\db_text
26-
*/
27-
protected $config_text;
28-
2925
/**
3026
* @var InputInterface
3127
*/
@@ -41,28 +37,40 @@ class reparse extends \phpbb\console\command\command
4137
*/
4238
protected $output;
4339

40+
/**
41+
* @var \phpbb\lock\db
42+
*/
43+
protected $reparse_lock;
44+
45+
/**
46+
* @var \phpbb\textreparser\manager
47+
*/
48+
protected $reparser_manager;
49+
4450
/**
4551
* @var \phpbb\di\service_collection
4652
*/
4753
protected $reparsers;
4854

4955
/**
50-
* @var array Reparser names as keys, and their last $current ID as values
56+
* @var array The reparser's last $current ID as values
5157
*/
5258
protected $resume_data;
5359

5460
/**
5561
* Constructor
5662
*
5763
* @param \phpbb\user $user
64+
* @param \phpbb\lock\db $reparse_lock
65+
* @param \phpbb\textreparser\manager $reparser_manager
5866
* @param \phpbb\di\service_collection $reparsers
59-
* @param \phpbb\config\db_text $config_text
6067
*/
61-
public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers, \phpbb\config\db_text $config_text)
68+
public function __construct(\phpbb\user $user, \phpbb\lock\db $reparse_lock, \phpbb\textreparser\manager $reparser_manager, \phpbb\di\service_collection $reparsers)
6269
{
6370
require_once __DIR__ . '/../../../../includes/functions_content.php';
6471

65-
$this->config_text = $config_text;
72+
$this->reparse_lock = $reparse_lock;
73+
$this->reparser_manager = $reparser_manager;
6674
$this->reparsers = $reparsers;
6775
parent::__construct($user);
6876
}
@@ -163,7 +171,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
163171
$this->input = $input;
164172
$this->output = $output;
165173
$this->io = new SymfonyStyle($input, $output);
166-
$this->load_resume_data();
174+
175+
if (!$this->reparse_lock->acquire())
176+
{
177+
throw new runtime_exception('REPARSE_LOCK_ERROR', array(), null, 1);
178+
}
167179

168180
$name = $input->getArgument('reparser-name');
169181
if (isset($name))
@@ -185,6 +197,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
185197

186198
$this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS'));
187199

200+
$this->reparse_lock->release();
201+
188202
return 0;
189203
}
190204

@@ -194,36 +208,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
194208
* Will use the last saved value if --resume is set and the option was not specified
195209
* on the command line
196210
*
197-
* @param string $reparser_name Reparser name
198211
* @param string $option_name Option name
199212
* @return integer
200213
*/
201-
protected function get_option($reparser_name, $option_name)
214+
protected function get_option($option_name)
202215
{
203216
// Return the option from the resume_data if applicable
204-
if ($this->input->getOption('resume') && isset($this->resume_data[$reparser_name][$option_name]) && !$this->input->hasParameterOption('--' . $option_name))
217+
if ($this->input->getOption('resume') && isset($this->resume_data[$option_name]) && !$this->input->hasParameterOption('--' . $option_name))
205218
{
206-
return $this->resume_data[$reparser_name][$option_name];
219+
return $this->resume_data[$option_name];
207220
}
208221

209-
$value = $this->input->getOption($option_name);
210-
211-
// range-max has no default value, it must be computed for each reparser
212-
if ($option_name === 'range-max' && $value === null)
213-
{
214-
$value = $this->reparsers[$reparser_name]->get_max_id();
215-
}
216-
217-
return $value;
218-
}
219-
220-
/**
221-
* Load the resume data from the database
222-
*/
223-
protected function load_resume_data()
224-
{
225-
$resume_data = $this->config_text->get('reparser_resume');
226-
$this->resume_data = (empty($resume_data)) ? array() : unserialize($resume_data);
222+
return $this->input->getOption($option_name);
227223
}
228224

229225
/**
@@ -234,6 +230,7 @@ protected function load_resume_data()
234230
protected function reparse($name)
235231
{
236232
$reparser = $this->reparsers[$name];
233+
$this->resume_data = $this->reparser_manager->get_resume_data($name);
237234
if ($this->input->getOption('dry-run'))
238235
{
239236
$reparser->disable_save();
@@ -244,9 +241,15 @@ protected function reparse($name)
244241
}
245242

246243
// Start at range-max if specified or at the highest ID otherwise
247-
$max = $this->get_option($name, 'range-max');
248-
$min = $this->get_option($name, 'range-min');
249-
$size = $this->get_option($name, 'range-size');
244+
$max = $this->get_option('range-max');
245+
$min = $this->get_option('range-min');
246+
$size = $this->get_option('range-size');
247+
248+
// range-max has no default value, it must be computed for each reparser
249+
if ($max == null)
250+
{
251+
$max = $reparser->get_max_id();
252+
}
250253

251254
if ($max < $min)
252255
{
@@ -272,34 +275,10 @@ protected function reparse($name)
272275
$current = $start - 1;
273276
$progress->setProgress($max + 1 - $start);
274277

275-
$this->update_resume_data($name, $current);
278+
$this->reparser_manager->update_resume_data($name, $min, $current, $size, !$this->input->getOption('dry-run'));
276279
}
277280
$progress->finish();
278281

279282
$this->io->newLine(2);
280283
}
281-
282-
/**
283-
* Save the resume data to the database
284-
*/
285-
protected function save_resume_data()
286-
{
287-
$this->config_text->set('reparser_resume', serialize($this->resume_data));
288-
}
289-
290-
/**
291-
* Save the resume data to the database
292-
*
293-
* @param string $name Reparser name
294-
* @param string $current Current ID
295-
*/
296-
protected function update_resume_data($name, $current)
297-
{
298-
$this->resume_data[$name] = array(
299-
'range-min' => $this->get_option($name, 'range-min'),
300-
'range-max' => $current,
301-
'range-size' => $this->get_option($name, 'range-size'),
302-
);
303-
$this->save_resume_data();
304-
}
305284
}

0 commit comments

Comments
 (0)