‪TYPO3CMS  9.5
Task.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
22 
27 class ‪Task extends ‪AbstractTask
28 {
32  protected ‪$commandIdentifier;
33 
37  protected ‪$arguments = [];
38 
42  protected ‪$defaults = [];
43 
47  protected ‪$objectManager;
48 
52  protected ‪$commandManager;
53 
57  protected ‪$taskExecutor;
58 
62  public function ‪__construct()
63  {
64  parent::__construct();
65  $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
66  $this->commandManager = $this->objectManager->get(CommandManager::class);
67  $this->taskExecutor = $this->objectManager->get(TaskExecutor::class);
68  }
69 
75  public function ‪__sleep()
76  {
77  $properties = get_object_vars($this);
78  unset(
79  $properties['commandManager'],
80  $properties['objectManager'],
81  $properties['taskExecutor'],
82  $properties['logger']
83  );
84  return array_keys($properties);
85  }
86 
90  public function ‪__wakeup()
91  {
92  $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
93  $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
94  $this->commandManager = $this->objectManager->get(CommandManager::class);
95  $this->taskExecutor = $this->objectManager->get(TaskExecutor::class);
96  }
97 
104  public function ‪execute()
105  {
106  try {
107  $this->taskExecutor->execute($this);
108  } catch (\Exception $e) {
109  $this->‪logException($e);
110  // Make sure the Scheduler gets exception details
111  throw $e;
112  }
113  return true;
114  }
115 
120  {
121  $this->commandIdentifier = ‪$commandIdentifier;
122  }
123 
127  public function ‪getCommandIdentifier()
128  {
130  }
131 
135  public function ‪setArguments(‪$arguments)
136  {
137  $this->arguments = ‪$arguments;
138  }
139 
143  public function ‪getArguments()
144  {
146  }
147 
151  public function ‪setDefaults(array ‪$defaults)
152  {
153  $this->defaults = ‪$defaults;
154  }
155 
159  public function ‪getDefaults()
160  {
161  return ‪$this->defaults;
162  }
163 
168  public function ‪addDefaultValue($argumentName, $argumentValue)
169  {
170  if (is_bool($argumentValue)) {
171  $argumentValue = (int)$argumentValue;
172  }
173  $this->defaults[$argumentName] = $argumentValue;
174  }
175 
181  public function ‪getAdditionalInformation()
182  {
184  if (!empty($this->arguments)) {
185  ‪$arguments = [];
186  foreach ($this->arguments as $argumentName => $argumentValue) {
187  if (!isset($this->defaults[$argumentName]) || $argumentValue != $this->defaults[$argumentName]) {
188  ‪$arguments[] = $argumentName . '=' . $argumentValue;
189  }
190  }
191  $label .= ' ' . implode(', ', ‪$arguments);
192  }
193  return $label;
194  }
195 
199  protected function ‪logException(\‪Exception $e)
200  {
201  $this->logger->error('A Task (' . $this->commandIdentifier . ') Exception was captured: ' . $e->getMessage() . ' (' . $e->getCode() . ')', ['exception' => $e]);
202  }
203 }
‪TYPO3\CMS\Extbase\Scheduler\Task\setDefaults
‪setDefaults(array $defaults)
Definition: Task.php:145
‪TYPO3\CMS\Extbase\Scheduler
Definition: FieldProvider.php:2
‪TYPO3\CMS\Extbase\Scheduler\Task\getArguments
‪array getArguments()
Definition: Task.php:137
‪TYPO3\CMS\Extbase\Scheduler\Task\setCommandIdentifier
‪setCommandIdentifier($commandIdentifier)
Definition: Task.php:113
‪TYPO3\CMS\Extbase\Scheduler\TaskExecutor
Definition: TaskExecutor.php:25
‪TYPO3\CMS\Extbase\Scheduler\Task\__construct
‪__construct()
Definition: Task.php:56
‪TYPO3\CMS\Extbase\Scheduler\Task\setArguments
‪setArguments($arguments)
Definition: Task.php:129
‪TYPO3\CMS\Extbase\Scheduler\Task\__sleep
‪array __sleep()
Definition: Task.php:69
‪TYPO3\CMS\Extbase\Scheduler\Task\$arguments
‪array $arguments
Definition: Task.php:35
‪TYPO3\CMS\Extbase\Scheduler\Task
Definition: Task.php:28
‪TYPO3\CMS\Extbase\Scheduler\Task\execute
‪bool execute()
Definition: Task.php:98
‪TYPO3\CMS\Extbase\Scheduler\Task\$commandManager
‪CommandManager $commandManager
Definition: Task.php:47
‪TYPO3\CMS\Extbase\Scheduler\Task\$objectManager
‪TYPO3 CMS Extbase Object ObjectManagerInterface $objectManager
Definition: Task.php:43
‪TYPO3\CMS\Extbase\Scheduler\Task\getAdditionalInformation
‪string getAdditionalInformation()
Definition: Task.php:175
‪TYPO3\CMS\Extbase\Exception
Definition: Exception.php:23
‪TYPO3\CMS\Extbase\Scheduler\Task\$defaults
‪array $defaults
Definition: Task.php:39
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:32
‪TYPO3\CMS\Extbase\Mvc\Cli\CommandManager
Definition: CommandManager.php:23
‪TYPO3\CMS\Extbase\Scheduler\Task\$commandIdentifier
‪string $commandIdentifier
Definition: Task.php:31
‪TYPO3\CMS\Extbase\Scheduler\Task\__wakeup
‪__wakeup()
Definition: Task.php:84
‪TYPO3\CMS\Extbase\Scheduler\Task\logException
‪logException(\Exception $e)
Definition: Task.php:193
‪TYPO3\CMS\Extbase\Scheduler\Task\addDefaultValue
‪addDefaultValue($argumentName, $argumentValue)
Definition: Task.php:162
‪TYPO3\CMS\Core\Log\LogManager
Definition: LogManager.php:25
‪TYPO3\CMS\Extbase\Scheduler\Task\getCommandIdentifier
‪string getCommandIdentifier()
Definition: Task.php:121
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extbase\Scheduler\Task\getDefaults
‪array getDefaults()
Definition: Task.php:153
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25
‪TYPO3\CMS\Extbase\Scheduler\Task\$taskExecutor
‪TaskExecutor $taskExecutor
Definition: Task.php:51