From abb8a2892d862c097285ee7f300d12c32428e12c Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Tue, 27 May 2014 12:36:44 +0200 Subject: [ticket/12597] Command for executing all available cron tasks Command cron:execute-all executes all available cron tasks. Test files in tests/console/cron folder PHPBB3-12597 --- phpBB/cron.php | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) (limited to 'phpBB/cron.php') diff --git a/phpBB/cron.php b/phpBB/cron.php index f63642faa2..a8333aecaf 100644 --- a/phpBB/cron.php +++ b/phpBB/cron.php @@ -39,11 +39,6 @@ function do_cron($cron_lock, $run_tasks) foreach ($run_tasks as $task) { - if (defined('DEBUG') && $config['use_system_cron']) - { - echo "[phpBB cron] Running task '{$task->get_name()}'\n"; - } - $task->run(); } @@ -59,38 +54,28 @@ function do_cron($cron_lock, $run_tasks) // // If DEBUG is defined and cron lock cannot be obtained, a message will be printed. -if (!$config['use_system_cron']) -{ - $cron_type = request_var('cron_type', ''); +$cron_type = request_var('cron_type', ''); - // Comment this line out for debugging so the page does not return an image. - output_image(); -} +// Comment this line out for debugging so the page does not return an image. +output_image(); $cron_lock = $phpbb_container->get('cron.lock_db'); if ($cron_lock->acquire()) { $cron = $phpbb_container->get('cron.manager'); - if ($config['use_system_cron']) + // If invalid task is specified, empty $run_tasks is passed to do_cron which then does nothing + $run_tasks = array(); + $task = $cron->find_task($cron_type); + if ($task) { - $run_tasks = $cron->find_all_ready_tasks(); - } - else - { - // If invalid task is specified, empty $run_tasks is passed to do_cron which then does nothing - $run_tasks = array(); - $task = $cron->find_task($cron_type); - if ($task) + if ($task->is_parametrized()) + { + $task->parse_parameters($request); + } + if ($task->is_ready()) { - if ($task->is_parametrized()) - { - $task->parse_parameters($request); - } - if ($task->is_ready()) - { - $run_tasks = array($task); - } + $run_tasks = array($task); } } @@ -100,6 +85,6 @@ else { if (defined('DEBUG')) { - echo "Could not obtain cron lock.\n"; + echo $this->user->lang('CRON_LOCK_ERROR') . '\n'; } } -- cgit v1.2.1 From 6f0121e2a49eca777f6767f5c254878f7a255fa9 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Wed, 28 May 2014 12:36:55 +0200 Subject: [ticket/12597] Correcting bug in cron.php PHPBB3-12597 --- phpBB/cron.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/cron.php') diff --git a/phpBB/cron.php b/phpBB/cron.php index a8333aecaf..c708527d99 100644 --- a/phpBB/cron.php +++ b/phpBB/cron.php @@ -85,6 +85,6 @@ else { if (defined('DEBUG')) { - echo $this->user->lang('CRON_LOCK_ERROR') . '\n'; + echo $user->lang('CRON_LOCK_ERROR') . "\n"; } } -- cgit v1.2.1 From 9761c1bf617763671308fabc569ec13d40cb6843 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Wed, 28 May 2014 12:57:49 +0200 Subject: [ticket/12597] Fix various refactoring mistakes PHPBB3-12597 --- phpBB/cron.php | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'phpBB/cron.php') diff --git a/phpBB/cron.php b/phpBB/cron.php index c708527d99..b35d16632a 100644 --- a/phpBB/cron.php +++ b/phpBB/cron.php @@ -33,20 +33,6 @@ function output_image() flush(); } -function do_cron($cron_lock, $run_tasks) -{ - global $config; - - foreach ($run_tasks as $task) - { - $task->run(); - } - - // Unloading cache and closing db after having done the dirty work. - $cron_lock->release(); - garbage_collection(); -} - // Thanks to various fatal errors and lack of try/finally, it is quite easy to leave // the cron lock locked, especially when working on cron-related code. // @@ -65,7 +51,6 @@ if ($cron_lock->acquire()) $cron = $phpbb_container->get('cron.manager'); // If invalid task is specified, empty $run_tasks is passed to do_cron which then does nothing - $run_tasks = array(); $task = $cron->find_task($cron_type); if ($task) { @@ -75,11 +60,12 @@ if ($cron_lock->acquire()) } if ($task->is_ready()) { - $run_tasks = array($task); + $task->run(); + $cron_lock->release(); + garbage_collection(); } } - do_cron($cron_lock, $run_tasks); } else { -- cgit v1.2.1 From 6f279c1bf47c4c86a507acc9ea7d705dad6e9b97 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Wed, 28 May 2014 14:39:02 +0200 Subject: [ticket/12597] Update pull-request Removes a useless comment. Switchs command name from cron:execute-all to cron:run-all. Replaces assertEquals by assertSame PHPBB3-12597 --- phpBB/cron.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/cron.php') diff --git a/phpBB/cron.php b/phpBB/cron.php index b35d16632a..0c1397979d 100644 --- a/phpBB/cron.php +++ b/phpBB/cron.php @@ -50,7 +50,6 @@ if ($cron_lock->acquire()) { $cron = $phpbb_container->get('cron.manager'); - // If invalid task is specified, empty $run_tasks is passed to do_cron which then does nothing $task = $cron->find_task($cron_type); if ($task) { -- cgit v1.2.1 From 5fca30813809c4fbbcad0ffc12903eda6279b88b Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Wed, 28 May 2014 16:47:57 +0200 Subject: [ticket/12597] Fix misplaced release of db lock PHPBB3-12597 --- phpBB/cron.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/cron.php') diff --git a/phpBB/cron.php b/phpBB/cron.php index 0c1397979d..0cae2ea130 100644 --- a/phpBB/cron.php +++ b/phpBB/cron.php @@ -60,10 +60,10 @@ if ($cron_lock->acquire()) if ($task->is_ready()) { $task->run(); - $cron_lock->release(); garbage_collection(); } } + $cron_lock->release(); } else -- cgit v1.2.1