diff options
author | Oleg Pudeyev <oleg@bsdpower.com> | 2010-04-15 10:11:40 -0400 |
---|---|---|
committer | Oleg Pudeyev <oleg@bsdpower.com> | 2011-02-12 22:05:49 -0500 |
commit | 61e0285da86ffaf825cfcd486b5372b9566e51d7 (patch) | |
tree | 352d2e8086f34997aa6e910a69fd15976b262cc4 /phpBB/includes/cron.php | |
parent | 3956e9f53363171db1ccbafe4971564ff91404e9 (diff) | |
download | forums-61e0285da86ffaf825cfcd486b5372b9566e51d7.tar forums-61e0285da86ffaf825cfcd486b5372b9566e51d7.tar.gz forums-61e0285da86ffaf825cfcd486b5372b9566e51d7.tar.bz2 forums-61e0285da86ffaf825cfcd486b5372b9566e51d7.tar.xz forums-61e0285da86ffaf825cfcd486b5372b9566e51d7.zip |
[feature/system-cron] Reformatted cron, includes/cron and includes/cron_lock.
PHPBB3-9596
Diffstat (limited to 'phpBB/includes/cron.php')
-rw-r--r-- | phpBB/includes/cron.php | 107 |
1 files changed, 68 insertions, 39 deletions
diff --git a/phpBB/includes/cron.php b/phpBB/includes/cron.php index 2aa22858b7..b9a1bb778a 100644 --- a/phpBB/includes/cron.php +++ b/phpBB/includes/cron.php @@ -23,113 +23,142 @@ if (!defined('IN_PHPBB')) class cron { var $tasks = array(); - - function cron() { + + function cron() + { global $config, $phpbb_root_path, $phpEx; $modules = $config['cron_modules']; $modules = explode(',', $modules); - foreach ($modules as $module) { + foreach ($modules as $module) + { // explode will return array("") when exploding an empty string; // users may also specify something like foo,,bar. // Account for module being possibly empty - if (!empty($module)) { + if (!empty($module)) + { // Misspelling or specifying nonexistent modules here may make the board // unusable due to error messages screwing up header output include_once($phpbb_root_path . "includes/cron/$module.$phpEx"); $cron_class = "cron_tasks_$module"; $object = new $cron_class; - foreach ($object->tasks as $cron_type => $params) { + foreach ($object->tasks as $cron_type => $params) + { $params['object'] = $object; $this->tasks[$cron_type] = $params; } } } } - - function is_valid_task($cron_type) { + + function is_valid_task($cron_type) + { return isset($this->tasks[$cron_type]); } - - function is_task_runnable($cron_type, $args=null) { + + 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']]) { + if ($cron_params['enable_config'] && !$config[$cron_params['enable_config']]) + { return false; } - if ($cron_param['custom_condition']) { + if ($cron_param['custom_condition']) + { $callable = array($cron_params['object'], $cron_type . '_condition'); - if ($args) { + if ($args) + { $answer = call_user_func_array($callable, $args); - } else { + } else + { $answer = call_user_func($callable); } - if (!$answer) { + if (!$answer) + { return false; } } - if ($time_now - $config[$cron_params['interval_config']] > $config[$cron_params['last_run_config']]) { + 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) { + + function is_task_shutdown_function_compatible($cron_type) + { $cron_params = $this->tasks[$cron_type]; - if (isset($cron_params['shutdown_function_condition'])) { + if (isset($cron_params['shutdown_function_condition'])) + { return call_user_func(array($cron_params->object, $cron_type . '_shutdown_function_condition')); - } else { + } else + { return true; } } - - function determine_cron_mode_param() { + + function determine_cron_mode_param() + { global $config; - if ($config['use_system_cron']) { + if ($config['use_system_cron']) + { $mode = 'run_from_system'; - } else { + } else + { $mode_param = 'run_from_phpbb'; } return $mode_param; } - - function find_one_runnable_task() { + + 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)) { + 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() { + + 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)) { + 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()) { + + function generate_task_code($cron_type, $args=array()) + { $cron_params = $this->tasks[$cron_type]; - if ($cron_params['custom_code']) { + if ($cron_params['custom_code']) + { $code = call_user_func_array(array($cron_params['object'], $cron_type . '_code'), $args); - } else { + } else + { $code = $this->generate_generic_task_code($cron_type); } return $code; } - - function generate_generic_task_code($cron_type) { + + function generate_generic_task_code($cron_type) + { global $phpbb_root_path, $phpEx; return '<img src="' . append_sid($phpbb_root_path . 'cron.' . $phpEx, 'cron_type=' . $cron_type) . '" width="1" height="1" alt="cron" />'; } - - function run_task($cron_type) { + + function run_task($cron_type) + { call_user_func(array($this->tasks[$cron_type]['object'], 'run_' . $cron_type)); } } |