TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
AbstractAction.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Install\Controller\Action;
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 
19 
23 abstract class AbstractAction implements ActionInterface
24 {
28  protected $view = null;
29 
33  protected $controller = '';
34 
38  protected $action = '';
39 
43  protected $token = '';
44 
48  protected $postValues = [];
49 
53  protected $lastError = [];
54 
58  protected $messages = [];
59 
65  public function handle()
66  {
67  $this->initializeHandle();
68  return $this->executeAction();
69  }
70 
76  protected function initializeHandle()
77  {
78  // Context service distinguishes between standalone and backend context
79  $contextService = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Service\ContextService::class);
80 
81  $viewRootPath = GeneralUtility::getFileAbsFileName('EXT:install/Resources/Private/');
82  $controllerActionDirectoryName = ucfirst($this->controller);
83  $mainTemplate = ucfirst($this->action);
84  $this->view = GeneralUtility::makeInstance(StandaloneView::class);
85  $this->view->setTemplatePathAndFilename($viewRootPath . 'Templates/Action/' . $controllerActionDirectoryName . '/' . $mainTemplate . '.html');
86  $this->view->setLayoutRootPaths([$viewRootPath . 'Layouts/']);
87  $this->view->setPartialRootPaths([$viewRootPath . 'Partials/']);
88  $this->view
89  // time is used in js and css as parameter to force loading of resources
90  ->assign('time', time())
91  ->assign('action', $this->action)
92  ->assign('controller', $this->controller)
93  ->assign('token', $this->token)
94  ->assign('context', $contextService->getContextString())
95  ->assign('contextService', $contextService)
96  ->assign('lastError', $this->lastError)
97  ->assign('messages', $this->messages)
98  ->assign('typo3Version', TYPO3_version)
99  ->assign('siteName', $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
100  }
101 
107  abstract protected function executeAction();
108 
115  public function setToken($token)
116  {
117  $this->token = $token;
118  }
119 
126  public function setController($controller)
127  {
128  $this->controller = $controller;
129  }
130 
138  public function setAction($action)
139  {
140  $this->action = $action;
141  }
142 
149  public function setPostValues(array $postValues)
150  {
151  $this->postValues = $postValues;
152  }
153 
159  public function setLastError(array $lastError)
160  {
161  $this->lastError = $lastError;
162  }
163 
169  public function setMessages(array $messages = [])
170  {
171  $this->messages = $messages;
172  }
173 
179  protected function getContext()
180  {
181  $context = 'standalone';
182  $formValues = GeneralUtility::_GP('install');
183  if (isset($formValues['context'])) {
184  $context = $formValues['context'] === 'backend' ? 'backend' : 'standalone';
185  }
186  return $context;
187  }
188 
195  protected function getDatabaseConnection()
196  {
197  static $database;
198  if (!is_object($database)) {
200  $database = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\DatabaseConnection::class);
201  $database->setDatabaseUsername($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['user']);
202  $database->setDatabasePassword($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['password']);
203  $database->setDatabaseHost($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['host']);
204  $database->setDatabasePort($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['port']);
205  $database->setDatabaseSocket($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['unix_socket']);
206  $database->setDatabaseName($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['dbname']);
207  $database->initialize();
208  $database->connectDB();
209  }
210  return $database;
211  }
212 
223  {
225  ->ensureClassLoadingInformationExists()
226  ->loadTypo3LoadedExtAndExtLocalconf(false)
227  ->defineLoggingAndExceptionConstants()
228  ->unsetReservedGlobalVariables()
229  ->initializeTypo3DbGlobal()
230  ->loadExtensionTables(false);
231  }
232 
239  protected function getHashedPassword($password)
240  {
242  return $saltFactory->getHashedPassword($password);
243  }
244 
250  protected function getExtensionCompatibilityTesterMessages()
251  {
252  $extensionCompatibilityTesterMessages = [];
253 
255  $message = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Status\LoadingStatus::class);
256  $message->setTitle('Loading...');
257  $extensionCompatibilityTesterMessages[] = $message;
258 
259  $message = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Status\ErrorStatus::class);
260  $message->setTitle('Incompatible extension found!');
261  $message->setMessage('Something went wrong and no protocol was written.');
262  $extensionCompatibilityTesterMessages[] = $message;
263 
264  $message = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Status\OkStatus::class);
265  $message->setTitle('All local extensions can be loaded!');
266  $extensionCompatibilityTesterMessages[] = $message;
267 
268  return $extensionCompatibilityTesterMessages;
269  }
270 }
static getSaltingInstance($saltedHash= '', $mode=TYPO3_MODE)
Definition: SaltFactory.php:83
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
static getFileAbsFileName($filename, $_=null, $_2=null)