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 --- .../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 +++++++++++ 8 files changed, 508 insertions(+) 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 (limited to 'phpBB/includes/cron/tasks/core') 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 @@ +