TYPO3 CMS  TYPO3_7-6
AbstractAction.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 
18 
22 abstract class AbstractAction implements ActionInterface
23 {
27  protected $objectManager = null;
28 
34  public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager)
35  {
36  $this->objectManager = $objectManager;
37  }
38 
42  protected $view = null;
43 
49  public function injectView(\TYPO3\CMS\Install\View\FailsafeView $view)
50  {
51  $this->view = $view;
52  }
53 
57  protected $controller = '';
58 
62  protected $action = '';
63 
67  protected $token = '';
68 
72  protected $postValues = [];
73 
77  protected $lastError = [];
78 
82  protected $messages = [];
83 
89  public function handle()
90  {
91  $this->initializeHandle();
92  return $this->executeAction();
93  }
94 
100  protected function initializeHandle()
101  {
102  // Context service distinguishes between standalone and backend context
103  $contextService = $this->objectManager->get(\TYPO3\CMS\Install\Service\ContextService::class);
104 
105  $viewRootPath = GeneralUtility::getFileAbsFileName('EXT:install/Resources/Private/');
106  $controllerActionDirectoryName = ucfirst($this->controller);
107  $mainTemplate = ucfirst($this->action);
108  $this->view->setTemplatePathAndFilename($viewRootPath . 'Templates/Action/' . $controllerActionDirectoryName . '/' . $mainTemplate . '.html');
109  $this->view->setLayoutRootPath($viewRootPath . 'Layouts/');
110  $this->view->setPartialRootPath($viewRootPath . 'Partials/');
111  $this->view
112  // time is used in js and css as parameter to force loading of resources
113  ->assign('time', time())
114  ->assign('action', $this->action)
115  ->assign('controller', $this->controller)
116  ->assign('token', $this->token)
117  ->assign('context', $contextService->getContextString())
118  ->assign('contextService', $contextService)
119  ->assign('lastError', $this->lastError)
120  ->assign('messages', $this->messages)
121  ->assign('typo3Version', TYPO3_version)
122  ->assign('siteName', $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
123  }
124 
130  abstract protected function executeAction();
131 
138  public function setToken($token)
139  {
140  $this->token = $token;
141  }
142 
149  public function setController($controller)
150  {
151  $this->controller = $controller;
152  }
153 
161  public function setAction($action)
162  {
163  $this->action = $action;
164  }
165 
172  public function setPostValues(array $postValues)
173  {
174  $this->postValues = $postValues;
175  }
176 
182  public function setLastError(array $lastError)
183  {
184  $this->lastError = $lastError;
185  }
186 
192  public function setMessages(array $messages = [])
193  {
194  $this->messages = $messages;
195  }
196 
202  protected function isDbalEnabled()
203  {
204  if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('adodb')
205  && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('dbal')
206  ) {
207  return true;
208  }
209  return false;
210  }
211 
217  protected function getContext()
218  {
219  $context = 'standalone';
220  $formValues = GeneralUtility::_GP('install');
221  if (isset($formValues['context'])) {
222  $context = $formValues['context'] === 'backend' ? 'backend' : 'standalone';
223  }
224  return $context;
225  }
226 
233  protected function getDatabaseConnection()
234  {
235  static $database;
236  if (!is_object($database)) {
238  $database = $this->objectManager->get(\TYPO3\CMS\Core\Database\DatabaseConnection::class);
239  $database->setDatabaseUsername($GLOBALS['TYPO3_CONF_VARS']['DB']['username']);
240  $database->setDatabasePassword($GLOBALS['TYPO3_CONF_VARS']['DB']['password']);
241  $database->setDatabaseHost($GLOBALS['TYPO3_CONF_VARS']['DB']['host']);
242  $database->setDatabasePort($GLOBALS['TYPO3_CONF_VARS']['DB']['port']);
243  $database->setDatabaseSocket($GLOBALS['TYPO3_CONF_VARS']['DB']['socket']);
244  $database->setDatabaseName($GLOBALS['TYPO3_CONF_VARS']['DB']['database']);
245  $database->initialize();
246  $database->connectDB();
247  }
248  return $database;
249  }
250 
261  {
263  ->ensureClassLoadingInformationExists()
264  ->loadTypo3LoadedExtAndExtLocalconf(false)
265  ->defineLoggingAndExceptionConstants()
266  ->unsetReservedGlobalVariables()
267  ->initializeTypo3DbGlobal()
268  ->loadExtensionTables(false);
269  }
270 
277  protected function getHashedPassword($password)
278  {
280  return $saltFactory->getHashedPassword($password);
281  }
282 
288  protected function getExtensionCompatibilityTesterMessages()
289  {
290  $extensionCompatibilityTesterMessages = [];
291 
293  $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\LoadingStatus::class);
294  $message->setTitle('Loading...');
295  $extensionCompatibilityTesterMessages[] = $message;
296 
297  $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
298  $message->setTitle('Incompatible extension found!');
299  $message->setMessage('Something went wrong and no protocol was written.');
300  $extensionCompatibilityTesterMessages[] = $message;
301 
302  $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\OkStatus::class);
303  $message->setTitle('All local extensions can be loaded!');
304  $extensionCompatibilityTesterMessages[] = $message;
305 
306  return $extensionCompatibilityTesterMessages;
307  }
308 }
$database
Definition: server.php:40
static getSaltingInstance($saltedHash='', $mode=TYPO3_MODE)
Definition: SaltFactory.php:82
injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager)
static getFileAbsFileName($filename, $onlyRelative=true, $relToTYPO3_mainDir=false)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
injectView(\TYPO3\CMS\Install\View\FailsafeView $view)