2 namespace TYPO3\CMS\Install\Controller\Action
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Core\Utility\GeneralUtility
;
18 use TYPO3\CMS\Fluid\View\StandaloneView
;
21 * General purpose controller action helper methods and bootstrap
23 abstract class AbstractAction
implements ActionInterface
28 protected $view = null;
31 * @var string Name of controller. One of the strings 'step', 'tool' or 'common'
33 protected $controller = '';
36 * @var string Name of target action, set by controller
38 protected $action = '';
41 * @var string Form token for CSRF protection
43 protected $token = '';
46 * @var array Values in $_POST['install']
48 protected $postValues = array();
51 * @var array Contains the fatal error array of the last request when passed. Schema is the one returned by error_get_last()
53 protected $lastError = array();
56 * @var array<\TYPO3\CMS\Install\Status\StatusInterface> Optional status message from controller
58 protected $messages = array();
63 * @return string Rendered content
65 public function handle()
67 $this->initializeHandle();
68 return $this->executeAction();
72 * Initialize the handle action, sets up fluid stuff and assigns default variables.
76 protected function initializeHandle()
78 // Context service distinguishes between standalone and backend context
79 $contextService = GeneralUtility
::makeInstance(\TYPO3\CMS\Install\Service\ContextService
::class);
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(array($viewRootPath . 'Layouts/'));
87 $this->view
->setPartialRootPaths(array($viewRootPath . 'Partials/'));
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']);
103 * Executes the action
105 * @return string|array Rendered content
107 abstract protected function executeAction();
110 * Set form protection token
112 * @param string $token Form protection token
115 public function setToken($token)
117 $this->token
= $token;
121 * Set action group. Either string 'step', 'tool' or 'common'
123 * @param string $controller Controller name
126 public function setController($controller)
128 $this->controller
= $controller;
132 * Set action name. This is usually similar to the class name,
133 * only for loginForm, the action is login
135 * @param string $action Name of target action for forms
138 public function setAction($action)
140 $this->action
= $action;
144 * Set POST form values of install tool
146 * @param array $postValues
149 public function setPostValues(array $postValues)
151 $this->postValues
= $postValues;
155 * Set the last error array as returned by error_get_last()
157 * @param array $lastError
159 public function setLastError(array $lastError)
161 $this->lastError
= $lastError;
165 * Status messages from controller
167 * @param array<\TYPO3\CMS\Install\Status\StatusInterface> $messages
169 public function setMessages(array $messages = array())
171 $this->messages
= $messages;
175 * Return TRUE if dbal and adodb extension is loaded
177 * @return bool TRUE if dbal and adodb is loaded
179 protected function isDbalEnabled()
181 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility
::isLoaded('adodb')
182 && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility
::isLoaded('dbal')
190 * Context determines if the install tool is called within backend or standalone
192 * @return string Either 'standalone' or 'backend'
194 protected function getContext()
196 $context = 'standalone';
197 $formValues = GeneralUtility
::_GP('install');
198 if (isset($formValues['context'])) {
199 $context = $formValues['context'] === 'backend' ?
'backend' : 'standalone';
205 * Get database instance.
206 * Will be initialized if it does not exist yet.
208 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
210 protected function getDatabaseConnection()
213 if (!is_object($database)) {
214 /** @var \TYPO3\CMS\Core\Database\DatabaseConnection $database */
215 $database = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Database\DatabaseConnection
::class);
216 $database->setDatabaseUsername($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['user']);
217 $database->setDatabasePassword($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['password']);
218 $database->setDatabaseHost($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['host']);
219 $database->setDatabasePort($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['port']);
220 $database->setDatabaseSocket($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['unix_socket']);
221 $database->setDatabaseName($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['dbname']);
222 $database->initialize();
223 $database->connectDB();
229 * Some actions like the database analyzer and the upgrade wizards need additional
230 * bootstrap actions performed.
232 * Those actions can potentially fatal if some old extension is loaded that triggers
233 * a fatal in ext_localconf or ext_tables code! Use only if really needed.
237 protected function loadExtLocalconfDatabaseAndExtTables()
239 \TYPO3\CMS\Core\Core\Bootstrap
::getInstance()
240 ->ensureClassLoadingInformationExists()
241 ->loadTypo3LoadedExtAndExtLocalconf(false)
242 ->defineLoggingAndExceptionConstants()
243 ->unsetReservedGlobalVariables()
244 ->initializeTypo3DbGlobal()
245 ->loadExtensionTables(false);
249 * This function returns a salted hashed key.
251 * @param string $password
254 protected function getHashedPassword($password)
256 $saltFactory = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory
::getSaltingInstance(null, 'BE');
257 return $saltFactory->getHashedPassword($password);
261 * Prepare status messages used in extension compatibility view template
263 * @return \TYPO3\CMS\Install\Status\StatusInterface[]
265 protected function getExtensionCompatibilityTesterMessages()
267 $extensionCompatibilityTesterMessages = array();
269 /** @var $message \TYPO3\CMS\Install\Status\StatusInterface */
270 $message = GeneralUtility
::makeInstance(\TYPO3\CMS\Install\Status\LoadingStatus
::class);
271 $message->setTitle('Loading...');
272 $extensionCompatibilityTesterMessages[] = $message;
274 $message = GeneralUtility
::makeInstance(\TYPO3\CMS\Install\Status\ErrorStatus
::class);
275 $message->setTitle('Incompatible extension found!');
276 $message->setMessage('Something went wrong and no protocol was written.');
277 $extensionCompatibilityTesterMessages[] = $message;
279 $message = GeneralUtility
::makeInstance(\TYPO3\CMS\Install\Status\OkStatus
::class);
280 $message->setTitle('All local extensions can be loaded!');
281 $extensionCompatibilityTesterMessages[] = $message;
283 return $extensionCompatibilityTesterMessages;