From 0f9b3bcc27e7daf7d605a7a38310a8f62b9a76e8 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 17 Apr 2010 03:13:30 -0400 Subject: [feature/system-cron] Refactored cron task naming, loading and running. PHPBB3-9596 --- phpBB/includes/cron.php | 164 ------------------- phpBB/includes/cron/cron_lock.php | 75 +++++++++ phpBB/includes/cron/cron_manager.php | 175 +++++++++++++++++++++ phpBB/includes/cron/cron_task.php | 60 +++++++ phpBB/includes/cron/cron_task_base.php | 64 ++++++++ phpBB/includes/cron/cron_task_wrapper.php | 68 ++++++++ phpBB/includes/cron/standard.php | 163 ------------------- .../includes/cron/tasks/core/prune_all_forums.php | 63 ++++++++ phpBB/includes/cron/tasks/core/prune_forum.php | 112 +++++++++++++ phpBB/includes/cron/tasks/core/queue.php | 64 ++++++++ phpBB/includes/cron/tasks/core/tidy_cache.php | 53 +++++++ phpBB/includes/cron/tasks/core/tidy_database.php | 44 ++++++ phpBB/includes/cron/tasks/core/tidy_search.php | 72 +++++++++ phpBB/includes/cron/tasks/core/tidy_sessions.php | 44 ++++++ phpBB/includes/cron/tasks/core/tidy_warnings.php | 56 +++++++ phpBB/includes/cron_lock.php | 75 --------- phpBB/includes/cron_task.php | 60 ------- phpBB/includes/cron_task_base.php | 64 -------- .../cron_tasks/standard/prune_all_forums.php | 63 -------- phpBB/includes/cron_tasks/standard/prune_forum.php | 112 ------------- phpBB/includes/cron_tasks/standard/queue.php | 64 -------- phpBB/includes/cron_tasks/standard/tidy_cache.php | 53 ------- .../includes/cron_tasks/standard/tidy_database.php | 44 ------ phpBB/includes/cron_tasks/standard/tidy_search.php | 72 --------- .../includes/cron_tasks/standard/tidy_sessions.php | 44 ------ .../includes/cron_tasks/standard/tidy_warnings.php | 56 ------- phpBB/includes/functions.php | 7 +- 27 files changed, 954 insertions(+), 1037 deletions(-) delete mode 100644 phpBB/includes/cron.php create mode 100644 phpBB/includes/cron/cron_lock.php create mode 100644 phpBB/includes/cron/cron_manager.php create mode 100644 phpBB/includes/cron/cron_task.php create mode 100644 phpBB/includes/cron/cron_task_base.php create mode 100644 phpBB/includes/cron/cron_task_wrapper.php delete mode 100644 phpBB/includes/cron/standard.php create mode 100644 phpBB/includes/cron/tasks/core/prune_all_forums.php create mode 100644 phpBB/includes/cron/tasks/core/prune_forum.php create mode 100644 phpBB/includes/cron/tasks/core/queue.php create mode 100644 phpBB/includes/cron/tasks/core/tidy_cache.php create mode 100644 phpBB/includes/cron/tasks/core/tidy_database.php create mode 100644 phpBB/includes/cron/tasks/core/tidy_search.php create mode 100644 phpBB/includes/cron/tasks/core/tidy_sessions.php create mode 100644 phpBB/includes/cron/tasks/core/tidy_warnings.php delete mode 100644 phpBB/includes/cron_lock.php delete mode 100644 phpBB/includes/cron_task.php delete mode 100644 phpBB/includes/cron_task_base.php delete mode 100644 phpBB/includes/cron_tasks/standard/prune_all_forums.php delete mode 100644 phpBB/includes/cron_tasks/standard/prune_forum.php delete mode 100644 phpBB/includes/cron_tasks/standard/queue.php delete mode 100644 phpBB/includes/cron_tasks/standard/tidy_cache.php delete mode 100644 phpBB/includes/cron_tasks/standard/tidy_database.php delete mode 100644 phpBB/includes/cron_tasks/standard/tidy_search.php delete mode 100644 phpBB/includes/cron_tasks/standard/tidy_sessions.php delete mode 100644 phpBB/includes/cron_tasks/standard/tidy_warnings.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/cron.php b/phpBB/includes/cron.php deleted file mode 100644 index b9a1bb778a..0000000000 --- a/phpBB/includes/cron.php +++ /dev/null @@ -1,164 +0,0 @@ -tasks as $cron_type => $params) - { - $params['object'] = $object; - $this->tasks[$cron_type] = $params; - } - } - } - } - - function is_valid_task($cron_type) - { - return isset($this->tasks[$cron_type]); - } - - function is_task_runnable($cron_type, $args=null) - { - global $config; - $time_now = time(); - $cron_params = $this->tasks[$cron_type]; - if ($cron_params['enable_config'] && !$config[$cron_params['enable_config']]) - { - return false; - } - if ($cron_param['custom_condition']) - { - $callable = array($cron_params['object'], $cron_type . '_condition'); - if ($args) - { - $answer = call_user_func_array($callable, $args); - } else - { - $answer = call_user_func($callable); - } - if (!$answer) - { - return false; - } - } - if ($time_now - $config[$cron_params['interval_config']] > $config[$cron_params['last_run_config']]) - { - return true; - } - return false; - } - - function is_task_shutdown_function_compatible($cron_type) - { - $cron_params = $this->tasks[$cron_type]; - if (isset($cron_params['shutdown_function_condition'])) - { - return call_user_func(array($cron_params->object, $cron_type . '_shutdown_function_condition')); - } else - { - return true; - } - } - - function determine_cron_mode_param() - { - global $config; - if ($config['use_system_cron']) - { - $mode = 'run_from_system'; - } else - { - $mode_param = 'run_from_phpbb'; - } - return $mode_param; - } - - function find_one_runnable_task() - { - $mode_param = $this->determine_cron_mode_param(); - foreach ($this->tasks as $cron_type => $cron_params) - { - if ($cron_params[$mode_param] && $this->is_task_runnable($cron_type)) - { - return $cron_type; - } - } - return null; - } - - function find_all_runnable_tasks() - { - $mode_param = $this->determine_cron_mode_param(); - $tasks = array(); - foreach ($this->tasks as $cron_type => $cron_params) - { - if ($cron_params[$mode_param] && $this->is_task_runnable($cron_type)) - { - $tasks[] = $cron_type; - } - } - return $tasks; - } - - function generate_task_code($cron_type, $args=array()) - { - $cron_params = $this->tasks[$cron_type]; - if ($cron_params['custom_code']) - { - $code = call_user_func_array(array($cron_params['object'], $cron_type . '_code'), $args); - } else - { - $code = $this->generate_generic_task_code($cron_type); - } - return $code; - } - - function generate_generic_task_code($cron_type) - { - global $phpbb_root_path, $phpEx; - return 'cron'; - } - - function run_task($cron_type) - { - call_user_func(array($this->tasks[$cron_type]['object'], 'run_' . $cron_type)); - } -} 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 @@ += 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 @@ +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 '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 @@ +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 @@ - 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 'cron'; - } - - 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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ += 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_task.php b/phpBB/includes/cron_task.php deleted file mode 100644 index 8b9ffacae6..0000000000 --- a/phpBB/includes/cron_task.php +++ /dev/null @@ -1,60 +0,0 @@ -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/standard/prune_forum.php b/phpBB/includes/cron_tasks/standard/prune_forum.php deleted file mode 100644 index f4ef2ea6dd..0000000000 --- a/phpBB/includes/cron_tasks/standard/prune_forum.php +++ /dev/null @@ -1,112 +0,0 @@ -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/standard/queue.php b/phpBB/includes/cron_tasks/standard/queue.php deleted file mode 100644 index 6a69799ef4..0000000000 --- a/phpBB/includes/cron_tasks/standard/queue.php +++ /dev/null @@ -1,64 +0,0 @@ -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 deleted file mode 100644 index 7c47be06c1..0000000000 --- a/phpBB/includes/cron_tasks/standard/tidy_cache.php +++ /dev/null @@ -1,53 +0,0 @@ -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 deleted file mode 100644 index 16a17b3538..0000000000 --- a/phpBB/includes/cron_tasks/standard/tidy_database.php +++ /dev/null @@ -1,44 +0,0 @@ -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 deleted file mode 100644 index 6ff2dee14b..0000000000 --- a/phpBB/includes/cron_tasks/standard/tidy_sessions.php +++ /dev/null @@ -1,44 +0,0 @@ -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 deleted file mode 100644 index 059125b18d..0000000000 --- a/phpBB/includes/cron_tasks/standard/tidy_warnings.php +++ /dev/null @@ -1,56 +0,0 @@ -find_one_runnable_task(); + $task = $cron->find_one_ready_task(); - if ($cron_type) + if ($task) { - $template->assign_var('RUN_CRON_TASK', $cron->generate_task_code($cron_type)); + $url = $task->get_url(); + $template->assign_var('RUN_CRON_TASK', 'cron'); } } -- cgit v1.2.1