diff options
Diffstat (limited to 'phpBB/phpbb/cron/task')
-rw-r--r-- | phpBB/phpbb/cron/task/core/prune_all_forums.php | 23 | ||||
-rw-r--r-- | phpBB/phpbb/cron/task/core/prune_forum.php | 2 | ||||
-rw-r--r-- | phpBB/phpbb/cron/task/core/prune_shadow_topics.php | 2 | ||||
-rw-r--r-- | phpBB/phpbb/cron/task/core/queue.php | 19 | ||||
-rw-r--r-- | phpBB/phpbb/cron/task/core/tidy_plupload.php | 18 | ||||
-rw-r--r-- | phpBB/phpbb/cron/task/core/update_hashes.php | 6 | ||||
-rw-r--r-- | phpBB/phpbb/cron/task/text_reparser/reparser.php | 168 |
7 files changed, 211 insertions, 27 deletions
diff --git a/phpBB/phpbb/cron/task/core/prune_all_forums.php b/phpBB/phpbb/cron/task/core/prune_all_forums.php index b47939ccbe..5005f5b894 100644 --- a/phpBB/phpbb/cron/task/core/prune_all_forums.php +++ b/phpBB/phpbb/cron/task/core/prune_all_forums.php @@ -55,21 +55,26 @@ class prune_all_forums extends \phpbb\cron\task\base include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext); } - $sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq - FROM ' . FORUMS_TABLE . " - WHERE enable_prune = 1 - AND prune_next < " . time(); + $sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, enable_shadow_prune, prune_shadow_days, prune_shadow_freq, prune_shadow_next, forum_flags, prune_freq + FROM ' . FORUMS_TABLE; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - if ($row['prune_days']) + if ($row['enable_prune'] && $row['prune_next'] < time()) { - auto_prune($row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']); - } + if ($row['prune_days']) + { + auto_prune($row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']); + } - if ($row['prune_viewed']) + if ($row['prune_viewed']) + { + auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']); + } + } + if ($row['enable_shadow_prune'] && $row['prune_shadow_next'] < time() && $row['prune_shadow_days']) { - auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']); + auto_prune($row['forum_id'], 'shadow', $row['forum_flags'], $row['prune_shadow_days'], $row['prune_shadow_freq']); } } $this->db->sql_freeresult($result); diff --git a/phpBB/phpbb/cron/task/core/prune_forum.php b/phpBB/phpbb/cron/task/core/prune_forum.php index ba68565197..abf91aee19 100644 --- a/phpBB/phpbb/cron/task/core/prune_forum.php +++ b/phpBB/phpbb/cron/task/core/prune_forum.php @@ -31,7 +31,7 @@ class prune_forum extends \phpbb\cron\task\base implements \phpbb\cron\task\para * If $forum_data is given, it is assumed to contain necessary information * about a single forum that is to be pruned. * - * If $forum_data is not given, forum id will be retrieved via request_var + * If $forum_data is not given, forum id will be retrieved via $request->variable() * and a database query will be performed to load the necessary information * about the forum. */ diff --git a/phpBB/phpbb/cron/task/core/prune_shadow_topics.php b/phpBB/phpbb/cron/task/core/prune_shadow_topics.php index 97a4b0ea86..0ab59f9ed5 100644 --- a/phpBB/phpbb/cron/task/core/prune_shadow_topics.php +++ b/phpBB/phpbb/cron/task/core/prune_shadow_topics.php @@ -33,7 +33,7 @@ class prune_shadow_topics extends \phpbb\cron\task\base implements \phpbb\cron\t * If $forum_data is given, it is assumed to contain necessary information * about a single forum that is to be pruned. * - * If $forum_data is not given, forum id will be retrieved via request_var + * If $forum_data is not given, forum id will be retrieved via $request->variable() * and a database query will be performed to load the necessary information * about the forum. */ diff --git a/phpBB/phpbb/cron/task/core/queue.php b/phpBB/phpbb/cron/task/core/queue.php index a9345a44df..eca69a5041 100644 --- a/phpBB/phpbb/cron/task/core/queue.php +++ b/phpBB/phpbb/cron/task/core/queue.php @@ -20,20 +20,23 @@ class queue extends \phpbb\cron\task\base { protected $phpbb_root_path; protected $php_ext; + protected $cache_dir; protected $config; /** - * Constructor. - * - * @param string $phpbb_root_path The root path - * @param string $php_ext PHP file extension - * @param \phpbb\config\config $config The config - */ - public function __construct($phpbb_root_path, $php_ext, \phpbb\config\config $config) + * Constructor. + * + * @param string $phpbb_root_path The root path + * @param string $php_ext PHP file extension + * @param \phpbb\config\config $config The config + * @param string $cache_dir phpBB cache directory + */ + public function __construct($phpbb_root_path, $php_ext, \phpbb\config\config $config, $cache_dir) { $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; $this->config = $config; + $this->cache_dir = $cache_dir; } /** @@ -60,7 +63,7 @@ class queue extends \phpbb\cron\task\base */ public function is_runnable() { - return file_exists($this->phpbb_root_path . 'cache/queue.' . $this->php_ext); + return file_exists($this->cache_dir . 'queue.' . $this->php_ext); } /** diff --git a/phpBB/phpbb/cron/task/core/tidy_plupload.php b/phpBB/phpbb/cron/task/core/tidy_plupload.php index b6aeecf4b4..37d0e9b21a 100644 --- a/phpBB/phpbb/cron/task/core/tidy_plupload.php +++ b/phpBB/phpbb/cron/task/core/tidy_plupload.php @@ -42,6 +42,12 @@ class tidy_plupload extends \phpbb\cron\task\base */ protected $config; + /** @var \phpbb\log\log_interface */ + protected $log; + + /** @var \phpbb\user */ + protected $user; + /** * Directory where plupload stores temporary files. * @var string @@ -53,11 +59,15 @@ class tidy_plupload extends \phpbb\cron\task\base * * @param string $phpbb_root_path The root path * @param \phpbb\config\config $config The config + * @param \phpbb\log\log_interface $log Log + * @param \phpbb\user $user User object */ - public function __construct($phpbb_root_path, \phpbb\config\config $config) + public function __construct($phpbb_root_path, \phpbb\config\config $config, \phpbb\log\log_interface $log, \phpbb\user $user) { $this->phpbb_root_path = $phpbb_root_path; $this->config = $config; + $this->log = $log; + $this->user = $user; $this->plupload_upload_path = $this->phpbb_root_path . $this->config['upload_path'] . '/plupload'; } @@ -88,13 +98,11 @@ class tidy_plupload extends \phpbb\cron\task\base } catch (\UnexpectedValueException $e) { - add_log( - 'critical', - 'LOG_PLUPLOAD_TIDY_FAILED', + $this->log->add('critical', $this->user->data['user_id'], $this->user->ip, 'LOG_PLUPLOAD_TIDY_FAILED', false, array( $this->plupload_upload_path, $e->getMessage(), $e->getTraceAsString() - ); + )); } $this->config->set('plupload_last_gc', time(), true); diff --git a/phpBB/phpbb/cron/task/core/update_hashes.php b/phpBB/phpbb/cron/task/core/update_hashes.php index a4fe477d99..ba095abc8b 100644 --- a/phpBB/phpbb/cron/task/core/update_hashes.php +++ b/phpBB/phpbb/cron/task/core/update_hashes.php @@ -111,9 +111,9 @@ class update_hashes extends \phpbb\cron\task\base // Increase number so we know that users were selected from the database $affected_rows++; - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_password = "' . $this->db->sql_escape($new_hash) . '" - WHERE user_id = ' . (int) $row['user_id']; + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_password = '" . $this->db->sql_escape($new_hash) . "' + WHERE user_id = " . (int) $row['user_id']; $this->db->sql_query($sql); } diff --git a/phpBB/phpbb/cron/task/text_reparser/reparser.php b/phpBB/phpbb/cron/task/text_reparser/reparser.php new file mode 100644 index 0000000000..fa3bc67325 --- /dev/null +++ b/phpBB/phpbb/cron/task/text_reparser/reparser.php @@ -0,0 +1,168 @@ +<?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\cron\task\text_reparser; + +/** + * Reparse text cron task + */ +class reparser extends \phpbb\cron\task\base +{ + const MIN = 1; + const SIZE = 100; + + /** + * @var \phpbb\config\config + */ + protected $config; + + /** + * @var \phpbb\config\db_text + */ + protected $config_text; + + /** + * @var \phpbb\lock\db + */ + protected $reparse_lock; + + /** + * @var \phpbb\textreparser\manager + */ + protected $reparser_manager; + + /** + * @var string + */ + protected $reparser_name; + + /** + * @var \phpbb\di\service_collection + */ + protected $reparsers; + + /** + * @var array + */ + protected $resume_data; + + /** + * Constructor + * + * @param \phpbb\config\config $config + * @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\config\config $config, \phpbb\config\db_text $config_text, \phpbb\lock\db $reparse_lock, \phpbb\textreparser\manager $reparser_manager, \phpbb\di\service_collection $reparsers) + { + $this->config = $config; + $this->config_text = $config_text; + $this->reparse_lock = $reparse_lock; + $this->reparser_manager = $reparser_manager; + $this->reparsers = $reparsers; + } + + /** + * Sets the reparser for this cron task + * + * @param string $reparser + */ + public function set_reparser($reparser) + { + $this->reparser_name = !isset($this->reparsers[$reparser]) ? $this->reparser_manager->find_reparser($reparser) : $reparser; + + if ($this->resume_data === null) + { + $this->resume_data = $this->reparser_manager->get_resume_data($this->reparser_name); + } + } + + /** + * {@inheritdoc} + */ + public function is_runnable() + { + if ($this->resume_data === null) + { + $this->resume_data = $this->reparser_manager->get_resume_data($this->reparser_name); + } + + if (!isset($this->resume_data['range-max']) || $this->resume_data['range-max'] >= $this->resume_data['range-min']) + { + return true; + } + + return false; + } + + /** + * {@inheritdoc} + */ + public function should_run() + { + if (!empty($this->config['reparse_lock'])) + { + $last_run = explode(' ', $this->config['reparse_lock']); + + if ($last_run[0] + 3600 >= time()) + { + return false; + } + } + + if ($this->config[$this->reparser_name . '_cron_interval']) + { + return $this->config[$this->reparser_name . '_last_cron'] < time() - $this->config[$this->reparser_name . '_cron_interval']; + } + + return false; + } + + /** + * {@inheritdoc} + */ + public function run() + { + if ($this->reparse_lock->acquire()) + { + if ($this->resume_data === null) + { + $this->resume_data = $this->reparser_manager->get_resume_data($this->reparser_name); + } + + /** + * @var \phpbb\textreparser\reparser_interface $reparser + */ + $reparser = $this->reparsers[$this->reparser_name]; + + $min = isset($this->resume_data['range-min']) ? $this->resume_data['range-min'] : self::MIN; + $current = isset($this->resume_data['range-max']) ? $this->resume_data['range-max'] : $reparser->get_max_id(); + $size = isset($this->resume_data['range-size']) ? $this->resume_data['range-size'] : self::SIZE; + + if ($current >= $min) + { + $start = max($min, $current + 1 - $size); + $end = max($min, $current); + + $reparser->reparse_range($start, $end); + + $this->reparser_manager->update_resume_data($this->reparser_name, $min, $start - 1, $size); + } + + $this->config->set($this->reparser_name . '_last_cron', time()); + $this->reparse_lock->release(); + } + } +} |