aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/includes/cron_task.php60
-rw-r--r--phpBB/includes/cron_task_base.php64
-rw-r--r--phpBB/includes/cron_tasks/standard/prune_all_forums.php45
-rw-r--r--phpBB/includes/cron_tasks/standard/prune_forum.php67
-rw-r--r--phpBB/includes/cron_tasks/standard/queue.php64
-rw-r--r--phpBB/includes/cron_tasks/standard/tidy_cache.php53
-rw-r--r--phpBB/includes/cron_tasks/standard/tidy_database.php44
-rw-r--r--phpBB/includes/cron_tasks/standard/tidy_search.php72
-rw-r--r--phpBB/includes/cron_tasks/standard/tidy_sessions.php44
-rw-r--r--phpBB/includes/cron_tasks/standard/tidy_warnings.php56
10 files changed, 569 insertions, 0 deletions
diff --git a/phpBB/includes/cron_task.php b/phpBB/includes/cron_task.php
new file mode 100644
index 0000000000..8b9ffacae6
--- /dev/null
+++ b/phpBB/includes/cron_task.php
@@ -0,0 +1,60 @@
+<?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;
+}
+
+/**
+* Cron task interface
+* @package phpBB3
+*/
+interface cron_task
+{
+ /**
+ * Runs this cron task.
+ */
+ public function run();
+
+ /**
+ * Returns whether this cron task can run, given current board configuration.
+ *
+ * For example, a cron task that prunes forums can only run when
+ * forum pruning is enabled.
+ */
+ public function is_runnable();
+
+ /**
+ * Returns whether this cron task should run now, because enough time
+ * has passed since it was last run.
+ */
+ public function should_run();
+
+ /**
+ * Returns whether this cron task can be run in shutdown function.
+ */
+ public function is_shutdown_function_safe();
+}
+
+/**
+* Parametrized cron task interface
+* @package phpBB3
+*/
+interface parametrized_cron_task extends cron_task
+{
+ /**
+ * Returns parameters of this cron task as a query string.
+ */
+ public function get_url_query_string();
+}
diff --git a/phpBB/includes/cron_task_base.php b/phpBB/includes/cron_task_base.php
new file mode 100644
index 0000000000..f66894e7b2
--- /dev/null
+++ b/phpBB/includes/cron_task_base.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;
+}
+
+/**
+* Cron task base class. Provides sensible defaults for cron tasks
+* and partially implements cron task interface, making writing cron tasks easier.
+*
+* At a minimum, subclasses must override the run() method.
+*
+* Cron tasks need not inherit from this base class. If desired,
+* they may implement cron task interface directly.
+*
+* @package phpBB3
+*/
+abstract class cron_task_base
+{
+ /**
+ * Runs this cron task.
+ */
+ abstract public function run();
+
+ /**
+ * Returns whether this cron task can run, given current board configuration.
+ *
+ * For example, a cron task that prunes forums can only run when
+ * forum pruning is enabled.
+ */
+ public function is_runnable()
+ {
+ return true;
+ }
+
+ /**
+ * Returns whether this cron task should run now, because enough time
+ * has passed since it was last run.
+ */
+ public function should_run()
+ {
+ return true;
+ }
+
+ /**
+ * Returns whether this cron task can be run in shutdown function.
+ */
+ public function is_shutdown_function_safe()
+ {
+ return true;
+ }
+}
diff --git a/phpBB/includes/cron_tasks/standard/prune_all_forums.php b/phpBB/includes/cron_tasks/standard/prune_all_forums.php
new file mode 100644
index 0000000000..f54f5d9ed9
--- /dev/null
+++ b/phpBB/includes/cron_tasks/standard/prune_all_forums.php
@@ -0,0 +1,45 @@
+<?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;
+}
+
+/**
+* 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 prune_all_forums_cron_task extends cron_task_base
+{
+ /**
+ * Runs this cron task.
+ */
+ public function run()
+ {
+ }
+
+ /**
+ * Returns whether this cron task can run, given current board configuration.
+ */
+ public function is_runnable()
+ {
+ global $config;
+ return !!$config['use_system_cron'];
+ }
+}
diff --git a/phpBB/includes/cron_tasks/standard/prune_forum.php b/phpBB/includes/cron_tasks/standard/prune_forum.php
new file mode 100644
index 0000000000..5ae1083677
--- /dev/null
+++ b/phpBB/includes/cron_tasks/standard/prune_forum.php
@@ -0,0 +1,67 @@
+<?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;
+}
+
+/**
+* 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 prune_forum_cron_task extends cron_task_base implements parametrized_cron_task
+{
+ public function __construct($forum_data)
+ {
+ $this->forum_data = $forum_data;
+ }
+
+ /**
+ * Runs this cron task.
+ */
+ public function run()
+ {
+ }
+
+ /**
+ * Returns whether this cron task can run, given current board configuration.
+ */
+ public function is_runnable()
+ {
+ global $config;
+ return !$config['use_system_cron'];
+ }
+
+ /**
+ * 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 a query string.
+ */
+ public function get_url_query_string()
+ {
+ return 'f=' . $this->forum_data['forum_id'];
+ }
+}
diff --git a/phpBB/includes/cron_tasks/standard/queue.php b/phpBB/includes/cron_tasks/standard/queue.php
new file mode 100644
index 0000000000..6a69799ef4
--- /dev/null
+++ b/phpBB/includes/cron_tasks/standard/queue.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;
+}
+
+/**
+* Queue cron task. Sends email and jabber messages queued by other scripts.
+*
+* @package phpBB3
+*/
+class queue_cron_task extends cron_task_base
+{
+ /**
+ * Runs this cron task.
+ */
+ public function run()
+ {
+ global $phpbb_root_path, $phpEx;
+ include_once($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;
+ return !$config['smtp_delivery'];
+ }
+}
diff --git a/phpBB/includes/cron_tasks/standard/tidy_cache.php b/phpBB/includes/cron_tasks/standard/tidy_cache.php
new file mode 100644
index 0000000000..7c47be06c1
--- /dev/null
+++ b/phpBB/includes/cron_tasks/standard/tidy_cache.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;
+}
+
+/**
+* Tidy cache cron task.
+*
+* @package phpBB3
+*/
+class tidy_cache_cron_task 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_tasks/standard/tidy_database.php b/phpBB/includes/cron_tasks/standard/tidy_database.php
new file mode 100644
index 0000000000..16a17b3538
--- /dev/null
+++ b/phpBB/includes/cron_tasks/standard/tidy_database.php
@@ -0,0 +1,44 @@
+<?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;
+}
+
+/**
+* Tidy database cron task.
+*
+* @package phpBB3
+*/
+class tidy_database_cron_task extends cron_task_base
+{
+ /**
+ * Runs this cron task.
+ */
+ public function run()
+ {
+ include_once($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_tasks/standard/tidy_search.php b/phpBB/includes/cron_tasks/standard/tidy_search.php
new file mode 100644
index 0000000000..ac42c26689
--- /dev/null
+++ b/phpBB/includes/cron_tasks/standard/tidy_search.php
@@ -0,0 +1,72 @@
+<?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;
+}
+
+/**
+* Tidy search cron task.
+*
+* Will only run when the currently selected search backend supports tidying.
+*
+* @package phpBB3
+*/
+class tidy_sessions_cron_task 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']);
+
+ include_once("{$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_tasks/standard/tidy_sessions.php b/phpBB/includes/cron_tasks/standard/tidy_sessions.php
new file mode 100644
index 0000000000..6ff2dee14b
--- /dev/null
+++ b/phpBB/includes/cron_tasks/standard/tidy_sessions.php
@@ -0,0 +1,44 @@
+<?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;
+}
+
+/**
+* Tidy sessions cron task.
+*
+* @package phpBB3
+*/
+class tidy_sessions_cron_task 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_tasks/standard/tidy_warnings.php b/phpBB/includes/cron_tasks/standard/tidy_warnings.php
new file mode 100644
index 0000000000..059125b18d
--- /dev/null
+++ b/phpBB/includes/cron_tasks/standard/tidy_warnings.php
@@ -0,0 +1,56 @@
+<?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;
+}
+
+/**
+* Tidy warnings cron task.
+*
+* Will only run when warnings are configured to expire.
+*
+* @package phpBB3
+*/
+class tidy_warnings_cron_task extends cron_task_base
+{
+ /**
+ * Runs this cron task.
+ */
+ public function run()
+ {
+ global $phpbb_root_path, $phpEx;
+ include_once($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 !!$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'];
+ }
+}