TYPO3 CMS  TYPO3_8-7
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 
92  protected function initialize(array $configuration)
93  {
94  // initialize unconsumed Request and Response
95  $this->request = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Cli\Request::class);
96  $this->response = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Cli\Response::class);
97  // initialize configuration
98  $this->configurationManager->setContentObject(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class));
99  $this->configurationManager->setConfiguration($configuration);
100  // configure object container
101  $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
102  if (isset($frameworkConfiguration['objects'])) {
103  $objectContainer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class);
104  foreach ($frameworkConfiguration['objects'] as $classNameWithDot => $classConfiguration) {
105  if (isset($classConfiguration['className'])) {
106  $originalClassName = rtrim($classNameWithDot, '.');
107  $objectContainer->registerImplementation($originalClassName, $classConfiguration['className']);
108  }
109  }
110  }
111  // initialize reflection
112  $reflectionService = $this->objectManager->get(\TYPO3\CMS\Extbase\Reflection\ReflectionService::class);
113  $reflectionService->setDataCache(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('extbase_reflection'));
114  if (!$reflectionService->isInitialized()) {
115  $reflectionService->initialize();
116  }
117  }
118 
127  public function execute(\TYPO3\CMS\Extbase\Scheduler\Task $task)
128  {
129  $commandIdentifier = $task->getCommandIdentifier();
130  list($extensionKey, $controllerName, $commandName) = explode(':', $commandIdentifier);
132  $this->initialize(['extensionName' => $extensionName]);
133  // execute command
134  $command = $this->commandManager->getCommandByIdentifier($commandIdentifier);
135  $this->request->setControllerObjectName($command->getControllerClassName());
136  $this->request->setControllerCommandName($command->getControllerCommandName());
137  $this->request->setArguments($task->getArguments());
138  $this->dispatcher->dispatch($this->request, $this->response);
139  $this->shutdown();
140  }
141 
145  protected function shutdown()
146  {
147  // shutdown
148  $persistenceManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class);
149  $persistenceManager->persistAll();
150  $reflectionService = $this->objectManager->get(\TYPO3\CMS\Extbase\Reflection\ReflectionService::class);
151  $reflectionService->shutdown();
152  }
153 }
execute(\TYPO3\CMS\Extbase\Scheduler\Task $task)
injectCommandManager(\TYPO3\CMS\Extbase\Mvc\Cli\CommandManager $commandManager)
static makeInstance($className,... $constructorArguments)
injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)