aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/cron/task/core
diff options
context:
space:
mode:
authorIgor Wiedler <igor@wiedler.ch>2011-02-13 15:54:42 +0100
committerIgor Wiedler <igor@wiedler.ch>2011-02-13 15:54:42 +0100
commit04bd2e640e771948671ab6554df8962de980f511 (patch)
treed1e5a226ca875e940d1d98c710051d1911d8b2ad /phpBB/includes/cron/task/core
parent8f0e9aee5ce518937b7ed05c2cd602e85e5b0b8a (diff)
parent1fd8d6de7f6bb41505530c83e487a9dc18bd25af (diff)
downloadforums-04bd2e640e771948671ab6554df8962de980f511.tar
forums-04bd2e640e771948671ab6554df8962de980f511.tar.gz
forums-04bd2e640e771948671ab6554df8962de980f511.tar.bz2
forums-04bd2e640e771948671ab6554df8962de980f511.tar.xz
forums-04bd2e640e771948671ab6554df8962de980f511.zip
Merge branch 'feature/system-cron' into develop
* feature/system-cron: (67 commits) [feature/system-cron] More tests for cron manager. [feature/system-cron] Added documentation for cron manager constructor. [feature/system-cron] Remove an unecessary assignment and an unecessary comment [feature/system-cron] Clarify comments about flush() call in cron. [feature/system-cron] preg_match returns int so cast to bool, fix comment [feature/system-cron] Rename lock() to acquire and unlock() to release. [feature/system-cron] Cache cron's task names. [feature/system-cron] Use a RecursiveDirectoryIterator instead of readdir. [feature/system-cron] Add array type hints if appropriate and remove globals. [feature/system-cron] Make use of the new config class in locks. [feature/system-cron] Fix duplicate instantiation of class loader in tests. [feature/system-cron] Abstract the database locking mechanism out of cron. [feature/system-cron] Move tests to phpunit.xml and always load class loader [feature/system-cron] Basic tests for cron manager. [feature/system-cron] Added @param/@return documentation [feature/system-cron] Add phpDoc documentation for everything else. [feature/system-cron] Cast result in cron_manager::is_valid_name() to bool. [feature/system-cron] Add phpDoc documentation for phpbb_cron_manager class. [feature/system-cron] Add phpDoc documentation for phpbb_cron_lock class. [feature/system-cron] Adjust SQL query style to follow coding guidelines. ...
Diffstat (limited to 'phpBB/includes/cron/task/core')
-rw-r--r--phpBB/includes/cron/task/core/prune_all_forums.php75
-rw-r--r--phpBB/includes/cron/task/core/prune_forum.php153
-rw-r--r--phpBB/includes/cron/task/core/queue.php84
-rw-r--r--phpBB/includes/cron/task/core/tidy_cache.php64
-rw-r--r--phpBB/includes/cron/task/core/tidy_database.php54
-rw-r--r--phpBB/includes/cron/task/core/tidy_search.php87
-rw-r--r--phpBB/includes/cron/task/core/tidy_sessions.php50
-rw-r--r--phpBB/includes/cron/task/core/tidy_warnings.php69
8 files changed, 636 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..39b5765229
--- /dev/null
+++ b/phpBB/includes/cron/task/core/prune_all_forums.php
@@ -0,0 +1,75 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* 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 phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base
+{
+ /**
+ * Runs this cron task.
+ *
+ * @return void
+ */
+ 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.
+ *
+ * This cron task will only run when system cron is utilised.
+ *
+ * @return bool
+ */
+ 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..55b1c58cd4
--- /dev/null
+++ b/phpBB/includes/cron/task/core/prune_forum.php
@@ -0,0 +1,153 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* 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 phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements phpbb_cron_task_parametrized
+{
+ 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.
+ *
+ * @param array $forum_data Information about a forum to be pruned.
+ */
+ 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.
+ *
+ * @return void
+ */
+ 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.
+ *
+ * This cron task will not run when system cron is utilised, as in
+ * such cases prune_all_forums task would run instead.
+ *
+ * Additionally, this task must be given the forum data, either via
+ * the constructor or parse_parameters method.
+ *
+ * @return bool
+ */
+ 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.
+ *
+ * Forum pruning interval is specified in the forum data.
+ *
+ * @return bool
+ */
+ 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.
+ *
+ * @return array
+ */
+ public function get_parameters()
+ {
+ return array('f' => $this->forum_data['forum_id']);
+ }
+
+ /**
+ * Parses parameters found in $request, which is an instance of
+ * phpbb_request_interface.
+ *
+ * It is expected to have a key f whose value is id of the forum to be pruned.
+ *
+ * @param phpbb_request_interface $request Request object.
+ *
+ * @return void
+ */
+ public function parse_parameters(phpbb_request_interface $request)
+ {
+ global $db;
+
+ $this->forum_data = null;
+ if ($request->is_set('f'))
+ {
+ $forum_id = $request->variable('f', 0);
+
+ $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..0e9de05984
--- /dev/null
+++ b/phpBB/includes/cron/task/core/queue.php
@@ -0,0 +1,84 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* Queue cron task. Sends email and jabber messages queued by other scripts.
+*
+* @package phpBB3
+*/
+class phpbb_cron_task_core_queue extends phpbb_cron_task_base
+{
+ /**
+ * Runs this cron task.
+ *
+ * @return void
+ */
+ 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.
+ *
+ * Queue task is only run if the email queue (file) exists.
+ *
+ * @return bool
+ */
+ 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.
+ *
+ * The interval between queue runs is specified in board configuration.
+ *
+ * @return bool
+ */
+ 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.
+ *
+ * A user reported that using the mail() function during shutdown
+ * function execution does not work. Therefore if email is delivered
+ * via the mail() function (as opposed to SMTP) queue cron task marks
+ * itself shutdown function-unsafe.
+ *
+ * @return bool
+ */
+ 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..793ce746b4
--- /dev/null
+++ b/phpBB/includes/cron/task/core/tidy_cache.php
@@ -0,0 +1,64 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* Tidy cache cron task.
+*
+* @package phpBB3
+*/
+class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base
+{
+ /**
+ * Runs this cron task.
+ *
+ * @return void
+ */
+ public function run()
+ {
+ global $cache;
+ $cache->tidy();
+ }
+
+ /**
+ * Returns whether this cron task can run, given current board configuration.
+ *
+ * Tidy cache cron task runs if the cache implementation in use
+ * supports tidying.
+ *
+ * @return bool
+ */
+ 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.
+ *
+ * The interval between cache tidying is specified in board
+ * configuration.
+ *
+ * @return bool
+ */
+ 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..fb0e81eaba
--- /dev/null
+++ b/phpBB/includes/cron/task/core/tidy_database.php
@@ -0,0 +1,54 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* Tidy database cron task.
+*
+* @package phpBB3
+*/
+class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base
+{
+ /**
+ * Runs this cron task.
+ *
+ * @return void
+ */
+ 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.
+ *
+ * The interval between database tidying is specified in board
+ * configuration.
+ *
+ * @return bool
+ */
+ 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..dcc78abbb8
--- /dev/null
+++ b/phpBB/includes/cron/task/core/tidy_search.php
@@ -0,0 +1,87 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* Tidy search cron task.
+*
+* Will only run when the currently selected search backend supports tidying.
+*
+* @package phpBB3
+*/
+class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base
+{
+ /**
+ * Runs this cron task.
+ *
+ * @return void
+ */
+ 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.
+ *
+ * Search cron task is runnable in all normal use. It may not be
+ * runnable if the search backend implementation selected in board
+ * configuration does not exist.
+ *
+ * @return bool
+ */
+ 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.
+ *
+ * The interval between search tidying is specified in board
+ * configuration.
+ *
+ * @return bool
+ */
+ 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..81e7e6a147
--- /dev/null
+++ b/phpBB/includes/cron/task/core/tidy_sessions.php
@@ -0,0 +1,50 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* Tidy sessions cron task.
+*
+* @package phpBB3
+*/
+class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base
+{
+ /**
+ * Runs this cron task.
+ *
+ * @return void
+ */
+ 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.
+ *
+ * The interval between session tidying is specified in board
+ * configuration.
+ *
+ * @return bool
+ */
+ 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..e7d4cc9eea
--- /dev/null
+++ b/phpBB/includes/cron/task/core/tidy_warnings.php
@@ -0,0 +1,69 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* Tidy warnings cron task.
+*
+* Will only run when warnings are configured to expire.
+*
+* @package phpBB3
+*/
+class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base
+{
+ /**
+ * Runs this cron task.
+ *
+ * @return void
+ */
+ 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.
+ *
+ * If warnings are set to never expire, this cron task will not run.
+ *
+ * @return bool
+ */
+ 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.
+ *
+ * The interval between warnings tidying is specified in board
+ * configuration.
+ *
+ * @return bool
+ */
+ public function should_run()
+ {
+ global $config;
+ return $config['warnings_last_gc'] < time() - $config['warnings_gc'];
+ }
+}