[BUGFIX] ENABLE_INSTALL_TOOL does not respect fileCreateMask
[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_utility_VersionNumber::convertVersionNumberToInteger()
56 */
57 public $versionNumber;
58
59
60
61 /**
62 *
63 * API functions
64 *
65 **/
66
67 /**
68 * second step: get user input if needed
69 *
70 * @param string input prefix, all names of form fields have to start with this. Append custom name in [ ... ]
71 * @return string HTML output
72 */
73 // public abstract function getUserInput($inputPrefix);
74
75
76 /**
77 * third step: do the updates
78 *
79 * @param array &$dbQueries: queries done in this update
80 * @param mixed &$customMessages: custom messages
81 * @return boolean whether it worked (TRUE) or not (FALSE)
82 */
83 // public abstract function performUpdate(&$dbQueries, &$customMessages);
84
85 /**
86 * Checks if user input is valid
87 *
88 * @param string pointer to output custom messages
89 * @return boolean TRUE if user input is correct, then the update is performed. When FALSE, return to getUserInput
90 */
91 // public abstract function checkUserInput(&$customMessages);
92
93
94
95
96
97 /**
98 *
99 * Helper functions, getters and setters
100 *
101 **/
102
103 /**
104 * returns the title attribute
105 *
106 * @return the title of this update wizard
107 **/
108 public function getTitle() {
109 if ($this->title) {
110 return $this->title;
111 } else {
112 return $this->identifier;
113 }
114 }
115
116 /**
117 * sets the title attribute
118 *
119 * @param $title the title of this update wizard
120 * @return void
121 **/
122 public function setTitle($title) {
123 $this->title = $title;
124 }
125
126
127 /**
128 * returns the identifier of this class
129 *
130 * @return the identifier of this update wizard
131 **/
132 public function getIdentifier() {
133 return $this->identifier;
134 }
135
136 /**
137 * sets the identifier attribute
138 *
139 * @param $identifier the identifier of this update wizard
140 * @return void
141 **/
142 public function setIdentifier($identifier) {
143 $this->identifier = $identifier;
144 }
145
146 /**
147 * simple wrapper function that helps dealing with the compatibility
148 * layer that some update wizards don't have a second parameter
149 * thus, it evaluates everything already
150 *
151 * @return boolean if the wizard should be shown at all on the overview page
152 * @see checkForUpdate()
153 */
154 public function shouldRenderWizard() {
155 $showUpdate = 0;
156 $explanation = '';
157 $res = $this->checkForUpdate($explanation, $showUpdate);
158 return ($showUpdate > 0 || $res == TRUE);
159 }
160
161 /**
162 * simple wrapper function that helps to check whether (if)
163 * this feature is cool if you want to tell the user that the update wizard
164 * is working fine, just as output (useful for the character set / utf8 wizard)
165 *
166 * @return boolean if the wizard should render the Next() button on the overview page
167 * @see checkForUpdate()
168 */
169 public function shouldRenderNextButton() {
170 $showUpdate = 0;
171 $explanation = '';
172 $res = $this->checkForUpdate($explanation, $showUpdate);
173 return ($showUpdate != 2 || $res == TRUE);
174 }
175
176 /**
177 * This method creates an instance of a connection to the Extension Manager
178 * and returns it. This is used when installing an extension.
179 *
180 * @return tx_em_Connection_ExtDirectServer EM connection instance
181 */
182 public function getExtensionManagerConnection() {
183 // Create an instance of language, if necessary.
184 // Needed in order to make the em_index work
185 if (!is_object($GLOBALS['LANG'])) {
186 $GLOBALS['LANG'] = t3lib_div::makeInstance('language');
187 $GLOBALS['LANG']->csConvObj = t3lib_div::makeInstance('t3lib_cs');
188 }
189 // Create an instance of a connection class to the EM
190 $extensionManagerConnection = t3lib_div::makeInstance('tx_em_Connection_ExtDirectServer', FALSE);
191 return $extensionManagerConnection;
192 }
193
194 /**
195 * This method can be called to install extensions following all proper processes
196 * (e.g. installing in both extList and extList_FE, respecting priority, etc.)
197 *
198 * @param array $extensionKeys List of keys of extensions to install
199 * @return void
200 */
201 protected function installExtensions($extensionKeys) {
202 $extensionManagerConnection = $this->getExtensionManagerConnection();
203 foreach ($extensionKeys as $extension) {
204 $extensionManagerConnection->enableExtension($extension);
205 }
206 }
207
208 /**
209 * Marks some wizard as being "seen" so that it not shown again.
210 *
211 * Writes the info in localconf.php
212 *
213 * @return void
214 */
215 protected function markWizardAsDone() {
216 /** @var t3lib_install $install */
217 $install = t3lib_div::makeInstance('t3lib_install');
218 $install->allowUpdateLocalConf = 1;
219 $install->updateIdentity = 'TYPO3 Upgrade Wizard';
220 // Get lines from localconf file
221 $lines = $install->writeToLocalconf_control();
222 $wizardClassName = get_class($this);
223 $install->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'INSTALL\'][\'wizardDone\'][\'' . $wizardClassName . '\']', 1);
224 $install->writeToLocalconf_control($lines);
225 }
226
227 /**
228 * Checks if this wizard has been "done" before
229 *
230 * @return boolean TRUE if wizard has been done before, FALSE otherwise
231 */
232 protected function isWizardDone() {
233 $wizardClassName = get_class($this);
234 $done = FALSE;
235 if (isset($GLOBALS['TYPO3_CONF_VARS']['INSTALL']['wizardDone'][$wizardClassName]) &&
236 $GLOBALS['TYPO3_CONF_VARS']['INSTALL']['wizardDone'][$wizardClassName]) {
237 $done = TRUE;
238 }
239 return $done;
240 }
241 }
242 ?>