[BUGFIX] Display detected fatal in extension check
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / Action / AbstractAction.php
1 <?php
2 namespace TYPO3\CMS\Install\Controller\Action;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 use TYPO3\CMS\Core\Utility\GeneralUtility;
28
29 /**
30 * General purpose controller action helper methods and bootstrap
31 */
32 abstract class AbstractAction {
33
34 /**
35 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
36 * @inject
37 */
38 protected $objectManager = NULL;
39
40 /**
41 * @var \TYPO3\CMS\Install\View\StandaloneView
42 * @inject
43 */
44 protected $view = NULL;
45
46 /**
47 * @var string Name of controller. One of the strings 'step', 'tool' or 'common'
48 */
49 protected $controller = '';
50
51 /**
52 * @var string Name of target action, set by controller
53 */
54 protected $action = '';
55
56 /**
57 * @var string Form token for CSRF protection
58 */
59 protected $token = '';
60
61 /**
62 * @var array Values in $_POST['install']
63 */
64 protected $postValues = array();
65
66 /**
67 * @var array Contains the fatal error array of the last request when passed. Schema is the one returned by error_get_last()
68 */
69 protected $lastError = array();
70
71 /**
72 * @var array<\TYPO3\CMS\Install\Status\StatusInterface> Optional status message from controller
73 */
74 protected $messages = array();
75
76 /**
77 * Initialize the handle action, sets up fluid stuff and assigns default variables.
78 *
79 * @return string content
80 */
81 protected function initializeHandle() {
82 /** @var \TYPO3\CMS\Install\Status\StatusUtility $statusUtility */
83 $statusUtility = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\StatusUtility');
84
85 // Count of failed environment checks are displayed in the left navigation menu
86 $environmentStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\SystemEnvironment\\Check')->getStatus();
87 $environmentErrors = $statusUtility->filterBySeverity($environmentStatus, 'error');
88
89 // Count of folder structure errors are displayed in left navigation menu
90 /** @var $folderStructureFacade \TYPO3\CMS\Install\FolderStructure\StructureFacade */
91 $folderStructureFacade = $this->objectManager->get('TYPO3\\CMS\\Install\\FolderStructure\\DefaultFactory')->getStructure();
92 $folderStructureErrors = $statusUtility->filterBySeverity($folderStructureFacade->getStatus(), 'error');
93
94 // Context service distinguishes between standalone and backend context
95 $contextService = $this->objectManager->get('TYPO3\\CMS\\Install\\Service\\ContextService');
96
97 $viewRootPath = GeneralUtility::getFileAbsFileName('EXT:install/Resources/Private/');
98 $controllerActionDirectoryName = ucfirst($this->controller);
99 $mainTemplate = ucfirst($this->action);
100 $this->view->setTemplatePathAndFilename($viewRootPath . 'Templates/Action/' . $controllerActionDirectoryName . '/' . $mainTemplate . '.html');
101 $this->view->setLayoutRootPath($viewRootPath . 'Layouts/');
102 $this->view->setPartialRootPath($viewRootPath . 'Partials/');
103 $this->view
104 // time is used in js and css as parameter to force loading of resources
105 ->assign('time', time())
106 ->assign('action', $this->action)
107 ->assign('controller', $this->controller)
108 ->assign('token', $this->token)
109 ->assign('context', $contextService->getContextString())
110 ->assign('contextService', $contextService)
111 ->assign('lastError', $this->lastError)
112 ->assign('messages', $this->messages)
113 ->assign('typo3Version', TYPO3_version)
114 ->assign('siteName', $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'])
115 ->assign('environmentErrors', $environmentErrors)
116 ->assign('folderStructureErrors', $folderStructureErrors);
117 }
118
119 /**
120 * Set form protection token
121 *
122 * @param string $token Form protection token
123 * @return void
124 */
125 public function setToken($token) {
126 $this->token = $token;
127 }
128
129 /**
130 * Set action group. Either string 'step', 'tool' or 'common'
131 *
132 * @param string $controller Controller name
133 * @return void
134 */
135 public function setController($controller) {
136 $this->controller = $controller;
137 }
138
139 /**
140 * Set action name. This is usually similar to the class name,
141 * only for loginForm, the action is login
142 *
143 * @param string $action Name of target action for forms
144 * @return void
145 */
146 public function setAction($action) {
147 $this->action = $action;
148 }
149
150 /**
151 * Set POST form values of install tool
152 *
153 * @param array $postValues
154 * @return void
155 */
156 public function setPostValues(array $postValues) {
157 $this->postValues = $postValues;
158 }
159
160 /**
161 * Set the last error array as returned by error_get_last()
162 *
163 * @param array $lastError
164 */
165 public function setLastError(array $lastError) {
166 $this->lastError = $lastError;
167 }
168
169 /**
170 * Status messages from controller
171 *
172 * @param array<\TYPO3\CMS\Install\Status\StatusInterface> $messages
173 */
174 public function setMessages(array $messages = array()) {
175 $this->messages = $messages;
176 }
177
178 /**
179 * Return TRUE if dbal and adodb extension is loaded
180 *
181 * @return boolean TRUE if dbal and adodb is loaded
182 */
183 protected function isDbalEnabled() {
184 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('adodb')
185 && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('dbal')
186 ) {
187 return TRUE;
188 }
189 return FALSE;
190 }
191
192 /**
193 * Context determines if the install tool is called within backend or standalone
194 *
195 * @return string Either 'standalone' or 'backend'
196 */
197 protected function getContext() {
198 $context = 'standalone';
199 $formValues = GeneralUtility::_GP('install');
200 if (isset($formValues['context'])) {
201 $context = $formValues['context'] === 'backend' ? 'backend' : 'standalone';
202 }
203 return $context;
204 }
205
206 /**
207 * Get database instance.
208 * Will be initialized if it does not exist yet.
209 *
210 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
211 */
212 protected function getDatabase() {
213 static $database;
214 if (!is_object($database)) {
215 /** @var \TYPO3\CMS\Core\Database\DatabaseConnection $database */
216 $database = $this->objectManager->get('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
217 $database->setDatabaseUsername($GLOBALS['TYPO3_CONF_VARS']['DB']['username']);
218 $database->setDatabasePassword($GLOBALS['TYPO3_CONF_VARS']['DB']['password']);
219 $database->setDatabaseHost($GLOBALS['TYPO3_CONF_VARS']['DB']['host']);
220 $database->setDatabasePort($GLOBALS['TYPO3_CONF_VARS']['DB']['port']);
221 $database->setDatabaseSocket($GLOBALS['TYPO3_CONF_VARS']['DB']['socket']);
222 $database->setDatabaseName($GLOBALS['TYPO3_CONF_VARS']['DB']['database']);
223 $database->connectDB();
224 }
225 return $database;
226 }
227
228 /**
229 * Some actions like the database analyzer and the upgrade wizards need additional
230 * bootstrap actions performed.
231 *
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.
234 *
235 * @return void
236 */
237 protected function loadExtLocalconfDatabaseAndExtTables() {
238 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()
239 ->loadTypo3LoadedExtAndExtLocalconf(FALSE)
240 ->applyAdditionalConfigurationSettings()
241 ->initializeTypo3DbGlobal()
242 ->loadExtensionTables(FALSE);
243 }
244
245 /**
246 * This function returns a salted hashed key.
247 *
248 * @param string $password
249 * @return string
250 */
251 protected function getHashedPassword($password) {
252 $saltFactory = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance(NULL, 'BE');
253 return $saltFactory->getHashedPassword($password);
254 }
255 }