[BUGFIX] fix php fatal error of Upgrade wizard
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / Base.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Benjamin Mack <benni@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28
29 /**
30 * Generic class that every update wizard class inherits from.
31 * Used by the update wizard in the install tool.
32 *
33 * @author Benjamin Mack <benni@typo3.org>
34 */
35 abstract class Tx_Install_Updates_Base {
36
37 /**
38 * the human-readable title of the upgrade wizard
39 */
40 protected $title;
41
42 /**
43 * parent object
44 * @var tx_install
45 */
46 public $pObj;
47
48 /**
49 * user input, set from outside
50 */
51 public $userInput;
52
53 /**
54 * current TYPO3 version number, set from outside
55 * version number coming from t3lib_div::int_from_ver()
56 */
57 public $versionNumber;
58
59
60
61 /**
62 *
63 * API functions
64 *
65 **/
66
67 /**
68 * The first function in the update wizard steps
69 *
70 * it works like this:
71 * @param $explanation string HTML that is outputted on the first
72 * @param $showUpdate int that informs you whether to show this update wizard or not. Possible values that checkForUpdate() should set:
73 * 0 = don't show this update wizard at all (because it's not needed)
74 * 1 = show the update wizard (explanation + next step button)
75 * 2 = show the update wizard (explanation but not the "next step" button), useful for showing a status of a wizard
76 * @return deprecated since TYPO3 4.5, in previous versions it was used to determine whether the update wizards should be shown, now, the $showUpdate parameter is used for that
77 */
78 // public abstract function checkForUpdate(&$explanation, &$showUpdate);
79
80
81 /**
82 * second step: get user input if needed
83 *
84 * @param string input prefix, all names of form fields have to start with this. Append custom name in [ ... ]
85 * @return string HTML output
86 */
87 // public abstract function getUserInput($inputPrefix);
88
89
90 /**
91 * third step: do the updates
92 *
93 * @param array &$dbQueries: queries done in this update
94 * @param mixed &$customMessages: custom messages
95 * @return boolean whether it worked (true) or not (false)
96 */
97 // public abstract function performUpdate(&$dbQueries, &$customMessages);
98
99 /**
100 * Checks if user input is valid
101 *
102 * @param string pointer to output custom messages
103 * @return boolean true if user input is correct, then the update is performed. When false, return to getUserInput
104 */
105 // public abstract function checkUserInput(&$customMessages);
106
107
108
109
110
111 /**
112 *
113 * Helper functions, getters and setters
114 *
115 **/
116
117 /**
118 * returns the title attribute
119 *
120 * @return the title of this update wizard
121 **/
122 public function getTitle() {
123 if ($this->title) {
124 return $this->title;
125 } else {
126 return $this->identifier;
127 }
128 }
129
130 /**
131 * sets the title attribute
132 *
133 * @param $title the title of this update wizard
134 * @return void
135 **/
136 public function setTitle($title) {
137 $this->title = $title;
138 }
139
140
141 /**
142 * returns the identifier of this class
143 *
144 * @return the identifier of this update wizard
145 **/
146 public function getIdentifier() {
147 return $this->identifier;
148 }
149
150 /**
151 * sets the identifier attribute
152 *
153 * @param $identifier the identifier of this update wizard
154 * @return void
155 **/
156 public function setIdentifier($identifier) {
157 $this->identifier = $identifier;
158 }
159
160 /**
161 * simple wrapper function that helps dealing with the compatibility
162 * layer that some update wizards don't have a second parameter
163 * thus, it evaluates everything already
164 *
165 * @return boolean if the wizard should be shown at all on the overview page
166 * @see checkForUpdate()
167 */
168 public function shouldRenderWizard() {
169 $showUpdate = 0;
170 $explanation = '';
171 $res = $this->checkForUpdate($explanation, $showUpdate);
172 return ($showUpdate > 0 || $res == TRUE);
173 }
174
175 /**
176 * simple wrapper function that helps to check whether (if)
177 * this feature is cool if you want to tell the user that the update wizard
178 * is working fine, just as output (useful for the character set / utf8 wizard)
179 *
180 * @return boolean if the wizard should render the Next() button on the overview page
181 * @see checkForUpdate()
182 */
183 public function shouldRenderNextButton() {
184 $showUpdate = 0;
185 $explanation = '';
186 $res = $this->checkForUpdate($explanation, $showUpdate);
187 return ($showUpdate != 2 || $res == TRUE);
188 }
189
190 /**
191 * This method creates an instance of a connection to the Extension Manager
192 * and returns it. This is used when installing an extension.
193 *
194 * @return tx_em_Connection_ExtDirectServer EM connection instance
195 */
196 public function getExtensionManagerConnection() {
197 // Create an instance of language, if necessary.
198 // Needed in order to make the em_index work
199 if (!is_object($GLOBALS['LANG'])) {
200 $GLOBALS['LANG'] = t3lib_div::makeInstance('language');
201 $GLOBALS['LANG']->csConvObj = t3lib_div::makeInstance('t3lib_cs');
202 }
203 // Create an instance of a connection class to the EM
204 $extensionManagerConnection = t3lib_div::makeInstance('tx_em_Connection_ExtDirectServer', FALSE);
205 return $extensionManagerConnection;
206 }
207
208 /**
209 * This method can be called to install extensions following all proper processes
210 * (e.g. installing in both extList and extList_FE, respecting priority, etc.)
211 *
212 * @param array $extensionKeys List of keys of extensions to install
213 * @return void
214 */
215 protected function installExtensions($extensionKeys) {
216 $extensionManagerConnection = $this->getExtensionManagerConnection();
217 foreach ($extensionKeys as $extension) {
218 $extensionManagerConnection->enableExtension($extension);
219 }
220 }
221
222 /**
223 * Marks some wizard as being "seen" so that it not shown again.
224 *
225 * Writes the info in localconf.php
226 *
227 * @return void
228 */
229 protected function markWizardAsDone() {
230 /** @var t3lib_install $install */
231 $install = t3lib_div::makeInstance('t3lib_install');
232 $install->allowUpdateLocalConf = 1;
233 $install->updateIdentity = 'TYPO3 Upgrade Wizard';
234 // Get lines from localconf file
235 $lines = $install->writeToLocalconf_control();
236 $wizardClassName = get_class($this);
237 $install->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'INSTALL\'][\'wizardDone\'][\'' . $wizardClassName . '\']', 1);
238 $install->writeToLocalconf_control($lines);
239 }
240
241 /**
242 * Checks if this wizard has been "done" before
243 *
244 * @return boolean TRUE if wizard has been done before, FALSE otherwise
245 */
246 protected function isWizardDone() {
247 $wizardClassName = get_class($this);
248 $done = FALSE;
249 if (isset($GLOBALS['TYPO3_CONF_VARS']['INSTALL']['wizardDone'][$wizardClassName]) &&
250 $GLOBALS['TYPO3_CONF_VARS']['INSTALL']['wizardDone'][$wizardClassName]) {
251 $done = TRUE;
252 }
253 return $done;
254 }
255 }
256 ?>