17 use Symfony\Component\Console\Command\Command;
18 use Symfony\Component\Console\Input\InputInterface;
19 use Symfony\Component\Console\Input\InputOption;
20 use Symfony\Component\Console\Output\OutputInterface;
47 ->setDescription(
'Start the TYPO3 Scheduler from the command line.')
48 ->setHelp(
'If no parameter is given, the scheduler executes any tasks that are overdue to run.
49 Call it like this: typo3/sysext/core/bin/typo3 scheduler:run --task=13 -f')
53 InputOption::VALUE_REQUIRED,
54 'UID of a specific task'
59 InputOption::VALUE_NONE,
60 'Force execution of the task which is passed with -i option'
65 InputOption::VALUE_NONE,
66 'Stop the task which is passed with -i option'
81 $this->scheduler = GeneralUtility::makeInstance(Scheduler::class);
83 if ((
int)$input->getOption(
'task') > 0) {
84 $taskUid = (int)$input->getOption(
'task');
85 $stopTask = (bool)($input->hasOption(
'stop') && $input->getOption(
'stop'));
86 $force = (bool)($input->hasOption(
'force') && $input->getOption(
'force'));
87 $task = $this->
getTask($taskUid, $stopTask || $force);
89 if ($this->scheduler->isValidTaskObject($task)) {
93 $this->scheduler->executeTask($task);
97 $this->scheduler->recordLastRun(
'cli-by-id');
110 if ($this->scheduler->isValidTaskObject($task)) {
111 $task->unmarkAllExecutions();
122 protected function getTask(
int $taskUid,
bool $force)
125 $task = $this->scheduler->fetchTask($taskUid);
127 $whereClause =
'uid = ' . (int)$taskUid .
' AND nextexecution != 0 AND nextexecution <= ' .
$GLOBALS[
'EXEC_TIME'];
128 list($task) = $this->scheduler->fetchTasksWithCondition($whereClause);
143 $task = $this->scheduler->fetchTask();
145 $this->scheduler->executeTask($task);
146 }
catch (\Exception $e) {
152 }
catch (\OutOfBoundsException $e) {
153 $this->hasTask =
false;
154 }
catch (\UnexpectedValueException $e) {
157 }
while ($this->hasTask);
159 $this->scheduler->recordLastRun();