[TASK] Update copyright year to 2013
[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 $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
70 $this->commandManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\CommandManager');
71 $this->taskExecutor = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Scheduler\\TaskExecutor');
72 }
73
74 /**
75 * Function execute from the Scheduler
76 *
77 * @return boolean TRUE on successful execution, FALSE on error
78 */
79 public function execute() {
80 try {
81 $this->taskExecutor->execute($this);
82 return TRUE;
83 } catch (\Exception $e) {
84 $this->logException($e);
85 return FALSE;
86 }
87 }
88
89 /**
90 * @param string $commandIdentifier
91 */
92 public function setCommandIdentifier($commandIdentifier) {
93 $this->commandIdentifier = $commandIdentifier;
94 }
95
96 /**
97 * @return string
98 */
99 public function getCommandIdentifier() {
100 return $this->commandIdentifier;
101 }
102
103 /**
104 * @param array $arguments
105 */
106 public function setArguments($arguments) {
107 $this->arguments = $arguments;
108 }
109
110 /**
111 * @return array
112 */
113 public function getArguments() {
114 return $this->arguments;
115 }
116
117 /**
118 * @param array $defaults
119 */
120 public function setDefaults(array $defaults) {
121 $this->defaults = $defaults;
122 }
123
124 /**
125 * @return array
126 */
127 public function getDefaults() {
128 return $this->defaults;
129 }
130
131 /**
132 * @param string $argumentName
133 * @param mixed $argumentValue
134 */
135 public function addDefaultValue($argumentName, $argumentValue) {
136 if (is_bool($argumentValue)) {
137 $argumentValue = intval($argumentValue);
138 }
139 $this->defaults[$argumentName] = $argumentValue;
140 }
141
142 /**
143 * Return a text representation of the selected command and arguments
144 *
145 * @return string Information to display
146 */
147 public function getAdditionalInformation() {
148 $label = $this->commandIdentifier;
149 if (count($this->arguments) > 0) {
150 $arguments = array();
151 foreach ($this->arguments as $argumentName => $argumentValue) {
152 if ($argumentValue != $this->defaults[$argumentName]) {
153 array_push($arguments, $argumentName . '=' . $argumentValue);
154 }
155 }
156 $label .= ' ' . implode(', ', $arguments);
157 }
158 return $label;
159 }
160
161 /**
162 * @param \Exception $e
163 */
164 protected function logException(\Exception $e) {
165 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($e->getMessage(), $this->commandIdentifier, 3);
166 }
167 }
168
169 ?>