[!!!][TASK] Rewrite install tool
[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 this action
73 *
74 * @return string content
75 */
76 protected function initialize() {
77 $viewRootPath = GeneralUtility::getFileAbsFileName('EXT:install/Resources/Private/');
78 $controllerActionDirectoryName = ucfirst($this->controller);
79 $mainTemplate = ucfirst($this->action);
80 $this->view->setTemplatePathAndFilename($viewRootPath . 'Templates/Action/' . $controllerActionDirectoryName . '/' . $mainTemplate . '.html');
81 $this->view->setLayoutRootPath($viewRootPath . 'Layouts/');
82 $this->view->setPartialRootPath($viewRootPath . 'Partials/');
83 $this->view
84 // time is used in js and css as parameter to force loading of resources
85 ->assign('time', time())
86 ->assign('action', $this->action)
87 ->assign('controller', $this->controller)
88 ->assign('token', $this->token)
89 ->assign('context', $this->getContext())
90 ->assign('messages', $this->messages)
91 ->assign('typo3Version', TYPO3_version)
92 ->assign('siteName', $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
93 }
94
95 /**
96 * Set form protection token
97 *
98 * @param string $token Form protection token
99 * @return void
100 */
101 public function setToken($token) {
102 $this->token = $token;
103 }
104
105 /**
106 * Set action group. Either string 'step', 'tool' or 'common'
107 *
108 * @param string $controller Controller name
109 * @return void
110 */
111 public function setController($controller) {
112 $this->controller = $controller;
113 }
114
115 /**
116 * Set action name. This is usually similar to the class name,
117 * only for loginForm, the action is login
118 *
119 * @param string $action Name of target action for forms
120 * @return void
121 */
122 public function setAction($action) {
123 $this->action = $action;
124 }
125
126 /**
127 * Set POST form values of install tool
128 *
129 * @param array $postValues
130 * @return void
131 */
132 public function setPostValues(array $postValues) {
133 $this->postValues = $postValues;
134 }
135
136 /**
137 * Status messages from controller
138 *
139 * @param array<\TYPO3\CMS\Install\Status\StatusInterface> $messages
140 */
141 public function setMessages(array $messages = array()) {
142 $this->messages = $messages;
143 }
144
145 /**
146 * Return TRUE if dbal and adodb extension is loaded
147 *
148 * @return boolean TRUE if dbal and adodb is loaded
149 */
150 protected function isDbalEnabled() {
151 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('adodb')
152 && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('dbal')
153 ) {
154 return TRUE;
155 }
156 return FALSE;
157 }
158
159 /**
160 * Context determines if the install tool is called within backend or standalone
161 *
162 * @return string Either 'standalone' or 'backend'
163 */
164 protected function getContext() {
165 $context = 'standalone';
166 $formValues = GeneralUtility::_GP('install');
167 if (isset($formValues['context'])) {
168 $context = $formValues['context'] === 'backend' ? 'backend' : 'standalone';
169 }
170 return $context;
171 }
172
173 /**
174 * Get database instance.
175 * Will be initialized if it does not exist yet.
176 *
177 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
178 */
179 protected function getDatabase() {
180 static $database;
181 if (!is_object($database)) {
182 /** @var \TYPO3\CMS\Core\Database\DatabaseConnection $database */
183 $database = $this->objectManager->get('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
184 $database->setDatabaseUsername($GLOBALS['TYPO3_CONF_VARS']['DB']['username']);
185 $database->setDatabasePassword($GLOBALS['TYPO3_CONF_VARS']['DB']['password']);
186 $database->setDatabaseHost($GLOBALS['TYPO3_CONF_VARS']['DB']['host']);
187 $database->setDatabasePort($GLOBALS['TYPO3_CONF_VARS']['DB']['port']);
188 $database->setDatabaseName($GLOBALS['TYPO3_CONF_VARS']['DB']['database']);
189 $database->connectDB();
190 }
191 return $database;
192 }
193
194 /**
195 * Some actions like the database analyzer and the upgrade wizards need additional
196 * bootstrap actions performed.
197 *
198 * Those actions can potentially fatal if some old extension is loaded that triggers
199 * a fatal in ext_localconf or ext_tables code! Use only if really needed.
200 *
201 * @return void
202 */
203 protected function loadExtLocalconfDatabaseAndExtTables() {
204 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()
205 ->loadTypo3LoadedExtAndExtLocalconf(FALSE)
206 ->applyAdditionalConfigurationSettings()
207 ->initializeTypo3DbGlobal()
208 ->loadExtensionTables(FALSE);
209 }
210 }
211 ?>