From c7ecb1310f7663e5fdaafb655381663b9410c31a Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Sat, 24 Oct 2015 20:10:16 +0200 Subject: [ticket/14257] Add reparse_lock to CLI command PHPBB3-14257 --- phpBB/phpbb/console/command/reparser/reparse.php | 50 ++++++++++++++++-------- 1 file changed, 34 insertions(+), 16 deletions(-) (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 index 63124b4b8c..e77b384d8e 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -13,6 +13,7 @@ namespace phpbb\console\command\reparser; +use phpbb\exception\runtime_exception; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; @@ -41,6 +42,11 @@ class reparse extends \phpbb\console\command\command */ protected $output; + /** + * @var \phpbb\lock\db + */ + protected $reparse_lock; + /** * @var \phpbb\di\service_collection */ @@ -57,13 +63,15 @@ class reparse extends \phpbb\console\command\command * @param \phpbb\user $user * @param \phpbb\di\service_collection $reparsers * @param \phpbb\config\db_text $config_text + * @param \phpbb\lock\db $reparse_lock */ - public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers, \phpbb\config\db_text $config_text) + public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers, \phpbb\config\db_text $config_text, \phpbb\lock\db $reparse_lock) { require_once __DIR__ . '/../../../../includes/functions_content.php'; $this->config_text = $config_text; $this->reparsers = $reparsers; + $this->reparse_lock = $reparse_lock; parent::__construct($user); } @@ -163,29 +171,39 @@ class reparse extends \phpbb\console\command\command $this->input = $input; $this->output = $output; $this->io = new SymfonyStyle($input, $output); - $this->load_resume_data(); - $name = $input->getArgument('reparser-name'); - if (isset($name)) + if (!$this->reparse_lock->acquire()) { - // Allow "post_text" to be an alias for "text_reparser.post_text" - if (!isset($this->reparsers[$name])) + $this->load_resume_data(); + + $name = $input->getArgument('reparser-name'); + if (isset($name)) { - $name = 'text_reparser.' . $name; + // Allow "post_text" to be an alias for "text_reparser.post_text" + if (!isset($this->reparsers[$name])) + { + $name = 'text_reparser.' . $name; + } + $this->reparse($name); } - $this->reparse($name); - } - else - { - foreach ($this->reparsers as $name => $service) + else { - $this->reparse($name); + foreach ($this->reparsers as $name => $service) + { + $this->reparse($name); + } } - } - $this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS')); + $this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS')); - return 0; + $this->reparse_lock->release(); + + return 0; + } + else + { + throw new runtime_exception('REPARSE_LOCK_ERROR', array(), null, 1); + } } /** -- cgit v1.2.1 From 8b0f8d7b3cf7e7687f11c2fc0a15d4919c91b6c1 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Sun, 25 Oct 2015 02:31:22 +0200 Subject: [ticket/14257] Fix lock acquire in CLI command PHPBB3-14257 --- phpBB/phpbb/console/command/reparser/reparse.php | 42 +++++++++++------------- 1 file changed, 20 insertions(+), 22 deletions(-) (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 index e77b384d8e..6fac3db854 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -174,36 +174,34 @@ class reparse extends \phpbb\console\command\command if (!$this->reparse_lock->acquire()) { - $this->load_resume_data(); + throw new runtime_exception('REPARSE_LOCK_ERROR', array(), null, 1); + } - $name = $input->getArgument('reparser-name'); - if (isset($name)) + $this->load_resume_data(); + + $name = $input->getArgument('reparser-name'); + if (isset($name)) + { + // Allow "post_text" to be an alias for "text_reparser.post_text" + if (!isset($this->reparsers[$name])) { - // Allow "post_text" to be an alias for "text_reparser.post_text" - if (!isset($this->reparsers[$name])) - { - $name = 'text_reparser.' . $name; - } - $this->reparse($name); + $name = 'text_reparser.' . $name; } - else + $this->reparse($name); + } + else + { + foreach ($this->reparsers as $name => $service) { - foreach ($this->reparsers as $name => $service) - { - $this->reparse($name); - } + $this->reparse($name); } + } - $this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS')); + $this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS')); - $this->reparse_lock->release(); + $this->reparse_lock->release(); - return 0; - } - else - { - throw new runtime_exception('REPARSE_LOCK_ERROR', array(), null, 1); - } + return 0; } /** -- cgit v1.2.1 From 25e2b17837f5b1c2330d07a86f88b25bb55d96c1 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Mon, 26 Oct 2015 01:39:52 +0100 Subject: [ticket/14257] Add text_reparser manager PHPBB3-14257 --- phpBB/phpbb/console/command/reparser/reparse.php | 54 +++++------------------- 1 file changed, 10 insertions(+), 44 deletions(-) (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 index 6fac3db854..575e447a78 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -22,11 +22,6 @@ use Symfony\Component\Console\Style\SymfonyStyle; class reparse extends \phpbb\console\command\command { - /** - * @var \phpbb\config\db_text - */ - protected $config_text; - /** * @var InputInterface */ @@ -47,6 +42,11 @@ class reparse extends \phpbb\console\command\command */ protected $reparse_lock; + /** + * @var \phpbb\textreparser\manager + */ + protected $reparser_manager; + /** * @var \phpbb\di\service_collection */ @@ -65,13 +65,13 @@ class reparse extends \phpbb\console\command\command * @param \phpbb\config\db_text $config_text * @param \phpbb\lock\db $reparse_lock */ - public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers, \phpbb\config\db_text $config_text, \phpbb\lock\db $reparse_lock) + public function __construct(\phpbb\user $user, \phpbb\lock\db $reparse_lock, \phpbb\textreparser\manager $reparser_manager, \phpbb\di\service_collection $reparsers) { require_once __DIR__ . '/../../../../includes/functions_content.php'; - $this->config_text = $config_text; - $this->reparsers = $reparsers; $this->reparse_lock = $reparse_lock; + $this->reparser_manager = $reparser_manager; + $this->reparsers = $reparsers; parent::__construct($user); } @@ -177,8 +177,6 @@ class reparse extends \phpbb\console\command\command throw new runtime_exception('REPARSE_LOCK_ERROR', array(), null, 1); } - $this->load_resume_data(); - $name = $input->getArgument('reparser-name'); if (isset($name)) { @@ -233,15 +231,6 @@ class reparse extends \phpbb\console\command\command return $value; } - /** - * Load the resume data from the database - */ - protected function load_resume_data() - { - $resume_data = $this->config_text->get('reparser_resume'); - $this->resume_data = (empty($resume_data)) ? array() : unserialize($resume_data); - } - /** * Reparse all text handled by given reparser within given range * @@ -250,6 +239,7 @@ class reparse extends \phpbb\console\command\command protected function reparse($name) { $reparser = $this->reparsers[$name]; + $this->resume_data = $this->reparser_manager->get_resume_data($name); if ($this->input->getOption('dry-run')) { $reparser->disable_save(); @@ -288,34 +278,10 @@ class reparse extends \phpbb\console\command\command $current = $start - 1; $progress->setProgress($max + 1 - $start); - $this->update_resume_data($name, $current); + $this->reparser_manager->update_resume_data($name, $min, $current, $size, !$this->input->getOption('dry-run')); } $progress->finish(); $this->io->newLine(2); } - - /** - * Save the resume data to the database - */ - protected function save_resume_data() - { - $this->config_text->set('reparser_resume', serialize($this->resume_data)); - } - - /** - * Save the resume data to the database - * - * @param string $name Reparser name - * @param string $current Current ID - */ - protected function update_resume_data($name, $current) - { - $this->resume_data[$name] = array( - 'range-min' => $this->get_option($name, 'range-min'), - 'range-max' => $current, - 'range-size' => $this->get_option($name, 'range-size'), - ); - $this->save_resume_data(); - } } -- cgit v1.2.1 From c805fd2a7378bc431ff11f93efd74fb829f558d9 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Mon, 26 Oct 2015 01:49:11 +0100 Subject: [ticket/14257] Fix phpdoc in CLI command PHPBB3-14257 --- phpBB/phpbb/console/command/reparser/reparse.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (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 index 575e447a78..6137a79b89 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -61,9 +61,9 @@ class reparse extends \phpbb\console\command\command * Constructor * * @param \phpbb\user $user - * @param \phpbb\di\service_collection $reparsers - * @param \phpbb\config\db_text $config_text * @param \phpbb\lock\db $reparse_lock + * @param \phpbb\textreparser\manager $reparser_manager + * @param \phpbb\di\service_collection $reparsers */ public function __construct(\phpbb\user $user, \phpbb\lock\db $reparse_lock, \phpbb\textreparser\manager $reparser_manager, \phpbb\di\service_collection $reparsers) { -- cgit v1.2.1 From 900ccd79af816d8d54e6974e9163d9999a823513 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Sun, 1 Nov 2015 03:49:01 +0100 Subject: [ticket/14257] Fix CLI reparser and set cron interval PHPBB3-14257 --- phpBB/phpbb/console/command/reparser/reparse.php | 31 +++++++++++------------- 1 file changed, 14 insertions(+), 17 deletions(-) (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 index 6137a79b89..ddc97a1d1d 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -53,7 +53,7 @@ class reparse extends \phpbb\console\command\command protected $reparsers; /** - * @var array Reparser names as keys, and their last $current ID as values + * @var array The reparser's last $current ID as values */ protected $resume_data; @@ -208,27 +208,18 @@ class reparse extends \phpbb\console\command\command * Will use the last saved value if --resume is set and the option was not specified * on the command line * - * @param string $reparser_name Reparser name * @param string $option_name Option name * @return integer */ - protected function get_option($reparser_name, $option_name) + protected function get_option($option_name) { // Return the option from the resume_data if applicable - if ($this->input->getOption('resume') && isset($this->resume_data[$reparser_name][$option_name]) && !$this->input->hasParameterOption('--' . $option_name)) + if ($this->input->getOption('resume') && isset($this->resume_data[$option_name]) && !$this->input->hasParameterOption('--' . $option_name)) { - return $this->resume_data[$reparser_name][$option_name]; + return $this->resume_data[$option_name]; } - $value = $this->input->getOption($option_name); - - // range-max has no default value, it must be computed for each reparser - if ($option_name === 'range-max' && $value === null) - { - $value = $this->reparsers[$reparser_name]->get_max_id(); - } - - return $value; + return $this->input->getOption($option_name); } /** @@ -250,9 +241,15 @@ class reparse extends \phpbb\console\command\command } // Start at range-max if specified or at the highest ID otherwise - $max = $this->get_option($name, 'range-max'); - $min = $this->get_option($name, 'range-min'); - $size = $this->get_option($name, 'range-size'); + $max = $this->get_option('range-max'); + $min = $this->get_option('range-min'); + $size = $this->get_option('range-size'); + + // range-max has no default value, it must be computed for each reparser + if ($max == null) + { + $max = $reparser->get_max_id(); + } if ($max < $min) { -- cgit v1.2.1