2 namespace TYPO3\CMS\Scheduler\Task;
79 $this->execution = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\
Scheduler\Execution::class);
91 abstract public function execute();
114 $this->taskUid = (int)$id;
134 return $GLOBALS[
'LANG']->sL(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
'scheduler'][
'tasks'][get_class($this)][
'title']);
144 return $GLOBALS[
'LANG']->sL(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
'scheduler'][
'tasks'][get_class($this)][
'description']);
154 return get_class($this);
176 $this->disabled =
true;
178 $this->disabled =
false;
190 $this->executionTime = (int)$timestamp;
252 $this->scheduler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\
Scheduler\Scheduler::class);
264 unset($this->scheduler);
272 public function registerSingleExecution($timestamp)
275 $execution = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\
Scheduler\Execution::class);
296 public function registerRecurringExecution($start, $interval, $end = 0, $multiple =
false, $cron_cmd =
'')
299 $execution = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\
Scheduler\Execution::class);
304 if (empty($cron_cmd)) {
345 return $this->execution->getNextExecution();
355 return $this->execution->getMultiple();
367 'SELECT' =>
'serialized_executions',
368 'FROM' =>
'tx_scheduler_task',
369 'WHERE' =>
'uid = ' . $this->taskUid,
372 $res =
$GLOBALS[
'TYPO3_DB']->exec_SELECT_queryArray($queryArr);
373 if ($row =
$GLOBALS[
'TYPO3_DB']->sql_fetch_assoc($res)) {
374 if (!empty($row[
'serialized_executions'])) {
378 $GLOBALS[
'TYPO3_DB']->sql_free_result($res);
391 'SELECT' =>
'serialized_executions',
392 'FROM' =>
'tx_scheduler_task',
393 'WHERE' =>
'uid = ' . $this->taskUid,
396 $res =
$GLOBALS[
'TYPO3_DB']->exec_SELECT_queryArray($queryArr);
397 $runningExecutions = array();
398 if ($row =
$GLOBALS[
'TYPO3_DB']->sql_fetch_assoc($res)) {
399 if ($row[
'serialized_executions'] !==
'') {
400 $runningExecutions = unserialize($row[
'serialized_executions']);
403 $GLOBALS[
'TYPO3_DB']->sql_free_result($res);
406 $numExecutions = count($runningExecutions);
407 $runningExecutions[$numExecutions] = time();
410 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
413 $GLOBALS[
'TYPO3_DB']->exec_UPDATEquery(
'tx_scheduler_task',
'uid = ' . $this->taskUid, array(
414 'serialized_executions' => serialize($runningExecutions),
415 'lastexecution_time' => time(),
416 'lastexecution_context' => $context
418 return $numExecutions;
432 'SELECT' =>
'serialized_executions',
433 'FROM' =>
'tx_scheduler_task',
434 'WHERE' =>
'uid = ' . $this->taskUid,
437 $res =
$GLOBALS[
'TYPO3_DB']->exec_SELECT_queryArray($queryArr);
438 if ($row =
$GLOBALS[
'TYPO3_DB']->sql_fetch_assoc($res)) {
439 if ($row[
'serialized_executions'] !==
'') {
440 $runningExecutions = unserialize($row[
'serialized_executions']);
442 unset($runningExecutions[$executionID]);
443 if (!empty($runningExecutions)) {
445 $runningExecutionsSerialized = serialize($runningExecutions);
447 $runningExecutionsSerialized =
'';
449 if ($failure instanceof \Exception) {
451 $logMessage =
'Task failed to execute successfully. Class: ' . get_class($this) .
', UID: ' . $this->taskUid .
'. ' . $failure->getMessage();
452 $this->scheduler->log($logMessage, 1, $failure->getCode());
454 $failureString = serialize(array(
455 'code' => $failure->getCode(),
456 'message' => $failure->getMessage(),
457 'file' => $failure->getFile(),
458 'line' => $failure->getLine(),
459 'traceString' => $failure->getTraceAsString(),
465 $GLOBALS[
'TYPO3_DB']->exec_UPDATEquery(
'tx_scheduler_task',
'uid = ' . $this->taskUid, array(
466 'serialized_executions' => $runningExecutionsSerialized,
467 'lastexecution_failure' => $failureString
471 $GLOBALS[
'TYPO3_DB']->sql_free_result($res);
482 $result =
$GLOBALS[
'TYPO3_DB']->exec_UPDATEquery(
'tx_scheduler_task',
'uid = ' . $this->taskUid, array(
483 'serialized_executions' =>
''
495 return $this->scheduler->saveTask($this);
506 $this->execution = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\
Scheduler\Execution::class);
514 public function remove()
516 $this->scheduler->removeTask($this);