Skip to content

Commit 05e9d08

Browse files
bmacksbuerk
authored andcommitted
[TASK] Separate execution logic in scheduler task
Some helper methods of AbstractTask are moved to Factory methods within the Execution class. Resolves: #106647 Releases: main Change-Id: Ibb4fcf0b142bf3054200da2913fd54b46d5df210 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/89292 Tested-by: Stefan Bürk <stefan@buerk.tech> Tested-by: core-ci <typo3@b13.com> Reviewed-by: Stefan Bürk <stefan@buerk.tech> Tested-by: Andreas Kienast <akienast@scripting-base.de> Reviewed-by: Andreas Kienast <akienast@scripting-base.de>
1 parent 140669d commit 05e9d08

File tree

3 files changed

+63
-64
lines changed

3 files changed

+63
-64
lines changed

typo3/sysext/scheduler/Classes/Controller/SchedulerModuleController.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use TYPO3\CMS\Scheduler\Domain\Repository\SchedulerTaskRepository;
4545
use TYPO3\CMS\Scheduler\Exception\InvalidDateException;
4646
use TYPO3\CMS\Scheduler\Exception\InvalidTaskException;
47+
use TYPO3\CMS\Scheduler\Execution;
4748
use TYPO3\CMS\Scheduler\Scheduler;
4849
use TYPO3\CMS\Scheduler\SchedulerManagementAction;
4950
use TYPO3\CMS\Scheduler\Service\TaskService;
@@ -297,7 +298,8 @@ protected function toggleDisabledFlag(ModuleTemplate $view, int $taskUid): void
297298
$isTaskDisabled = $task->isDisabled();
298299
if ($isTaskDisabled && $isTaskQueuedForExecution) {
299300
$task->setDisabled(false);
300-
$task->registerSingleExecution($this->context->getAspect('date')->get('timestamp'));
301+
$execution = Execution::createSingleExecution($this->context->getAspect('date')->get('timestamp'));
302+
$task->setExecution($execution);
301303
$this->addMessage($view, sprintf($languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.taskEnabledAndQueuedForExecution'), $taskName, $taskUid));
302304
} elseif ($isTaskDisabled) {
303305
$task->setDisabled(false);
@@ -714,16 +716,17 @@ protected function setTaskDataFromRequest(AbstractTask $task, ServerRequestInter
714716
{
715717
$parsedBody = $request->getParsedBody()['tx_scheduler'];
716718
if ((int)$parsedBody['runningType'] === AbstractTask::TYPE_SINGLE) {
717-
$task->registerSingleExecution($this->getTimestampFromDateString($parsedBody['start']));
719+
$execution = Execution::createSingleExecution($this->getTimestampFromDateString($parsedBody['start']));
718720
} else {
719-
$task->registerRecurringExecution(
721+
$execution = Execution::createRecurringExecution(
720722
$this->getTimestampFromDateString($parsedBody['start']),
721723
is_numeric($parsedBody['frequency']) ? (int)$parsedBody['frequency'] : 0,
722724
!empty($parsedBody['end'] ?? '') ? $this->getTimestampFromDateString($parsedBody['end']) : 0,
723725
(bool)($parsedBody['multiple'] ?? false),
724726
!is_numeric($parsedBody['frequency']) ? $parsedBody['frequency'] : '',
725727
);
726728
}
729+
$task->setExecution($execution);
727730
$task->setDisabled($parsedBody['disable'] ?? false);
728731
$task->setDescription($parsedBody['description'] ?? '');
729732
$task->setTaskGroup((int)($parsedBody['task_group'] ?? 0));

typo3/sysext/scheduler/Classes/Execution.php

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,63 @@ class Execution
6868
*/
6969
protected $isNewSingleExecution = false;
7070

71+
public static function createFromDetails(array $details): self
72+
{
73+
$obj = new self();
74+
$obj->setStart((int)$details['start']);
75+
$obj->setEnd((int)$details['end']);
76+
$obj->setInterval((int)$details['interval']);
77+
$obj->setMultiple((bool)$details['multiple']);
78+
$obj->setCronCmd((string)$details['cronCmd']);
79+
$obj->setIsNewSingleExecution((bool)$details['isNewSingleExecution']);
80+
return $obj;
81+
}
82+
83+
/**
84+
* Registers a single execution of the task
85+
*
86+
* @param int $timestamp Timestamp of the next execution
87+
*/
88+
public static function createSingleExecution(int $timestamp): self
89+
{
90+
$obj = new self();
91+
$obj->setStart($timestamp);
92+
$obj->setInterval(0);
93+
$obj->setEnd($timestamp);
94+
$obj->setCronCmd('');
95+
$obj->setMultiple(false);
96+
$obj->setIsNewSingleExecution(true);
97+
return $obj;
98+
}
99+
100+
/**
101+
* Registers a recurring execution of the task
102+
*
103+
* @param int $start The first date/time when this execution should occur (timestamp)
104+
* @param int $interval Execution interval in seconds
105+
* @param int $end The last date/time when this execution should occur (timestamp)
106+
* @param bool $multiple Set to FALSE if multiple executions of this task are not permitted in parallel
107+
* @param string $cronCmd Used like in crontab (minute hour day month weekday)
108+
*/
109+
public static function createRecurringExecution(int $start, int $interval, int $end = 0, bool $multiple = false, string $cronCmd = ''): self
110+
{
111+
$obj = new self();
112+
// Set general values
113+
$obj->setStart($start);
114+
$obj->setEnd($end);
115+
$obj->setMultiple($multiple);
116+
if (empty($cronCmd)) {
117+
// Use interval
118+
$obj->setInterval($interval);
119+
$obj->setCronCmd('');
120+
} else {
121+
// Use cron syntax
122+
$obj->setInterval(0);
123+
$obj->setCronCmd($cronCmd);
124+
}
125+
return $obj;
126+
}
127+
71128
/**********************************
72129
* Setters and getters
73130
**********************************/
@@ -282,18 +339,6 @@ public function isEnded()
282339
return $result;
283340
}
284341

285-
public static function createFromDetails(array $details): self
286-
{
287-
$obj = new self();
288-
$obj->setStart((int)$details['start']);
289-
$obj->setEnd((int)$details['end']);
290-
$obj->setInterval((int)$details['interval']);
291-
$obj->setMultiple((bool)$details['multiple']);
292-
$obj->setCronCmd((string)$details['cronCmd']);
293-
$obj->setIsNewSingleExecution((bool)$details['isNewSingleExecution']);
294-
return $obj;
295-
}
296-
297342
public function toArray(): array
298343
{
299344
// The type cast is necessary as long as the DB migration (upgrade wizard) exists,

typo3/sysext/scheduler/Classes/Task/AbstractTask.php

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -301,55 +301,6 @@ public function unsetScheduler()
301301
unset($this->logger);
302302
}
303303

304-
/**
305-
* Registers a single execution of the task
306-
*
307-
* @param int $timestamp Timestamp of the next execution
308-
* @internal since TYPO3 v12.3, not part of TYPO3 Public API anymore.
309-
*/
310-
public function registerSingleExecution($timestamp)
311-
{
312-
$execution = new Execution();
313-
$execution->setStart($timestamp);
314-
$execution->setInterval(0);
315-
$execution->setEnd($timestamp);
316-
$execution->setCronCmd('');
317-
$execution->setMultiple(false);
318-
$execution->setIsNewSingleExecution(true);
319-
// Replace existing execution object
320-
$this->execution = $execution;
321-
}
322-
323-
/**
324-
* Registers a recurring execution of the task
325-
*
326-
* @param int $start The first date/time where this execution should occur (timestamp)
327-
* @param int $interval Execution interval in seconds
328-
* @param int $end The last date/time where this execution should occur (timestamp)
329-
* @param bool $multiple Set to FALSE if multiple executions of this task are not permitted in parallel
330-
* @param string $cron_cmd Used like in crontab (minute hour day month weekday)
331-
* @internal since TYPO3 v12.3, not part of TYPO3 Public API anymore.
332-
*/
333-
public function registerRecurringExecution($start, $interval, $end = 0, $multiple = false, $cron_cmd = '')
334-
{
335-
$execution = GeneralUtility::makeInstance(Execution::class);
336-
// Set general values
337-
$execution->setStart($start);
338-
$execution->setEnd($end);
339-
$execution->setMultiple($multiple);
340-
if (empty($cron_cmd)) {
341-
// Use interval
342-
$execution->setInterval($interval);
343-
$execution->setCronCmd('');
344-
} else {
345-
// Use cron syntax
346-
$execution->setInterval(0);
347-
$execution->setCronCmd($cron_cmd);
348-
}
349-
// Replace existing execution object
350-
$this->execution = $execution;
351-
}
352-
353304
/**
354305
* Sets the internal execution object
355306
*

0 commit comments

Comments
 (0)