[FEATURE] ext:install Show number of folder structure errors in menu
[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<\TYPO3\CMS\Install\Status\StatusInterface> Optional status message from controller
68 */
69 protected $messages = array();
70
71 /**
72 * Initialize the handle action, sets up fluid stuff and assigns default variables.
73 *
74 * @return string content
75 */
76 protected function initializeHandle() {
77 $statusUtility = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\StatusUtility');
78
79 // Count of failed environment checks are displayed in the left navigation menu
80 $environmentStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\SystemEnvironment\\Check')->getStatus();
81 $environmentErrors = $statusUtility->filterBySeverity($environmentStatus, 'error');
82
83 // Count of folder structure errors are displayed in left navigation menu
84 /** @var $folderStructureFacade \TYPO3\CMS\Install\FolderStructure\StructureFacade */
85 $folderStructureFacade = $this->objectManager->get('TYPO3\\CMS\\Install\\FolderStructure\\DefaultFactory')->getStructure();
86 $folderStructureErrors = $statusUtility->filterBySeverity($folderStructureFacade->getStatus(), 'error');
87
88 // Context service distinguishes between standalone and backend context
89 $contextService = $this->objectManager->get('TYPO3\\CMS\\Install\\Service\\ContextService');
90
91 $viewRootPath = GeneralUtility::getFileAbsFileName('EXT:install/Resources/Private/');
92 $controllerActionDirectoryName = ucfirst($this->controller);
93 $mainTemplate = ucfirst($this->action);
94 $this->view->setTemplatePathAndFilename($viewRootPath . 'Templates/Action/' . $controllerActionDirectoryName . '/' . $mainTemplate . '.html');
95 $this->view->setLayoutRootPath($viewRootPath . 'Layouts/');
96 $this->view->setPartialRootPath($viewRootPath . 'Partials/');
97 $this->view
98 // time is used in js and css as parameter to force loading of resources
99 ->assign('time', time())
100 ->assign('action', $this->action)
101 ->assign('controller', $this->controller)
102 ->assign('token', $this->token)
103 ->assign('context', $contextService->getContextString())
104 ->assign('contextService', $contextService)
105 ->assign('messages', $this->messages)
106 ->assign('typo3Version', TYPO3_version)
107 ->assign('siteName', $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'])
108 ->assign('environmentErrors', $environmentErrors)
109 ->assign('folderStructureErrors', $folderStructureErrors);
110 }
111
112 /**
113 * Set form protection token
114 *
115 * @param string $token Form protection token
116 * @return void
117 */
118 public function setToken($token) {
119 $this->token = $token;
120 }
121
122 /**
123 * Set action group. Either string 'step', 'tool' or 'common'
124 *
125 * @param string $controller Controller name
126 * @return void
127 */
128 public function setController($controller) {
129 $this->controller = $controller;
130 }
131
132 /**
133 * Set action name. This is usually similar to the class name,
134 * only for loginForm, the action is login
135 *
136 * @param string $action Name of target action for forms
137 * @return void
138 */
139 public function setAction($action) {
140 $this->action = $action;
141 }
142
143 /**
144 * Set POST form values of install tool
145 *
146 * @param array $postValues
147 * @return void
148 */
149 public function setPostValues(array $postValues) {
150 $this->postValues = $postValues;
151 }
152
153 /**
154 * Status messages from controller
155 *
156 * @param array<\TYPO3\CMS\Install\Status\StatusInterface> $messages
157 */
158 public function setMessages(array $messages = array()) {
159 $this->messages = $messages;
160 }
161
162 /**
163 * Return TRUE if dbal and adodb extension is loaded
164 *
165 * @return boolean TRUE if dbal and adodb is loaded
166 */
167 protected function isDbalEnabled() {
168 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('adodb')
169 && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('dbal')
170 ) {
171 return TRUE;
172 }
173 return FALSE;
174 }
175
176 /**
177 * Context determines if the install tool is called within backend or standalone
178 *
179 * @return string Either 'standalone' or 'backend'
180 */
181 protected function getContext() {
182 $context = 'standalone';
183 $formValues = GeneralUtility::_GP('install');
184 if (isset($formValues['context'])) {
185 $context = $formValues['context'] === 'backend' ? 'backend' : 'standalone';
186 }
187 return $context;
188 }
189
190 /**
191 * Get database instance.
192 * Will be initialized if it does not exist yet.
193 *
194 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
195 */
196 protected function getDatabase() {
197 static $database;
198 if (!is_object($database)) {
199 /** @var \TYPO3\CMS\Core\Database\DatabaseConnection $database */
200 $database = $this->objectManager->get('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
201 $database->setDatabaseUsername($GLOBALS['TYPO3_CONF_VARS']['DB']['username']);
202 $database->setDatabasePassword($GLOBALS['TYPO3_CONF_VARS']['DB']['password']);
203 $database->setDatabaseHost($GLOBALS['TYPO3_CONF_VARS']['DB']['host']);
204 $database->setDatabasePort($GLOBALS['TYPO3_CONF_VARS']['DB']['port']);
205 $database->setDatabaseSocket($GLOBALS['TYPO3_CONF_VARS']['DB']['socket']);
206 $database->setDatabaseName($GLOBALS['TYPO3_CONF_VARS']['DB']['database']);
207 $database->connectDB();
208 }
209 return $database;
210 }
211
212 /**
213 * Some actions like the database analyzer and the upgrade wizards need additional
214 * bootstrap actions performed.
215 *
216 * Those actions can potentially fatal if some old extension is loaded that triggers
217 * a fatal in ext_localconf or ext_tables code! Use only if really needed.
218 *
219 * @return void
220 */
221 protected function loadExtLocalconfDatabaseAndExtTables() {
222 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()
223 ->loadTypo3LoadedExtAndExtLocalconf(FALSE)
224 ->applyAdditionalConfigurationSettings()
225 ->initializeTypo3DbGlobal()
226 ->loadExtensionTables(FALSE);
227 }
228
229 /**
230 * This function returns a salted hashed key.
231 *
232 * @param string $password
233 * @return string
234 */
235 protected function getHashedPassword($password) {
236 $saltFactory = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance(NULL, 'BE');
237 return $saltFactory->getHashedPassword($password);
238 }
239 }
240 ?>