From 794d376be4d3587f21bf7149de428a37deaa71c8 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 28 Oct 2010 21:35:53 +0200 Subject: [feature/system-cron] rename tasks to task PHPBB3-9596 --- phpBB/includes/cron/task/core/prune_all_forums.php | 74 +++++++++++ phpBB/includes/cron/task/core/prune_forum.php | 139 +++++++++++++++++++++ phpBB/includes/cron/task/core/queue.php | 73 +++++++++++ phpBB/includes/cron/task/core/tidy_cache.php | 58 +++++++++ phpBB/includes/cron/task/core/tidy_database.php | 53 ++++++++ phpBB/includes/cron/task/core/tidy_search.php | 80 ++++++++++++ phpBB/includes/cron/task/core/tidy_sessions.php | 49 ++++++++ phpBB/includes/cron/task/core/tidy_warnings.php | 64 ++++++++++ .../includes/cron/tasks/core/prune_all_forums.php | 74 ----------- phpBB/includes/cron/tasks/core/prune_forum.php | 139 --------------------- phpBB/includes/cron/tasks/core/queue.php | 73 ----------- phpBB/includes/cron/tasks/core/tidy_cache.php | 58 --------- phpBB/includes/cron/tasks/core/tidy_database.php | 53 -------- phpBB/includes/cron/tasks/core/tidy_search.php | 80 ------------ phpBB/includes/cron/tasks/core/tidy_sessions.php | 49 -------- phpBB/includes/cron/tasks/core/tidy_warnings.php | 64 ---------- 16 files changed, 590 insertions(+), 590 deletions(-) create mode 100644 phpBB/includes/cron/task/core/prune_all_forums.php create mode 100644 phpBB/includes/cron/task/core/prune_forum.php create mode 100644 phpBB/includes/cron/task/core/queue.php create mode 100644 phpBB/includes/cron/task/core/tidy_cache.php create mode 100644 phpBB/includes/cron/task/core/tidy_database.php create mode 100644 phpBB/includes/cron/task/core/tidy_search.php create mode 100644 phpBB/includes/cron/task/core/tidy_sessions.php create mode 100644 phpBB/includes/cron/task/core/tidy_warnings.php delete mode 100644 phpBB/includes/cron/tasks/core/prune_all_forums.php delete mode 100644 phpBB/includes/cron/tasks/core/prune_forum.php delete mode 100644 phpBB/includes/cron/tasks/core/queue.php delete mode 100644 phpBB/includes/cron/tasks/core/tidy_cache.php delete mode 100644 phpBB/includes/cron/tasks/core/tidy_database.php delete mode 100644 phpBB/includes/cron/tasks/core/tidy_search.php delete mode 100644 phpBB/includes/cron/tasks/core/tidy_sessions.php delete mode 100644 phpBB/includes/cron/tasks/core/tidy_warnings.php 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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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/tasks/core/prune_forum.php b/phpBB/includes/cron/tasks/core/prune_forum.php deleted file mode 100644 index 7728932d7e..0000000000 --- a/phpBB/includes/cron/tasks/core/prune_forum.php +++ /dev/null @@ -1,139 +0,0 @@ -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/tasks/core/queue.php b/phpBB/includes/cron/tasks/core/queue.php deleted file mode 100644 index dffaf5aed4..0000000000 --- a/phpBB/includes/cron/tasks/core/queue.php +++ /dev/null @@ -1,73 +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; - // 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/tasks/core/tidy_cache.php b/phpBB/includes/cron/tasks/core/tidy_cache.php deleted file mode 100644 index 72843ba680..0000000000 --- a/phpBB/includes/cron/tasks/core/tidy_cache.php +++ /dev/null @@ -1,58 +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/core/tidy_database.php b/phpBB/includes/cron/tasks/core/tidy_database.php deleted file mode 100644 index 6724ec092e..0000000000 --- a/phpBB/includes/cron/tasks/core/tidy_database.php +++ /dev/null @@ -1,53 +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/core/tidy_sessions.php b/phpBB/includes/cron/tasks/core/tidy_sessions.php deleted file mode 100644 index ecf0be3978..0000000000 --- a/phpBB/includes/cron/tasks/core/tidy_sessions.php +++ /dev/null @@ -1,49 +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/core/tidy_warnings.php b/phpBB/includes/cron/tasks/core/tidy_warnings.php deleted file mode 100644 index 6ef6a17fab..0000000000 --- a/phpBB/includes/cron/tasks/core/tidy_warnings.php +++ /dev/null @@ -1,64 +0,0 @@ -