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