diff options
author | Igor Wiedler <igor@wiedler.ch> | 2012-04-09 00:22:55 +0200 |
---|---|---|
committer | Igor Wiedler <igor@wiedler.ch> | 2012-04-09 12:42:31 +0200 |
commit | 2e76620c8824da62f97cfdaee8f9b1014159fd7c (patch) | |
tree | f5868b1b7209a545bda547138f563b82179ea56f /phpBB/includes/cron/task | |
parent | 9165a045c5dee06bb5c163281bb817369a1733a3 (diff) | |
download | forums-2e76620c8824da62f97cfdaee8f9b1014159fd7c.tar forums-2e76620c8824da62f97cfdaee8f9b1014159fd7c.tar.gz forums-2e76620c8824da62f97cfdaee8f9b1014159fd7c.tar.bz2 forums-2e76620c8824da62f97cfdaee8f9b1014159fd7c.tar.xz forums-2e76620c8824da62f97cfdaee8f9b1014159fd7c.zip |
[feature/dic] Rewrite cron system to use DIC
PHPBB3-10739
Diffstat (limited to 'phpBB/includes/cron/task')
-rw-r--r-- | phpBB/includes/cron/task/core/prune_all_forums.php | 25 | ||||
-rw-r--r-- | phpBB/includes/cron/task/core/prune_forum.php | 44 | ||||
-rw-r--r-- | phpBB/includes/cron/task/core/queue.php | 18 | ||||
-rw-r--r-- | phpBB/includes/cron/task/core/tidy_cache.php | 17 | ||||
-rw-r--r-- | phpBB/includes/cron/task/core/tidy_database.php | 15 | ||||
-rw-r--r-- | phpBB/includes/cron/task/core/tidy_search.php | 24 | ||||
-rw-r--r-- | phpBB/includes/cron/task/core/tidy_sessions.php | 14 | ||||
-rw-r--r-- | phpBB/includes/cron/task/core/tidy_warnings.php | 18 | ||||
-rw-r--r-- | phpBB/includes/cron/task/provider.php | 37 |
9 files changed, 124 insertions, 88 deletions
diff --git a/phpBB/includes/cron/task/core/prune_all_forums.php b/phpBB/includes/cron/task/core/prune_all_forums.php index 15b93a9ca6..f3a179d81b 100644 --- a/phpBB/includes/cron/task/core/prune_all_forums.php +++ b/phpBB/includes/cron/task/core/prune_all_forums.php @@ -26,6 +26,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base { + private $phpbb_root_path, $phpEx, $config, $db; + + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, dbal $db) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + $this->db = $db; + } + /** * Runs this cron task. * @@ -33,19 +43,17 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base */ public function run() { - global $phpbb_root_path, $phpEx, $db; - if (!function_exists('auto_prune')) { - include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + include($this->phpbb_root_path . 'includes/functions_admin.' . $this->phpEx); } $sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq FROM ' . FORUMS_TABLE . " - WHERE enable_prune = 1 + WHERE enable_prune = 1 AND prune_next < " . time(); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if ($row['prune_days']) { @@ -57,7 +65,7 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']); } } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); } /** @@ -69,7 +77,6 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base */ public function is_runnable() { - global $config; - return (bool) $config['use_system_cron']; + return (bool) $this->config['use_system_cron']; } } diff --git a/phpBB/includes/cron/task/core/prune_forum.php b/phpBB/includes/cron/task/core/prune_forum.php index 7686fd4281..1f717904ef 100644 --- a/phpBB/includes/cron/task/core/prune_forum.php +++ b/phpBB/includes/cron/task/core/prune_forum.php @@ -26,31 +26,25 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements phpbb_cron_task_parametrized { + private $phpbb_root_path, $phpEx, $config, $db; private $forum_data; + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, dbal $db) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + $this->db = $db; + } + /** - * Constructor. - * - * If $forum_data is given, it is assumed to contain necessary information - * about a single forum that is to be pruned. - * - * If $forum_data is not given, forum id will be retrieved via request_var - * and a database query will be performed to load the necessary information - * about the forum. + * Manually set forum data. * * @param array $forum_data Information about a forum to be pruned. */ - public function __construct($forum_data = null) + public function set_forum_data($forum_data) { - global $db; - if ($forum_data) - { - $this->forum_data = $forum_data; - } - else - { - $this->forum_data = null; - } + $this->forum_data = $forum_data; } /** @@ -60,10 +54,9 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p */ public function run() { - global $phpbb_root_path, $phpEx; if (!function_exists('auto_prune')) { - include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + include($this->phpbb_root_path . 'includes/functions_admin.' . $this->phpEx); } if ($this->forum_data['prune_days']) @@ -90,8 +83,7 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p */ public function is_runnable() { - global $config; - return !$config['use_system_cron'] && $this->forum_data; + return !$this->config['use_system_cron'] && $this->forum_data; } /** @@ -130,8 +122,6 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p */ public function parse_parameters(phpbb_request_interface $request) { - global $db; - $this->forum_data = null; if ($request->is_set('f')) { @@ -140,9 +130,9 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p $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); + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); if ($row) { diff --git a/phpBB/includes/cron/task/core/queue.php b/phpBB/includes/cron/task/core/queue.php index 1c72eec7c7..70db94f31d 100644 --- a/phpBB/includes/cron/task/core/queue.php +++ b/phpBB/includes/cron/task/core/queue.php @@ -22,6 +22,15 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_queue extends phpbb_cron_task_base { + private $phpbb_root_path, $phpEx, $config; + + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + } + /** * Runs this cron task. * @@ -29,10 +38,9 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base */ public function run() { - global $phpbb_root_path, $phpEx; if (!class_exists('queue')) { - include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); + include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->phpEx); } $queue = new queue(); $queue->process(); @@ -47,8 +55,7 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base */ public function is_runnable() { - global $phpbb_root_path, $phpEx; - return file_exists($phpbb_root_path . 'cache/queue.' . $phpEx); + return file_exists($this->phpbb_root_path . 'cache/queue.' . $this->phpEx); } /** @@ -61,7 +68,6 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base */ public function should_run() { - global $config; - return $config['last_queue_run'] < time() - $config['queue_interval_config']; + return $this->config['last_queue_run'] < time() - $this->config['queue_interval_config']; } } diff --git a/phpBB/includes/cron/task/core/tidy_cache.php b/phpBB/includes/cron/task/core/tidy_cache.php index c9dc0bd9ae..530f25dacb 100644 --- a/phpBB/includes/cron/task/core/tidy_cache.php +++ b/phpBB/includes/cron/task/core/tidy_cache.php @@ -22,6 +22,14 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base { + private $config, $cache; + + public function __construct(phpbb_config $config, phpbb_cache_driver_interface $cache) + { + $this->config = $config; + $this->cache = $cache; + } + /** * Runs this cron task. * @@ -29,8 +37,7 @@ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base */ public function run() { - global $cache; - $cache->tidy(); + $this->cache->tidy(); } /** @@ -43,8 +50,7 @@ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base */ public function is_runnable() { - global $cache; - return method_exists($cache, 'tidy'); + return method_exists($this->cache, 'tidy'); } /** @@ -58,7 +64,6 @@ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base */ public function should_run() { - global $config; - return $config['cache_last_gc'] < time() - $config['cache_gc']; + return $this->config['cache_last_gc'] < time() - $this->config['cache_gc']; } } diff --git a/phpBB/includes/cron/task/core/tidy_database.php b/phpBB/includes/cron/task/core/tidy_database.php index 80a1901b1e..910e27cf20 100644 --- a/phpBB/includes/cron/task/core/tidy_database.php +++ b/phpBB/includes/cron/task/core/tidy_database.php @@ -22,6 +22,15 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base { + private $phpbb_root_path, $phpEx, $config; + + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + } + /** * Runs this cron task. * @@ -29,10 +38,9 @@ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base */ public function run() { - global $phpbb_root_path, $phpEx; if (!function_exists('tidy_database')) { - include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + include($this->phpbb_root_path . 'includes/functions_admin.' . $this->phpEx); } tidy_database(); } @@ -48,7 +56,6 @@ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base */ public function should_run() { - global $config; - return $config['database_last_gc'] < time() - $config['database_gc']; + return $this->config['database_last_gc'] < time() - $this->config['database_gc']; } } diff --git a/phpBB/includes/cron/task/core/tidy_search.php b/phpBB/includes/cron/task/core/tidy_search.php index 8a0b1b690a..1b8a0b8151 100644 --- a/phpBB/includes/cron/task/core/tidy_search.php +++ b/phpBB/includes/cron/task/core/tidy_search.php @@ -24,6 +24,15 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base { + private $phpbb_root_path, $phpEx, $config; + + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + } + /** * Runs this cron task. * @@ -31,14 +40,12 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base */ public function run() { - global $phpbb_root_path, $phpEx, $config, $error; - // Select the search method - $search_type = basename($config['search_type']); + $search_type = basename($this->config['search_type']); if (!class_exists($search_type)) { - include("{$phpbb_root_path}includes/search/$search_type.$phpEx"); + include($this->phpbb_root_path . "includes/search/$search_type." . $this->phpEx); } // We do some additional checks in the module to ensure it can actually be utilised @@ -62,12 +69,10 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base */ public function is_runnable() { - global $phpbb_root_path, $phpEx, $config; - // Select the search method - $search_type = basename($config['search_type']); + $search_type = basename($this->config['search_type']); - return file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx); + return file_exists($this->phpbb_root_path . 'includes/search/' . $search_type . '.' . $this->phpEx); } /** @@ -81,7 +86,6 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base */ public function should_run() { - global $config; - return $config['search_last_gc'] < time() - $config['search_gc']; + return $this->config['search_last_gc'] < time() - $this->config['search_gc']; } } diff --git a/phpBB/includes/cron/task/core/tidy_sessions.php b/phpBB/includes/cron/task/core/tidy_sessions.php index ae7bb242b8..b409c93868 100644 --- a/phpBB/includes/cron/task/core/tidy_sessions.php +++ b/phpBB/includes/cron/task/core/tidy_sessions.php @@ -22,6 +22,14 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base { + private $config, $user; + + public function __construct(phpbb_config $config, phpbb_user $user) + { + $this->config = $config; + $this->user = $user; + } + /** * Runs this cron task. * @@ -29,8 +37,7 @@ class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base */ public function run() { - global $user; - $user->session_gc(); + $this->user->session_gc(); } /** @@ -44,7 +51,6 @@ class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base */ public function should_run() { - global $config; - return $config['session_last_gc'] < time() - $config['session_gc']; + return $this->config['session_last_gc'] < time() - $this->config['session_gc']; } } diff --git a/phpBB/includes/cron/task/core/tidy_warnings.php b/phpBB/includes/cron/task/core/tidy_warnings.php index e1434e7087..3b87a300d0 100644 --- a/phpBB/includes/cron/task/core/tidy_warnings.php +++ b/phpBB/includes/cron/task/core/tidy_warnings.php @@ -24,6 +24,15 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base { + private $phpbb_root_path, $phpEx, $config; + + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + } + /** * Runs this cron task. * @@ -31,10 +40,9 @@ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base */ public function run() { - global $phpbb_root_path, $phpEx; if (!function_exists('tidy_warnings')) { - include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + include($this->phpbb_root_path . 'includes/functions_admin.' . $this->phpEx); } tidy_warnings(); } @@ -48,8 +56,7 @@ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base */ public function is_runnable() { - global $config; - return (bool) $config['warnings_expire_days']; + return (bool) $this->config['warnings_expire_days']; } /** @@ -63,7 +70,6 @@ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base */ public function should_run() { - global $config; - return $config['warnings_last_gc'] < time() - $config['warnings_gc']; + return $this->config['warnings_last_gc'] < time() - $this->config['warnings_gc']; } } diff --git a/phpBB/includes/cron/task/provider.php b/phpBB/includes/cron/task/provider.php index 1482051699..acc3d455ec 100644 --- a/phpBB/includes/cron/task/provider.php +++ b/phpBB/includes/cron/task/provider.php @@ -15,6 +15,8 @@ if (!defined('IN_PHPBB')) exit; } +use Symfony\Component\DependencyInjection\Container; + /** * Provides cron manager with tasks * @@ -22,27 +24,30 @@ if (!defined('IN_PHPBB')) * * @package phpBB3 */ -class phpbb_cron_task_provider extends phpbb_extension_provider +class phpbb_cron_task_provider implements IteratorAggregate { + private $container; + + public function __construct(Container $container) + { + $this->container = $container; + } + /** - * Finds cron task names using the extension manager. - * - * All PHP files in includes/cron/task/core/ are considered tasks. Tasks - * in extensions have to be located in a directory called cron or a subdir - * of a directory called cron. The class and filename must end in a _task - * suffix. Additionally all PHP files in includes/cron/task/core/ are - * tasks. + * Retrieve an iterator over all items * - * @return array List of task names + * @return ArrayIterator An iterator for the array of cron tasks */ - protected function find() + public function getIterator() { - $finder = $this->extension_manager->get_finder(); + $definitions = $this->container->findTaggedServiceIds('cron.task'); + + $tasks = array(); + foreach ($definitions as $name => $definition) + { + $tasks[] = $this->container->get($name); + } - return $finder - ->extension_suffix('_task') - ->extension_directory('/cron') - ->core_path('includes/cron/task/core/') - ->get_classes(); + return new ArrayIterator($tasks); } } |