aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/cron/task/core
diff options
context:
space:
mode:
authorIgor Wiedler <igor@wiedler.ch>2010-10-28 21:35:53 +0200
committerOleg Pudeyev <oleg@bsdpower.com>2011-02-12 22:05:51 -0500
commit794d376be4d3587f21bf7149de428a37deaa71c8 (patch)
treec57dda93fd686806b3a2b29b7281e55a2ef5ed35 /phpBB/includes/cron/task/core
parent1c7d29783b9b1a103265cfe62b4a62dbe81fa85a (diff)
downloadforums-794d376be4d3587f21bf7149de428a37deaa71c8.tar
forums-794d376be4d3587f21bf7149de428a37deaa71c8.tar.gz
forums-794d376be4d3587f21bf7149de428a37deaa71c8.tar.bz2
forums-794d376be4d3587f21bf7149de428a37deaa71c8.tar.xz
forums-794d376be4d3587f21bf7149de428a37deaa71c8.zip
[feature/system-cron] rename tasks to task
PHPBB3-9596
Diffstat (limited to 'phpBB/includes/cron/task/core')
-rw-r--r--phpBB/includes/cron/task/core/prune_all_forums.php74
-rw-r--r--phpBB/includes/cron/task/core/prune_forum.php139
-rw-r--r--phpBB/includes/cron/task/core/queue.php73
-rw-r--r--phpBB/includes/cron/task/core/tidy_cache.php58
-rw-r--r--phpBB/includes/cron/task/core/tidy_database.php53
-rw-r--r--phpBB/includes/cron/task/core/tidy_search.php80
-rw-r--r--phpBB/includes/cron/task/core/tidy_sessions.php49
-rw-r--r--phpBB/includes/cron/task/core/tidy_warnings.php64
8 files changed, 590 insertions, 0 deletions
diff --git a/phpBB/includes/cron/task/core/prune_all_forums.php b/phpBB/includes/cron/task/core/prune_all_forums.php
new file mode 100644
index 0000000000..de7ea557b0
--- /dev/null
+++ b/phpBB/includes/cron/task/core/prune_all_forums.php
@@ -0,0 +1,74 @@
+<?php
+/**
+*
+* @package phpBB3
+* @version $Id$
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+if (!class_exists('cron_task_base'))
+{
+ include($phpbb_root_path . 'includes/cron/cron_task_base.' . $phpEx);
+}
+
+/**
+* Prune all forums cron task.
+*
+* It is intended to be invoked from system cron.
+* This task will find all forums for which pruning is enabled, and will
+* prune all forums as necessary.
+*
+* @package phpBB3
+*/
+class cron_task_core_prune_all_forums extends cron_task_base
+{
+ /**
+ * Runs this cron task.
+ */
+ public function run()
+ {
+ global $phpbb_root_path, $phpEx, $db;
+
+ if (!function_exists('auto_prune'))
+ {
+ include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
+ }
+
+ $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();
+ $result = $db->sql_query($sql);
+ while ($row = $db->sql_fetchrow($result))
+ {
+ if ($row['prune_days'])
+ {
+ auto_prune($row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']);
+ }
+
+ if ($row['prune_viewed'])
+ {
+ auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']);
+ }
+ }
+ $db->sql_freeresult($result);
+ }
+
+ /**
+ * Returns whether this cron task can run, given current board configuration.
+ */
+ public function is_runnable()
+ {
+ global $config;
+ return (bool) $config['use_system_cron'];
+ }
+}
diff --git a/phpBB/includes/cron/task/core/prune_forum.php b/phpBB/includes/cron/task/core/prune_forum.php
new file mode 100644
index 0000000000..7728932d7e
--- /dev/null
+++ b/phpBB/includes/cron/task/core/prune_forum.php
@@ -0,0 +1,139 @@
+<?php
+/**
+*
+* @package phpBB3
+* @version $Id$
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+if (!class_exists('cron_task_base'))
+{
+ include($phpbb_root_path . 'includes/cron/cron_task_base.' . $phpEx);
+}
+
+/**
+* Prune one forum cron task.
+*
+* It is intended to be used when cron is invoked via web.
+* This task can decide whether it should be run using data obtained by viewforum
+* code, without making additional database queries.
+*
+* @package phpBB3
+*/
+class cron_task_core_prune_forum extends cron_task_base implements parametrized_cron_task
+{
+ private $forum_data;
+
+ /**
+ * Constructor.
+ *
+ * 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
+ * and a database query will be performed to load the necessary information
+ * about the forum.
+ */
+ public function __construct($forum_data=null)
+ {
+ global $db;
+ if ($forum_data)
+ {
+ $this->forum_data = $forum_data;
+ }
+ else
+ {
+ $this->forum_data = null;
+ }
+ }
+
+ /**
+ * Runs this cron task.
+ */
+ public function run()
+ {
+ global $phpbb_root_path, $phpEx;
+ if (!function_exists('auto_prune'))
+ {
+ include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
+ }
+
+ if ($this->forum_data['prune_days'])
+ {
+ auto_prune($this->forum_data['forum_id'], 'posted', $this->forum_data['forum_flags'], $this->forum_data['prune_days'], $this->forum_data['prune_freq']);
+ }
+
+ if ($this->forum_data['prune_viewed'])
+ {
+ auto_prune($this->forum_data['forum_id'], 'viewed', $this->forum_data['forum_flags'], $this->forum_data['prune_viewed'], $this->forum_data['prune_freq']);
+ }
+ }
+
+ /**
+ * Returns whether this cron task can run, given current board configuration.
+ */
+ public function is_runnable()
+ {
+ global $config;
+ return !$config['use_system_cron'] && $this->forum_data;
+ }
+
+ /**
+ * Returns whether this cron task should run now, because enough time
+ * has passed since it was last run.
+ */
+ public function should_run()
+ {
+ return $this->forum_data['enable_prune'] && $this->forum_data['prune_next'] < time();
+ }
+
+ /**
+ * Returns parameters of this cron task as an array.
+ *
+ * The array has one key, f, whose value is id of the forum to be pruned.
+ */
+ public function get_parameters()
+ {
+ return array('f' => $this->forum_data['forum_id']);
+ }
+
+ /**
+ * Parses parameters found in $params, which is an array.
+ *
+ * $params may contain user input and is not trusted.
+ *
+ * $params is expected to have a key f whose value is id of the forum to be pruned.
+ */
+ public function parse_parameters($params)
+ {
+ global $db;
+
+ $this->forum_data = null;
+ if (isset($params['f']))
+ {
+ $forum_id = (int) $params['f'];
+
+ $sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq
+ FROM ' . FORUMS_TABLE . "
+ WHERE forum_id = $forum_id";
+ $result = $db->sql_query($sql);
+ $row = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
+
+ if ($row)
+ {
+ $this->forum_data = $row;
+ }
+ }
+ }
+}
diff --git a/phpBB/includes/cron/task/core/queue.php b/phpBB/includes/cron/task/core/queue.php
new file mode 100644
index 0000000000..dffaf5aed4
--- /dev/null
+++ b/phpBB/includes/cron/task/core/queue.php
@@ -0,0 +1,73 @@
+<?php
+/**
+*
+* @package phpBB3
+* @version $Id$
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+if (!class_exists('cron_task_base'))
+{
+ include($phpbb_root_path . 'includes/cron/cron_task_base.' . $phpEx);
+}
+
+/**
+* Queue cron task. Sends email and jabber messages queued by other scripts.
+*
+* @package phpBB3
+*/
+class cron_task_core_queue extends cron_task_base
+{
+ /**
+ * Runs this cron task.
+ */
+ public function run()
+ {
+ global $phpbb_root_path, $phpEx;
+ if (!class_exists('queue'))
+ {
+ include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
+ }
+ $queue = new queue();
+ $queue->process();
+ }
+
+ /**
+ * Returns whether this cron task can run, given current board configuration.
+ */
+ public function is_runnable()
+ {
+ global $phpbb_root_path, $phpEx;
+ return file_exists($phpbb_root_path . 'cache/queue.' . $phpEx);
+ }
+
+ /**
+ * Returns whether this cron task should run now, because enough time
+ * has passed since it was last run.
+ */
+ public function should_run()
+ {
+ global $config;
+ return $config['last_queue_run'] < time() - $config['queue_interval_config'];
+ }
+
+ /**
+ * Returns whether this cron task can be run in shutdown function.
+ */
+ public function is_shutdown_function_safe()
+ {
+ global $config;
+ // A user reported using the mail() function while using shutdown does not work. We do not want to risk that.
+ return !$config['smtp_delivery'];
+ }
+}
diff --git a/phpBB/includes/cron/task/core/tidy_cache.php b/phpBB/includes/cron/task/core/tidy_cache.php
new file mode 100644
index 0000000000..72843ba680
--- /dev/null
+++ b/phpBB/includes/cron/task/core/tidy_cache.php
@@ -0,0 +1,58 @@
+<?php
+/**
+*
+* @package phpBB3
+* @version $Id$
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+if (!class_exists('cron_task_base'))
+{
+ include($phpbb_root_path . 'includes/cron/cron_task_base.' . $phpEx);
+}
+
+/**
+* Tidy cache cron task.
+*
+* @package phpBB3
+*/
+class cron_task_core_tidy_cache extends cron_task_base
+{
+ /**
+ * Runs this cron task.
+ */
+ public function run()
+ {
+ global $cache;
+ $cache->tidy();
+ }
+
+ /**
+ * Returns whether this cron task can run, given current board configuration.
+ */
+ public function is_runnable()
+ {
+ global $cache;
+ return method_exists($cache, 'tidy');
+ }
+
+ /**
+ * Returns whether this cron task should run now, because enough time
+ * has passed since it was last run.
+ */
+ public function should_run()
+ {
+ global $config;
+ return $config['cache_last_gc'] < time() - $config['cache_gc'];
+ }
+}
diff --git a/phpBB/includes/cron/task/core/tidy_database.php b/phpBB/includes/cron/task/core/tidy_database.php
new file mode 100644
index 0000000000..6724ec092e
--- /dev/null
+++ b/phpBB/includes/cron/task/core/tidy_database.php
@@ -0,0 +1,53 @@
+<?php
+/**
+*
+* @package phpBB3
+* @version $Id$
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+if (!class_exists('cron_task_base'))
+{
+ include($phpbb_root_path . 'includes/cron/cron_task_base.' . $phpEx);
+}
+
+/**
+* Tidy database cron task.
+*
+* @package phpBB3
+*/
+class cron_task_core_tidy_database extends cron_task_base
+{
+ /**
+ * Runs this cron task.
+ */
+ public function run()
+ {
+ global $phpbb_root_path, $phpEx;
+ if (!function_exists('tidy_database'))
+ {
+ include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
+ }
+ tidy_database();
+ }
+
+ /**
+ * Returns whether this cron task should run now, because enough time
+ * has passed since it was last run.
+ */
+ public function should_run()
+ {
+ global $config;
+ return $config['database_last_gc'] < time() - $config['database_gc'];
+ }
+}
diff --git a/phpBB/includes/cron/task/core/tidy_search.php b/phpBB/includes/cron/task/core/tidy_search.php
new file mode 100644
index 0000000000..e821310c9f
--- /dev/null
+++ b/phpBB/includes/cron/task/core/tidy_search.php
@@ -0,0 +1,80 @@
+<?php
+/**
+*
+* @package phpBB3
+* @version $Id$
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+if (!class_exists('cron_task_base'))
+{
+ include($phpbb_root_path . 'includes/cron/cron_task_base.' . $phpEx);
+}
+
+/**
+* Tidy search cron task.
+*
+* Will only run when the currently selected search backend supports tidying.
+*
+* @package phpBB3
+*/
+class cron_task_core_tidy_search extends cron_task_base
+{
+ /**
+ * Runs this cron task.
+ */
+ public function run()
+ {
+ global $phpbb_root_path, $phpEx, $config, $error;
+
+ // Select the search method
+ $search_type = basename($config['search_type']);
+
+ if (!class_exists($search_type))
+ {
+ include("{$phpbb_root_path}includes/search/$search_type.$phpEx");
+ }
+
+ // We do some additional checks in the module to ensure it can actually be utilised
+ $error = false;
+ $search = new $search_type($error);
+
+ if (!$error)
+ {
+ $search->tidy();
+ }
+ }
+
+ /**
+ * Returns whether this cron task can run, given current board configuration.
+ */
+ public function is_runnable()
+ {
+ global $phpbb_root_path, $phpEx, $config;
+
+ // Select the search method
+ $search_type = basename($config['search_type']);
+
+ return file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx);
+ }
+
+ /**
+ * Returns whether this cron task should run now, because enough time
+ * has passed since it was last run.
+ */
+ public function should_run()
+ {
+ global $config;
+ return $config['search_last_gc'] < time() - $config['search_gc'];
+ }
+}
diff --git a/phpBB/includes/cron/task/core/tidy_sessions.php b/phpBB/includes/cron/task/core/tidy_sessions.php
new file mode 100644
index 0000000000..ecf0be3978
--- /dev/null
+++ b/phpBB/includes/cron/task/core/tidy_sessions.php
@@ -0,0 +1,49 @@
+<?php
+/**
+*
+* @package phpBB3
+* @version $Id$
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+if (!class_exists('cron_task_base'))
+{
+ include($phpbb_root_path . 'includes/cron/cron_task_base.' . $phpEx);
+}
+
+/**
+* Tidy sessions cron task.
+*
+* @package phpBB3
+*/
+class cron_task_core_tidy_sessions extends cron_task_base
+{
+ /**
+ * Runs this cron task.
+ */
+ public function run()
+ {
+ global $user;
+ $user->session_gc();
+ }
+
+ /**
+ * Returns whether this cron task should run now, because enough time
+ * has passed since it was last run.
+ */
+ public function should_run()
+ {
+ global $config;
+ return $config['session_last_gc'] < time() - $config['session_gc'];
+ }
+}
diff --git a/phpBB/includes/cron/task/core/tidy_warnings.php b/phpBB/includes/cron/task/core/tidy_warnings.php
new file mode 100644
index 0000000000..6ef6a17fab
--- /dev/null
+++ b/phpBB/includes/cron/task/core/tidy_warnings.php
@@ -0,0 +1,64 @@
+<?php
+/**
+*
+* @package phpBB3
+* @version $Id$
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+if (!class_exists('cron_task_base'))
+{
+ include($phpbb_root_path . 'includes/cron/cron_task_base.' . $phpEx);
+}
+
+/**
+* Tidy warnings cron task.
+*
+* Will only run when warnings are configured to expire.
+*
+* @package phpBB3
+*/
+class cron_task_core_tidy_warnings extends cron_task_base
+{
+ /**
+ * Runs this cron task.
+ */
+ public function run()
+ {
+ global $phpbb_root_path, $phpEx;
+ if (!function_exists('tidy_warnings'))
+ {
+ include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
+ }
+ tidy_warnings();
+ }
+
+ /**
+ * Returns whether this cron task can run, given current board configuration.
+ */
+ public function is_runnable()
+ {
+ global $config;
+ return (bool) $config['warnings_expire_days'];
+ }
+
+ /**
+ * Returns whether this cron task should run now, because enough time
+ * has passed since it was last run.
+ */
+ public function should_run()
+ {
+ global $config;
+ return $config['warnings_last_gc'] < time() - $config['warnings_gc'];
+ }
+}