execution = new Execution(); } /** * This is the main method that is called when a task is executed * It MUST be implemented by all classes inheriting from this one * Note that there is no error handling, errors and failures are expected * to be handled and logged by the client implementations. * Should return TRUE on successful execution, FALSE on error. * * @return bool Returns TRUE on successful execution, FALSE on error */ abstract public function execute(); /** * This method is designed to return some additional information about the task, * that may help to set it apart from other tasks from the same class * This additional information is used - for example - in the Scheduler's BE module * This method should be implemented in most task classes * * @return string Information to display */ public function getAdditionalInformation() { return ''; } /** * This method is used to set the unique id of the task * * @param int $id Primary key (from the database record) of the scheduled task */ public function setTaskUid($id): void { $this->taskUid = (int)$id; } /** * This method returns the unique id of the task * * @return int The id of the task */ public function getTaskUid(): int { return $this->taskUid; } /** * This method returns the disabled status of the task * * @return bool TRUE if task is disabled, FALSE otherwise */ public function isDisabled() { return $this->disabled; } /** * This method is used to set the disabled status of the task * * @param bool $flag TRUE if task should be disabled, FALSE otherwise */ public function setDisabled($flag) { if ($flag) { $this->disabled = true; } else { $this->disabled = false; } } /** * This method set the flag for next cron job execution * * @param bool $flag TRUE if task should run with the next cron job, FALSE otherwise */ public function setRunOnNextCronJob($flag) { $this->runOnNextCronJob = $flag; } /** * This method returns the run on next cron job status of the task * * @return bool TRUE if task should run on next cron job, FALSE otherwise */ public function getRunOnNextCronJob() { return $this->runOnNextCronJob; } /** * This method is used to set the timestamp corresponding to the next execution time of the task * * @param int $timestamp Timestamp of next execution */ public function setExecutionTime($timestamp) { $this->executionTime = (int)$timestamp; } /** * This method returns the task group (uid) of the task * * @return int|null Uid of task group or null if it came back from the DB without the task group set. */ public function getTaskGroup() { return $this->taskGroup; } /** * This method is used to set the task group (uid) of the task * * @param int $taskGroup Uid of task group */ public function setTaskGroup($taskGroup) { $this->taskGroup = (int)$taskGroup; } /** * This method returns the timestamp corresponding to the next execution time of the task * * @return int Timestamp of next execution */ public function getExecutionTime() { return $this->executionTime; } /** * This method is used to set the description of the task * * @param string $description Description */ public function setDescription($description): void { $this->description = (string)$description; } /** * This method returns the description of the task * * @return string Description */ public function getDescription() { return $this->description; } /** * Sets the internal execution object * * @param Execution $execution The execution to add * @internal since TYPO3 v12.3, not part of TYPO3 Public API anymore. */ public function setExecution(Execution $execution): void { $this->execution = $execution; } /** * Returns the execution object * * @return Execution|object|null The internal execution object - when an invalid task is being unserialized, the Execution object might not be available * @internal since TYPO3 v12.3, not part of TYPO3 Public API anymore. */ public function getExecution() { return $this->execution; } /** * Guess recurring type from the existing information * If an interval or a cron command is defined, it's a recurring task */ public function getType(): int { if ($this->execution->isRecurring()) { return self::TYPE_RECURRING; } return self::TYPE_SINGLE; } protected function logException(\Exception $e) { $this->logger?->error('A Task Exception was captured.', ['exception' => $e]); } protected function getLanguageService(): ?LanguageService { return $GLOBALS['LANG'] ?? null; } public function getTaskType(): string { return static::class; } /** * It is recommended to implement this method in the respective task class. */ public function getTaskParameters(): array { $vars = get_object_vars($this); $parameters = []; foreach ($vars as $key => $value) { $key = trim($key); $key = trim($key, "*\0"); $key = trim($key); $parameters[$key] = $value; } unset( // Needs to be kept until TYPO3 v16.0 until the upgrade wizard was run through $parameters['scheduler'], $parameters['logger'], $parameters['taskUid'], $parameters['disabled'], $parameters['runOnNextCronJob'], $parameters['execution'], $parameters['executionTime'], $parameters['description'], $parameters['taskGroup'], ); return $parameters; } /** * Used to fill fields of this class, e.g. also when instantiating this class when no parameters are * given but native DB fields are coming in. * @param array $parameters */ public function setTaskParameters(array $parameters): void { foreach ($parameters as $key => $value) { // Ensure a member property exists; Task objects might have old configuration data changed with // attributes that were removed meanwhile. This would otherwise trigger a PHP notice like // "PHP Runtime Deprecation Notice: Creation of dynamic property TYPO3\CMS\Linkvalidator\Task\ValidatorTask::$fileConfiguration is deprecated" if (property_exists($this, $key)) { $this->{$key} = $value; } } } }