From 0532048292e056d62b7bafa5dda3d53b297bce94 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 15 Apr 2010 03:28:59 -0400 Subject: [PATCH] [feature/system-cron] WIP on reorganizing cron tasks into classes. PHPBB3-9596 --- phpBB/includes/cron_task.php | 60 ++++++++++++++++ phpBB/includes/cron_task_base.php | 64 +++++++++++++++++ .../cron_tasks/standard/prune_all_forums.php | 45 ++++++++++++ .../cron_tasks/standard/prune_forum.php | 67 +++++++++++++++++ phpBB/includes/cron_tasks/standard/queue.php | 64 +++++++++++++++++ .../cron_tasks/standard/tidy_cache.php | 53 ++++++++++++++ .../cron_tasks/standard/tidy_database.php | 44 ++++++++++++ .../cron_tasks/standard/tidy_search.php | 72 +++++++++++++++++++ .../cron_tasks/standard/tidy_sessions.php | 44 ++++++++++++ .../cron_tasks/standard/tidy_warnings.php | 56 +++++++++++++++ 10 files changed, 569 insertions(+) create mode 100644 phpBB/includes/cron_task.php create mode 100644 phpBB/includes/cron_task_base.php create mode 100644 phpBB/includes/cron_tasks/standard/prune_all_forums.php create mode 100644 phpBB/includes/cron_tasks/standard/prune_forum.php create mode 100644 phpBB/includes/cron_tasks/standard/queue.php create mode 100644 phpBB/includes/cron_tasks/standard/tidy_cache.php create mode 100644 phpBB/includes/cron_tasks/standard/tidy_database.php create mode 100644 phpBB/includes/cron_tasks/standard/tidy_search.php create mode 100644 phpBB/includes/cron_tasks/standard/tidy_sessions.php create mode 100644 phpBB/includes/cron_tasks/standard/tidy_warnings.php 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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +