[TASK] Merge submodule workspaces into core
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Scheduler / Task.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Scheduler;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
8 * Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * Scheduler task to execute CommandController commands
32 */
33 class Task extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
34
35 /**
36 * @var string
37 */
38 protected $commandIdentifier;
39
40 /**
41 * @var array
42 */
43 protected $arguments = array();
44
45 /**
46 * @var array
47 */
48 protected $defaults = array();
49
50 /**
51 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
52 */
53 protected $objectManager;
54
55 /**
56 * @var \TYPO3\CMS\Extbase\Mvc\Cli\CommandManager
57 */
58 protected $commandManager;
59
60 /**
61 * @var \TYPO3\CMS\Extbase\Scheduler\TaskExecutor
62 */
63 protected $taskExecutor;
64
65 /**
66 * Intanciates the Object Manager
67 */
68 public function __construct() {
69 parent::__construct();
70 $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
71 $this->commandManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\CommandManager');
72 $this->taskExecutor = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Scheduler\\TaskExecutor');
73 }
74
75 /**
76 * Function execute from the Scheduler
77 *
78 * @return boolean TRUE on successful execution, FALSE on error
79 */
80 public function execute() {
81 try {
82 $this->taskExecutor->execute($this);
83 return TRUE;
84 } catch (\Exception $e) {
85 $this->logException($e);
86 return FALSE;
87 }
88 }
89
90 /**
91 * @param string $commandIdentifier
92 */
93 public function setCommandIdentifier($commandIdentifier) {
94 $this->commandIdentifier = $commandIdentifier;
95 }
96
97 /**
98 * @return string
99 */
100 public function getCommandIdentifier() {
101 return $this->commandIdentifier;
102 }
103
104 /**
105 * @param array $arguments
106 */
107 public function setArguments($arguments) {
108 $this->arguments = $arguments;
109 }
110
111 /**
112 * @return array
113 */
114 public function getArguments() {
115 return $this->arguments;
116 }
117
118 /**
119 * @param array $defaults
120 */
121 public function setDefaults(array $defaults) {
122 $this->defaults = $defaults;
123 }
124
125 /**
126 * @return array
127 */
128 public function getDefaults() {
129 return $this->defaults;
130 }
131
132 /**
133 * @param string $argumentName
134 * @param mixed $argumentValue
135 */
136 public function addDefaultValue($argumentName, $argumentValue) {
137 if (is_bool($argumentValue)) {
138 $argumentValue = intval($argumentValue);
139 }
140 $this->defaults[$argumentName] = $argumentValue;
141 }
142
143 /**
144 * Return a text representation of the selected command and arguments
145 *
146 * @return string Information to display
147 */
148 public function getAdditionalInformation() {
149 $label = $this->commandIdentifier;
150 if (count($this->arguments) > 0) {
151 $arguments = array();
152 foreach ($this->arguments as $argumentName => $argumentValue) {
153 if ($argumentValue != $this->defaults[$argumentName]) {
154 array_push($arguments, $argumentName . '=' . $argumentValue);
155 }
156 }
157 $label .= ' ' . implode(', ', $arguments);
158 }
159 return $label;
160 }
161
162 /**
163 * @param \Exception $e
164 */
165 protected function logException(\Exception $e) {
166 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($e->getMessage(), $this->commandIdentifier, 3);
167 }
168 }
169
170 ?>