2 /***************************************************************
5 * (c) 2011 Claus Due, Wildside A/S <claus@wildside.dk>
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.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
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.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
28 * Takes a Tx_Extbase_Scheduler_Task and executes the CommandController command
32 * @subpackage Scheduler
34 class Tx_Extbase_Scheduler_TaskExecutor
implements t3lib_Singleton
{
37 * @var Tx_Extbase_Object_ObjectManagerInterface
39 protected $objectManager;
42 * @var Tx_Extbase_MVC_CLI_CommandManager
44 protected $commandManager;
47 * @var Tx_Extbase_Configuration_ConfigurationManagerInterface
49 protected $configurationManager;
52 * @param Tx_Extbase_Object_ObjectManager $objectManager
54 public function injectObjectManager(Tx_Extbase_Object_ObjectManager
$objectManager) {
55 $this->objectManager
= $objectManager;
59 * @param Tx_Extbase_MVC_CLI_CommandManager $commandManager
61 public function injectCommandManager(Tx_Extbase_MVC_CLI_CommandManager
$commandManager) {
62 $this->commandManager
= $commandManager;
66 * @param Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager
68 public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface
$configurationManager) {
69 $this->configurationManager
= $configurationManager;
73 * Initializes configuration manager, object container and reflection service
75 * @param array $configuration
78 protected function initialize(array $configuration) {
79 // initialize configuration
80 $this->configurationManager
->setContentObject(t3lib_div
::makeInstance('tslib_cObj'));
81 $this->configurationManager
->setConfiguration($configuration);
83 // configure object container
84 $typoScriptSetup = $this->configurationManager
->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface
::CONFIGURATION_TYPE_FULL_TYPOSCRIPT
);
85 if (isset($typoScriptSetup['config.']['tx_extbase.']['objects.'])) {
86 $objectContainer = t3lib_div
::makeInstance('Tx_Extbase_Object_Container_Container');
87 foreach ($typoScriptSetup['config.']['tx_extbase.']['objects.'] as $classNameWithDot => $classConfiguration) {
88 if (isset($classConfiguration['className'])) {
89 $originalClassName = rtrim($classNameWithDot, '.');
90 $objectContainer->registerImplementation($originalClassName, $classConfiguration['className']);
95 // initialize reflection
96 $reflectionService = $this->objectManager
->get('Tx_Extbase_Reflection_Service');
97 $reflectionService->setDataCache($GLOBALS['typo3CacheManager']->getCache('extbase_reflection'));
98 if (!$reflectionService->isInitialized()) {
99 $reflectionService->initialize();
106 * If errors occur during Task execution they are thrown as Exceptions which
107 * must be caught manually if you manually execute Tasks through your code.
109 * @param Tx_Extbase_Scheduler_Task $task the task to execute
112 public function execute(Tx_Extbase_Scheduler_Task
$task) {
113 $commandIdentifier = $task->getCommandIdentifier();
114 list ($extensionKey, $controllerName, $commandName) = explode(':', $commandIdentifier);
115 $extensionName = t3lib_div
::underscoredToUpperCamelCase($extensionKey);
116 $this->initialize(array('extensionName' => $extensionName));
118 $request = $this->objectManager
->create('Tx_Extbase_MVC_CLI_Request');
119 $dispatcher = $this->objectManager
->get('Tx_Extbase_MVC_Dispatcher');
120 $response = $this->objectManager
->create('Tx_Extbase_MVC_CLI_Response');
123 $command = $this->commandManager
->getCommandByIdentifier($commandIdentifier);
124 $request->setControllerObjectName($command->getControllerClassName());
125 $request->setControllerCommandName($command->getControllerCommandName());
126 $request->setArguments($task->getArguments());
127 $dispatcher->dispatch($request, $response);
133 * Resets framework singletons
137 protected function shutdown() {
139 $persistenceManager = $this->objectManager
->get('Tx_Extbase_Persistence_Manager');
140 $persistenceManager->persistAll();
141 $reflectionService = $this->objectManager
->get('Tx_Extbase_Reflection_Service');
142 $reflectionService->shutdown();