TYPO3 CMS  TYPO3_6-2
Task.php
Go to the documentation of this file.
1 <?php
3 
20 
24  protected $commandIdentifier;
25 
29  protected $arguments = array();
30 
34  protected $defaults = array();
35 
39  protected $objectManager;
40 
44  protected $commandManager;
45 
49  protected $taskExecutor;
50 
54  public function __construct() {
55  parent::__construct();
56  $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
57  $this->commandManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\CommandManager');
58  $this->taskExecutor = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Scheduler\\TaskExecutor');
59  }
60 
66  public function __sleep() {
67  $properties = get_object_vars($this);
68  unset($properties['commandManager']);
69  unset($properties['objectManager']);
70  unset($properties['taskExecutor']);
71  return array_keys($properties);
72  }
73 
79  public function __wakeup() {
80  $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
81  $this->commandManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\CommandManager');
82  $this->taskExecutor = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Scheduler\\TaskExecutor');
83  }
84 
91  public function execute() {
92  try {
93  $this->taskExecutor->execute($this);
94  } catch (\Exception $e) {
95  $this->logException($e);
96  // Make sure the Scheduler gets exception details
97  throw $e;
98  }
99  return TRUE;
100  }
101 
106  $this->commandIdentifier = $commandIdentifier;
107  }
108 
112  public function getCommandIdentifier() {
114  }
115 
119  public function setArguments($arguments) {
120  $this->arguments = $arguments;
121  }
122 
126  public function getArguments() {
127  return $this->arguments;
128  }
129 
133  public function setDefaults(array $defaults) {
134  $this->defaults = $defaults;
135  }
136 
140  public function getDefaults() {
141  return $this->defaults;
142  }
143 
148  public function addDefaultValue($argumentName, $argumentValue) {
149  if (is_bool($argumentValue)) {
150  $argumentValue = (int)$argumentValue;
151  }
152  $this->defaults[$argumentName] = $argumentValue;
153  }
154 
160  public function getAdditionalInformation() {
161  $label = $this->commandIdentifier;
162  if (count($this->arguments) > 0) {
163  $arguments = array();
164  foreach ($this->arguments as $argumentName => $argumentValue) {
165  if ($argumentValue != $this->defaults[$argumentName]) {
166  array_push($arguments, $argumentName . '=' . $argumentValue);
167  }
168  }
169  $label .= ' ' . implode(', ', $arguments);
170  }
171  return $label;
172  }
173 
177  protected function logException(\Exception $e) {
178  \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($e->getMessage(), $this->commandIdentifier, 3);
179  }
180 }
setDefaults(array $defaults)
Definition: Task.php:133
addDefaultValue($argumentName, $argumentValue)
Definition: Task.php:148
setCommandIdentifier($commandIdentifier)
Definition: Task.php:105
logException(\Exception $e)
Definition: Task.php:177