mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-24 18:41:52 +02:00
[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
This commit is contained in:
@@ -46,6 +46,15 @@ services:
|
||||
tags:
|
||||
- { name: console.command }
|
||||
|
||||
console.command.cron.execute_all:
|
||||
class: phpbb\console\command\cron\execute_all
|
||||
arguments:
|
||||
- @cron.manager
|
||||
- @cron.lock_db
|
||||
- @user
|
||||
tags:
|
||||
- { name: console.command }
|
||||
|
||||
console.command.db.migrate:
|
||||
class: phpbb\console\command\db\migrate
|
||||
arguments:
|
||||
|
@@ -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())
|
||||
{
|
||||
if ($task->is_parametrized())
|
||||
{
|
||||
$task->parse_parameters($request);
|
||||
}
|
||||
if ($task->is_ready())
|
||||
{
|
||||
$run_tasks = array($task);
|
||||
}
|
||||
$task->parse_parameters($request);
|
||||
}
|
||||
if ($task->is_ready())
|
||||
{
|
||||
$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';
|
||||
}
|
||||
}
|
||||
|
@@ -221,8 +221,11 @@ $lang = array_merge($lang, array(
|
||||
|
||||
'BACK' => 'Back',
|
||||
|
||||
'CLI_DESCR_CRON_EXECUTE_ALL' => 'Executes all available cron tasks.',
|
||||
|
||||
'COLOUR_SWATCH' => 'Web-safe colour swatch',
|
||||
'CONFIG_UPDATED' => 'Configuration updated successfully.',
|
||||
'CRON_LOCK_ERROR' => 'Could not obtain cron lock.',
|
||||
|
||||
'DEACTIVATE' => 'Deactivate',
|
||||
'DIRECTORY_DOES_NOT_EXIST' => 'The entered path “%s” does not exist.',
|
||||
@@ -283,6 +286,7 @@ $lang = array_merge($lang, array(
|
||||
'REMIND' => 'Remind',
|
||||
'RESYNC' => 'Resynchronise',
|
||||
|
||||
'RUNNING_TASK' => 'Running task: %s.',
|
||||
'SELECT_ANONYMOUS' => 'Select anonymous user',
|
||||
'SELECT_OPTION' => 'Select option',
|
||||
|
||||
|
65
phpBB/phpbb/console/command/cron/execute_all.php
Normal file
65
phpBB/phpbb/console/command/cron/execute_all.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package phpBB3
|
||||
* @copyright (c) 2014 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
namespace phpbb\console\command\cron;
|
||||
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class execute_all extends \phpbb\console\command\command
|
||||
{
|
||||
/** @var \phpbb\cron\manager */
|
||||
protected $cron_manager;
|
||||
|
||||
/** @var \phpbb\lock\db */
|
||||
protected $lock_db;
|
||||
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
public function __construct(\phpbb\cron\manager $cron_manager, \phpbb\lock\db $lock_db, \phpbb\user $user)
|
||||
{
|
||||
$this->cron_manager = $cron_manager;
|
||||
$this->lock_db = $lock_db;
|
||||
$this->user = $user;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('cron:execute-all')
|
||||
->setDescription($this->user->lang('CLI_DESCR_CRON_EXECUTE_ALL'))
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if ($this->lock_db->acquire())
|
||||
{
|
||||
$run_tasks = $this->cron_manager->find_all_ready_tasks();
|
||||
|
||||
foreach ($run_tasks as $task)
|
||||
{
|
||||
if ($input->getOption('verbose'))
|
||||
{
|
||||
$output->writeln($this->user->lang('RUNNING_TASK', $task->get_name()) . "\n");
|
||||
}
|
||||
|
||||
$task->run();
|
||||
}
|
||||
$this->lock_db->release();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln('<error>' . $this->user->lang('CRON_LOCK_ERROR') . '</error>');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user