From 33500fd3728f6e3444d5479b09b941b2570ff47c Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Sun, 25 Oct 2015 02:07:40 +0100 Subject: [PATCH] [ticket/14257] Use migrations instead of cron job for some reparsers PHPBB3-14257 --- .../default/container/services_cron.yml | 52 ----------- .../db/migration/data/v320/reparse_fast.php | 87 +++++++++++++++++++ 2 files changed, 87 insertions(+), 52 deletions(-) create mode 100644 phpBB/phpbb/db/migration/data/v320/reparse_fast.php diff --git a/phpBB/config/default/container/services_cron.yml b/phpBB/config/default/container/services_cron.yml index d05e4c1b1a..53335a6101 100644 --- a/phpBB/config/default/container/services_cron.yml +++ b/phpBB/config/default/container/services_cron.yml @@ -147,58 +147,6 @@ services: tags: - { name: cron.task } - cron.task.text_reparser.contact_admin_info: - class: phpbb\cron\task\text_reparser\reparser - arguments: - - @config - - @config_text - - @text_reparser.lock - - @text_reparser_collection - calls: - - [set_name, [cron.task.text_reparser.contact_admin_info]] - - [set_reparser, [text_reparser.contact_admin_info]] - tags: - - { name: cron.task } - - cron.task.text_reparser.forum_description: - class: phpbb\cron\task\text_reparser\reparser - arguments: - - @config - - @config_text - - @text_reparser.lock - - @text_reparser_collection - calls: - - [set_name, [cron.task.text_reparser.forum_description]] - - [set_reparser, [text_reparser.forum_description]] - tags: - - { name: cron.task } - - cron.task.text_reparser.forum_rules: - class: phpbb\cron\task\text_reparser\reparser - arguments: - - @config - - @config_text - - @text_reparser.lock - - @text_reparser_collection - calls: - - [set_name, [cron.task.text_reparser.forum_rules]] - - [set_reparser, [text_reparser.forum_rules]] - tags: - - { name: cron.task } - - cron.task.text_reparser.group_description: - class: phpbb\cron\task\text_reparser\reparser - arguments: - - @config - - @config_text - - @text_reparser.lock - - @text_reparser_collection - calls: - - [set_name, [cron.task.text_reparser.group_description]] - - [set_reparser, [text_reparser.group_description]] - tags: - - { name: cron.task } - cron.task.text_reparser.pm_text: class: phpbb\cron\task\text_reparser\reparser arguments: diff --git a/phpBB/phpbb/db/migration/data/v320/reparse_fast.php b/phpBB/phpbb/db/migration/data/v320/reparse_fast.php new file mode 100644 index 0000000000..ddb11f7f67 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v320/reparse_fast.php @@ -0,0 +1,87 @@ + + * @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\db\migration\data\v320; + +class reparse_fast extends \phpbb\db\migration\container_aware_migration +{ + static public function depends_on() + { + return array('\phpbb\db\migration\data\v310\contact_admin_form'); + } + + public function effectively_installed() + { + return isset($this->config['reparse_lock']); + } + + public function update_data() + { + return array( + array('config.add', array('reparse_lock', 0, true)), + array('custom', array(array($this, 'reparse'))), + ); + } + + public function reparse($resume_data) + { + // Somtimes a cron job is too much + $limit = 200; + $fast_reparsers = array( + 'text_reparser.contact_admin_info', + 'text_reparser.forum_description', + 'text_reparser.forum_rules', + 'text_reparser.group_description', + ); + + if (!is_array($resume_data)) + { + $resume_data = array( + 'reparser' => 0, + 'current' => $this->container->get($fast_reparsers[0])->get_max_id(), + ); + } + + $fast_reparsers_size = sizeof($fast_reparsers); + $processed_records = 0; + while ($processed_records < $limit && $resume_data['reparser'] < $fast_reparsers_size) + { + $reparser = $this->container->get($fast_reparsers[$resume_data['reparser']]); + + // New reparser + if ($resume_data['current'] === 0) + { + $resume_data['current'] = $reparser->get_max_id(); + } + + $start = max(1, $resume_data['current'] + 1 - ($limit - $processed_records)); + $end = max(1, $resume_data['current']); + $reparser->reparse_range($start, $end); + + $processed_records = $end - $start + 1; + $resume_data['current'] = $start - 1; + + if ($start === 1) + { + $resume_data['reparser']++; + } + } + + if ($resume_data['reparser'] === $fast_reparsers_size) + { + return true; + } + + return $resume_data; + } +}