aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/cron
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes/cron')
-rw-r--r--phpBB/includes/cron/cron_lock.php75
-rw-r--r--phpBB/includes/cron/cron_manager.php175
-rw-r--r--phpBB/includes/cron/cron_task.php60
-rw-r--r--phpBB/includes/cron/cron_task_base.php64
-rw-r--r--phpBB/includes/cron/cron_task_wrapper.php68
-rw-r--r--phpBB/includes/cron/standard.php163
-rw-r--r--phpBB/includes/cron/tasks/core/prune_all_forums.php63
-rw-r--r--phpBB/includes/cron/tasks/core/prune_forum.php112
-rw-r--r--phpBB/includes/cron/tasks/core/queue.php64
-rw-r--r--phpBB/includes/cron/tasks/core/tidy_cache.php53
-rw-r--r--phpBB/includes/cron/tasks/core/tidy_database.php44
-rw-r--r--phpBB/includes/cron/tasks/core/tidy_search.php72
-rw-r--r--phpBB/includes/cron/tasks/core/tidy_sessions.php44
-rw-r--r--phpBB/includes/cron/tasks/core/tidy_warnings.php56
14 files changed, 950 insertions, 163 deletions
diff --git a/phpBB/includes/cron/cron_lock.php b/phpBB/includes/cron/cron_lock.php
new file mode 100644
index 0000000000..1046d62da4
--- /dev/null
+++ b/phpBB/includes/cron/cron_lock.php
@@ -0,0 +1,75 @@
+<?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 lock class
+* @package phpBB3
+*/
+class cron_lock
+{
+ private $cron_id;
+
+ function lock()
+ {
+ global $config, $db;
+
+ if (!isset($config['cron_lock']))
+ {
+ set_config('cron_lock', '0', true);
+ }
+
+ // make sure cron doesn't run multiple times in parallel
+ if ($config['cron_lock'])
+ {
+ // if the other process is running more than an hour already we have to assume it
+ // aborted without cleaning the lock
+ $time = explode(' ', $config['cron_lock']);
+ $time = $time[0];
+
+ if ($time + 3600 >= time())
+ {
+ return false;
+ }
+ }
+
+ $this->cron_id = time() . ' ' . unique_id();
+
+ $sql = 'UPDATE ' . CONFIG_TABLE . "
+ SET config_value = '" . $db->sql_escape($this->cron_id) . "'
+ WHERE config_name = 'cron_lock' AND config_value = '" . $db->sql_escape($config['cron_lock']) . "'";
+ $db->sql_query($sql);
+
+ // another cron process altered the table between script start and UPDATE query so exit
+ if ($db->sql_affectedrows() != 1)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ function unlock()
+ {
+ global $db;
+
+ $sql = 'UPDATE ' . CONFIG_TABLE . "
+ SET config_value = '0'
+ WHERE config_name = 'cron_lock' AND config_value = '" . $db->sql_escape($this->cron_id) . "'";
+ $db->sql_query($sql);
+ }
+}
diff --git a/phpBB/includes/cron/cron_manager.php b/phpBB/includes/cron/cron_manager.php
new file mode 100644
index 0000000000..5ee06ac102
--- /dev/null
+++ b/phpBB/includes/cron/cron_manager.php
@@ -0,0 +1,175 @@
+<?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 manager class.
+*
+* Finds installed cron tasks, stores task objects, provides task selection.
+*
+* @package phpBB3
+*/
+class cron_manager
+{
+ private $tasks = array();
+
+ public function __construct()
+ {
+ $task_files = $this->find_cron_task_files();
+ $this->load_tasks($task_files);
+ }
+
+ /**
+ * Finds cron task files.
+ *
+ * A cron task file must follow the naming convention:
+ * includes/cron/tasks/$mod/$name.php.
+ * $mod is core for tasks that are part of phpbb.
+ * Modifications should use their name as $mod.
+ * $name is the name of the cron task.
+ * Cron task is expected to be a class named cron_task_${mod}_${name}.
+ *
+ * Todo: consider caching found task file list in global cache.
+ */
+ public function find_cron_task_files()
+ {
+ global $phpbb_root_path, $phpEx;
+
+ $tasks_root_path = $phpbb_root_path . 'includes/cron/tasks';
+ $dir = opendir($tasks_root_path);
+ $task_dirs = array();
+ while (($entry = readdir($dir)) !== false)
+ {
+ // ignore ., .. and dot directories
+ // todo: change is_dir to account for symlinks
+ if ($entry[0] == '.' || !is_dir($entry))
+ {
+ continue;
+ }
+ $task_dirs[] = $entry;
+ }
+ closedir($dir);
+
+ $ext = '.' . $phpEx;
+ $ext_length = strlen($ext);
+ $task_files = array();
+ foreach ($task_dirs as $task_dir)
+ {
+ $path = $phpbb_root_path . 'includes/cron/tasks/' . $task_dir;
+ $dir = opendir($path);
+ while (($entry = readdir($dir)) !== false && substr($entry, -$ext_length) == $ext)
+ {
+ $task_file = substr($entry, 0, -$ext_length);
+ $task_files[] = array($task_dir, $task_file);
+ }
+ closedir($dir);
+ }
+ return $task_files;
+ }
+
+ /**
+ * Checks whether $name is a valid identifier, and therefore part of valid cron task class name.
+ */
+ public function is_valid_name($name)
+ {
+ return preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $name);
+ }
+
+ public function load_tasks($task_files)
+ {
+ global $phpbb_root_path, $phpEx;
+
+ foreach ($task_files as $task_file)
+ {
+ list($mod, $filename) = $task_file;
+ if ($this->is_valid_name($mod) && $this->is_valid_name($filename))
+ {
+ include_once($phpbb_root_path . "includes/cron/$mod/$filename.$phpEx");
+ $class = "cron_task_${mod}_${filename}";
+ $object = new $class;
+ $this->tasks[] = $object;
+ }
+ }
+ }
+
+ /**
+ * Finds a task that is ready to run.
+ *
+ * If several tasks are ready, any one of them could be returned.
+ */
+ function find_one_ready_task()
+ {
+ foreach ($this->tasks as $task)
+ {
+ if ($task->is_ready())
+ {
+ return $task;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Finds all tasks that are ready to run.
+ */
+ function find_all_ready_tasks()
+ {
+ $tasks = array();
+ foreach ($this->tasks as $task)
+ {
+ if ($task->is_ready())
+ {
+ $tasks[] = $task;
+ }
+ }
+ return $tasks;
+ }
+
+ /**
+ * Finds a task by name.
+ *
+ * Web runner uses this method to resolve names to tasks.
+ */
+ function find_task($name)
+ {
+ foreach ($this->tasks as $task)
+ {
+ if ($task->get_name() == $name)
+ {
+ return $task;
+ }
+ }
+ return null;
+ }
+
+ function instantiate_task($name, $args)
+ {
+ $task = $this->find_task($name);
+ if ($task)
+ {
+ $class = get_class($task);
+ $task = new $class($args);
+ }
+ return $task;
+ }
+
+ function generate_generic_task_code($cron_type)
+ {
+ global $phpbb_root_path, $phpEx;
+ return '<img src="' . $url . '" width="1" height="1" alt="cron" />';
+ }
+}
diff --git a/phpBB/includes/cron/cron_task.php b/phpBB/includes/cron/cron_task.php
new file mode 100644
index 0000000000..8b9ffacae6
--- /dev/null
+++ b/phpBB/includes/cron/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/cron_task_base.php b/phpBB/includes/cron/cron_task_base.php
new file mode 100644
index 0000000000..f66894e7b2
--- /dev/null
+++ b/phpBB/includes/cron/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/cron_task_wrapper.php b/phpBB/includes/cron/cron_task_wrapper.php
new file mode 100644
index 0000000000..3919e4f049
--- /dev/null
+++ b/phpBB/includes/cron/cron_task_wrapper.php
@@ -0,0 +1,68 @@
+<?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 wrapper class.
+* Enhances cron tasks with convenience methods that work identically for all tasks.
+*
+* @package phpBB3
+*/
+class cron_task_wrapper
+{
+ public function __construct($task)
+ {
+ $this->task = $task;
+ }
+
+ /**
+ * Returns whether the wrapped task is ready to run.
+ *
+ * A task is ready to run when it is runnable according to current configuration
+ * and enough time has passed since it was last run.
+ */
+ public function is_ready()
+ {
+ return $this->task->is_runnable() && $this->task->should_run();
+ }
+
+ /**
+ * Returns the name of wrapped task.
+ */
+ public function get_name()
+ {
+ $class = get_class($this->task);
+ return preg_replace('/^cron_task_/', '', $class);
+ }
+
+ public function get_url()
+ {
+ global $phpbb_root_path, $phpEx;
+
+ $name = $this->get_name();
+ $url = append_sid($phpbb_root_path . 'cron.' . $phpEx, 'cron_type=' . $name);
+ return $url;
+ }
+
+ /**
+ * Forwards all other method calls to the wrapped task implementation.
+ */
+ public function __call($name, $args)
+ {
+ return call_user_func_array(array($this->task, $name), $args);
+ }
+}
diff --git a/phpBB/includes/cron/standard.php b/phpBB/includes/cron/standard.php
deleted file mode 100644
index 1cb8738f17..0000000000
--- a/phpBB/includes/cron/standard.php
+++ /dev/null
@@ -1,163 +0,0 @@
-<?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;
-}
-
-/**
-* Standard cron tasks
-* @package phpBB3
-*/
-class cron_tasks_standard
-{
- var $tasks = array(
- // key: cron type
- // values: config name for enable/disable flag,
- // whether to check condition function to determine if the task can/should be run,
- // config name for interval,
- // config name for last run time,
- // whether task should be considered in phpbb cron mode,
- // whether task should be considered in system cron mode,
- // whether task requires special code generation
- 'prune_all_forums' => array(
- 'custom_condition' => true,
- 'run_from_system' => true,
- ),
- 'prune_forum' => array(
- 'custom_condition' => true,
- 'custom_code' => true,
- ),
- 'queue' => array(
- 'custom_condition' => true,
- 'interval_config' => 'queue_interval_config',
- 'last_run_config' => 'last_queue_run',
- 'run_from_phpbb' => true,
- 'run_from_system' => true,
- 'shutdown_function_condition' => true,
- ),
- 'tidy_cache' => array(
- 'custom_condition' => true,
- 'interval_config' => 'cache_gc',
- 'last_run_config' => 'cache_last_gc',
- 'run_from_phpbb' => true,
- 'run_from_system' => true,
- ),
- 'tidy_database' => array(
- 'interval_config' => 'database_gc',
- 'last_run_config' => 'database_last_gc',
- 'run_from_phpbb' => true,
- 'run_from_system' => true,
- ),
- 'tidy_search' => array(
- 'interval_config' => 'search_gc',
- 'last_run_config' => 'search_last_gc',
- 'run_from_phpbb' => true,
- 'run_from_system' => true,
- ),
- 'tidy_sessions' => array(
- 'interval_config' => 'session_gc',
- 'last_run_config' => 'session_last_gc',
- 'run_from_phpbb' => true,
- 'run_from_system' => true,
- ),
- 'tidy_warnings' => array(
- 'enable_config' => 'warnings_expire_days',
- 'interval_config' => 'warnings_gc',
- 'last_run_config' => 'warnings_last_gc',
- 'run_from_phpbb' => true,
- 'run_from_system' => true,
- ),
- );
-
- function prune_forum_condition($forum_data) {
- return $forum_data['enable_prune'] && $forum_data['prune_next'] < time();
- }
-
- function prune_forum_code($forum_id) {
- global $phpbb_root_path, $phpEx;
- return '<img src="' . append_sid($phpbb_root_path . 'cron.' . $phpEx, 'cron_type=prune_forum&amp;f=' . $forum_id) . '" alt="cron" width="1" height="1" />';
- }
-
- function run_prune_forum() {
- }
-
- function queue_condition() {
- global $phpbb_root_path, $phpEx;
- return file_exists($phpbb_root_path . 'cache/queue.' . $phpEx);
- }
-
- function queue_shutdown_function_condition() {
- global $config;
- return !$config['smtp_delivery'];
- }
-
- function run_queue() {
- global $phpbb_root_path, $phpEx;
- include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
- $queue = new queue();
- $queue->process();
- }
-
- function tidy_cache_condition() {
- global $cache;
- return method_exists($cache, 'tidy');
- }
-
- function run_tidy_cache() {
- global $cache;
- $cache->tidy();
- }
-
- function run_tidy_database() {
- include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
- tidy_database();
- }
-
- function tidy_search_condition() {
- 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);
- }
-
- function run_tidy_search() {
- 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();
- }
- }
-
- function run_tidy_sessions() {
- global $user;
- $user->session_gc();
- }
-
- function run_tidy_warnings() {
- include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
- tidy_warnings();
- }
-}
diff --git a/phpBB/includes/cron/tasks/core/prune_all_forums.php b/phpBB/includes/cron/tasks/core/prune_all_forums.php
new file mode 100644
index 0000000000..13286de2b0
--- /dev/null
+++ b/phpBB/includes/cron/tasks/core/prune_all_forums.php
@@ -0,0 +1,63 @@
+<?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 cron_task_core_prune_all_forums extends cron_task_base
+{
+ /**
+ * Runs this cron task.
+ */
+ public function run()
+ {
+ global $db;
+ $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 !!$config['use_system_cron'];
+ }
+}
diff --git a/phpBB/includes/cron/tasks/core/prune_forum.php b/phpBB/includes/cron/tasks/core/prune_forum.php
new file mode 100644
index 0000000000..4925447162
--- /dev/null
+++ b/phpBB/includes/cron/tasks/core/prune_forum.php
@@ -0,0 +1,112 @@
+<?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 cron_task_core_prune_forum extends cron_task_base implements parametrized_cron_task
+{
+ /**
+ * 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
+ {
+ $forum_id = request_var('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)
+ {
+ // FIXME what to do?
+ break;
+ }
+
+ $this->forum_data = $row;
+ }
+ }
+
+ /**
+ * Runs this cron task.
+ */
+ public function run()
+ {
+ global $phpbb_root_path, $phpEx;
+ include_once($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'];
+ }
+
+ /**
+ * 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/core/queue.php b/phpBB/includes/cron/tasks/core/queue.php
new file mode 100644
index 0000000000..d7dfeb9319
--- /dev/null
+++ b/phpBB/includes/cron/tasks/core/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 cron_task_core_queue 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/core/tidy_cache.php b/phpBB/includes/cron/tasks/core/tidy_cache.php
new file mode 100644
index 0000000000..69038a8a5a
--- /dev/null
+++ b/phpBB/includes/cron/tasks/core/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 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/tasks/core/tidy_database.php b/phpBB/includes/cron/tasks/core/tidy_database.php
new file mode 100644
index 0000000000..c6c2a60445
--- /dev/null
+++ b/phpBB/includes/cron/tasks/core/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 cron_task_core_tidy_database 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/core/tidy_search.php b/phpBB/includes/cron/tasks/core/tidy_search.php
new file mode 100644
index 0000000000..0f409d114a
--- /dev/null
+++ b/phpBB/includes/cron/tasks/core/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 cron_task_core_tidy_sessions 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/core/tidy_sessions.php b/phpBB/includes/cron/tasks/core/tidy_sessions.php
new file mode 100644
index 0000000000..ea6aa70699
--- /dev/null
+++ b/phpBB/includes/cron/tasks/core/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 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/tasks/core/tidy_warnings.php b/phpBB/includes/cron/tasks/core/tidy_warnings.php
new file mode 100644
index 0000000000..c1ab14d788
--- /dev/null
+++ b/phpBB/includes/cron/tasks/core/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 cron_task_core_tidy_warnings 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'];
+ }
+}