TYPO3 CMS  TYPO3_7-6
TaskExecutor.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
24 {
28  protected $request;
29 
33  protected $response;
34 
38  protected $dispatcher;
39 
43  protected $objectManager;
44 
48  protected $commandManager;
49 
54 
58  public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
59  {
60  $this->objectManager = $objectManager;
61  }
62 
66  public function injectCommandManager(\TYPO3\CMS\Extbase\Mvc\Cli\CommandManager $commandManager)
67  {
68  $this->commandManager = $commandManager;
69  }
70 
74  public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
75  {
76  $this->configurationManager = $configurationManager;
77  }
78 
82  public function initializeObject()
83  {
84  $this->dispatcher = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Dispatcher::class);
85  }
86 
93  protected function initialize(array $configuration)
94  {
95  // initialize unconsumed Request and Response
96  $this->request = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Cli\Request::class);
97  $this->response = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Cli\Response::class);
98  // initialize configuration
99  $this->configurationManager->setContentObject(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class));
100  $this->configurationManager->setConfiguration($configuration);
101  // configure object container
102  $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
103  if (isset($frameworkConfiguration['objects'])) {
104  $objectContainer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class);
105  foreach ($frameworkConfiguration['objects'] as $classNameWithDot => $classConfiguration) {
106  if (isset($classConfiguration['className'])) {
107  $originalClassName = rtrim($classNameWithDot, '.');
108  $objectContainer->registerImplementation($originalClassName, $classConfiguration['className']);
109  }
110  }
111  }
112  // initialize reflection
113  $reflectionService = $this->objectManager->get(\TYPO3\CMS\Extbase\Reflection\ReflectionService::class);
114  $reflectionService->setDataCache(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('extbase_reflection'));
115  if (!$reflectionService->isInitialized()) {
116  $reflectionService->initialize();
117  }
118  }
119 
129  public function execute(\TYPO3\CMS\Extbase\Scheduler\Task $task)
130  {
131  $commandIdentifier = $task->getCommandIdentifier();
132  list($extensionKey, $controllerName, $commandName) = explode(':', $commandIdentifier);
134  $this->initialize(['extensionName' => $extensionName]);
135  // execute command
136  $command = $this->commandManager->getCommandByIdentifier($commandIdentifier);
137  $this->request->setControllerObjectName($command->getControllerClassName());
138  $this->request->setControllerCommandName($command->getControllerCommandName());
139  $this->request->setArguments($task->getArguments());
140  $this->dispatcher->dispatch($this->request, $this->response);
141  $this->shutdown();
142  }
143 
149  protected function shutdown()
150  {
151  // shutdown
152  $persistenceManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class);
153  $persistenceManager->persistAll();
154  $reflectionService = $this->objectManager->get(\TYPO3\CMS\Extbase\Reflection\ReflectionService::class);
155  $reflectionService->shutdown();
156  }
157 }
execute(\TYPO3\CMS\Extbase\Scheduler\Task $task)
injectCommandManager(\TYPO3\CMS\Extbase\Mvc\Cli\CommandManager $commandManager)
injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)