!!! Fixed bug #15171: Add an Update Wizard to install the new sysexts
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / updates / class.tx_coreupdates_installsysexts.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008-2010 Benjamin Mack <benni@typo3.org>
6 * (c) 2008-2010 Steffen Kamper <info@sk-typo3.de>
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
19 *
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28
29 /**
30 * Contains the update class for adding the system extension "simulate static".
31 *
32 * $Id$
33 *
34 * @author Benjamin Mack <benni@typo3.org>
35 * @author Steffen Kamper <info@sk-typo3.de>
36 */
37 class tx_coreupdates_installsysexts {
38 public $versionNumber; // version number coming from t3lib_div::int_from_ver()
39 protected $newSystemExtensions = array('info', 'perm', 'func', 'filelist', 'about', 'cshmanual', 'feedit', 'opendocs', 'simulatestatic');
40
41 /**
42 * parent object
43 *
44 * @var tx_install
45 */
46 public $pObj;
47 public $userInput; // user input
48
49
50 /**
51 * Checks if an update is needed
52 *
53 * @param string &$description: The description for the update
54 * @return boolean whether an update is needed (true) or not (false)
55 */
56 public function checkForUpdate(&$description) {
57 $result = false;
58 $description = '
59 <p>
60 Install the following system extensions as their functionality
61 is moved out of the TYPO3 base installation and now optional:
62 </p>
63 <ul>
64 <li>
65 <strong>Web&gt;Info [info]</strong>
66 <br />
67 Shows page related information, eg. hit statistics, change log, record counts.
68 </li>
69 <li>
70 <strong>Web&gt;Access [perm]</strong>
71 <br />
72 Sets page editing permissions.
73 </li>
74 <li>
75 <strong>Web&gt;Functions [func]</strong>
76 <br />
77 Advanced functions like wizards for page sorting and batch creating.
78 </li>
79 <li>
80 <strong>File&gt;Filelist [filelist]</strong>
81 <br />
82 Listing of files in the directory.
83 </li>
84 <li>
85 <strong>Help&gt;About [about]</strong>
86 <br />
87 Shows info about TYPO3 and installed extensions.
88 </li>
89 <li>
90 <strong>Help&gt;TYPO3 Manual [cshmanual]</strong>
91 <br />
92 Shows TYPO3 inline user manual.
93 </li>
94 <li>
95 <strong>Frontend Editing [feedit]</strong>
96 <br />
97 This module enables FE-editing, configuration is done by
98 Typoscript.
99 </li>
100 <li>
101 <strong>User&gt;Open Documents [opendocs]</strong>
102 <br />
103 Handles the list of opened documents in TYPO3 backend.
104 </li>
105 <li>
106 <strong>Simulate Static URLs [simulatestatic]</strong>
107 <br />
108 If you do not want to use RealURL or CoolURI but still want
109 the Speaking URL feature. If you used
110 "config.simulateStaticDocuments = 1" in this installation
111 before, you should install this system extension. Be sure to
112 read the manual of "simulatestatic".
113 </li>
114 </ul>
115 ';
116
117 foreach($this->newSystemExtensions as $ext) {
118 if (!t3lib_extMgm::isLoaded($ext)) {
119 $result = true;
120 }
121 }
122 return $result;
123 }
124
125 /**
126 * second step: get user input for installing sysextensions
127 *
128 * @param string input prefix, all names of form fields have to start with this. Append custom name in [ ... ]
129 * @return string HTML output
130 */
131 public function getUserInput($inputPrefix) {
132 $content = '
133 <p>
134 <strong>
135 Install the following SystemExtensions
136 </strong>:
137 </p>
138 <fieldset>
139 <ol>
140 <li class="labelAfter">
141 <input type="checkbox" id="info" name="' . $inputPrefix . '[sysext][info]" value="1" checked="checked" />
142 <label for="info">Web&gt;Info [info]</label>
143 </li>
144 <li class="labelAfter">
145 <input type="checkbox" id="perm" name="' . $inputPrefix . '[sysext][perm]" value="1" checked="checked" />
146 <label for="perm">Web&gt;Access [perm]</label>
147 </li>
148 <li class="labelAfter">
149 <input type="checkbox" id="func" name="' . $inputPrefix . '[sysext][func]" value="1" checked="checked" />
150 <label for="func">Web&gt;Functions [func]</label>
151 </li>
152 <li class="labelAfter">
153 <input type="checkbox" id="filelist" name="' . $inputPrefix . '[sysext][filelist]" value="1" checked="checked" />
154 <label for="filelist">File&gt;Filelist [filelist]</label>
155 </li>
156 <li class="labelAfter">
157 <input type="checkbox" id="about" name="' . $inputPrefix . '[sysext][about]" value="1" checked="checked" />
158 <label for="about">Help&gt;About [about]</label>
159 </li>
160 <li class="labelAfter">
161 <input type="checkbox" id="cshmanual" name="' . $inputPrefix . '[sysext][cshmanual]" value="1" checked="checked" />
162 <label for="cshmanual">Help&gt;TYPO3 Manual [cshmanual]</label>
163 </li>
164 <li class="labelAfter">
165 <input type="checkbox" id="feedit" name="' . $inputPrefix . '[sysext][feedit]" value="1" checked="checked" />
166 <label for="feedit">Frontend Editing [feedit]</label>
167 </li>
168 <li class="labelAfter">
169 <input type="checkbox" id="opendocs" name="' . $inputPrefix . '[sysext][opendocs]" value="1" checked="checked" />
170 <label for="opendocs">User&gt;Open Documents [opendocs]</label>
171 </li>
172 <li class="labelAfter">
173 <input type="checkbox" id="simulatestatic" name="' . $inputPrefix . '[sysext][simulatestatic]" value="1" checked="checked" />
174 <label for="simulatestatic">Simulate Static URLs [simulatestatic]</label>
175 </li>
176 </ol>
177 </fieldset>
178 ';
179
180 return $content;
181 }
182
183 /**
184 * Adds the extensions "about", "cshmanual" and "simulatestatic" to the extList in TYPO3_CONF_VARS
185 *
186 * @param array &$dbQueries: queries done in this update
187 * @param mixed &$customMessages: custom messages
188 * @return boolean whether it worked (true) or not (false)
189 */
190 public function performUpdate(&$dbQueries, &$customMessages) {
191 $result = false;
192
193 // Get extension keys that were submitted by the used to be installed and that are valid for this update wizard:
194 if (is_array($this->pObj->INSTALL['update']['installSystemExtensions']['sysext'])) {
195 $extArray = array_intersect(
196 $this->newSystemExtensions,
197 array_keys($this->pObj->INSTALL['update']['installSystemExtensions']['sysext'])
198 );
199 t3lib_div::debug(array_keys($this->pObj->INSTALL['update']['installSystemExtensions']['sysext']));
200 t3lib_div::debug($extArray);
201 $extList = $this->addExtToList($extArray);
202 if ($extList) {
203 $this->writeNewExtensionList($extList);
204 $result = true;
205 }
206 }
207
208 return $result;
209 }
210
211
212 /**
213 * Adds extension to extension list and returns new list. If -1 is returned, an error happend.
214 * Does NOT check dependencies yet.
215 *
216 * @param array Extension keys to add
217 * @return string New list of installed extensions or -1 if error
218 */
219 function addExtToList(array $extKeys) {
220 // Get list of installed extensions and add this one.
221 $tmpLoadedExt = $GLOBALS['TYPO3_LOADED_EXT'];
222 if (isset($tmpLoadedExt['_CACHEFILE'])) {
223 unset($tmpLoadedExt['_CACHEFILE']);
224 }
225
226 $listArr = array_keys($tmpLoadedExt);
227 $listArr = array_merge($listArr, $extKeys);
228
229 // Implode unique list of extensions to load and return:
230 return implode(',', array_unique($listArr));
231 }
232
233
234 /**
235 * Writes the extension list to "localconf.php" file
236 * Removes the temp_CACHED* files before return.
237 *
238 * @param string List of extensions
239 * @return void
240 */
241 protected function writeNewExtensionList($newExtList) {
242 // Instance of install tool
243 $instObj = new t3lib_install;
244 $instObj->allowUpdateLocalConf = 1;
245 $instObj->updateIdentity = 'TYPO3 Core Update Manager';
246
247 // Get lines from localconf file
248 $lines = $instObj->writeToLocalconf_control();
249 $instObj->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'EXT\'][\'extList\']', $newExtList);
250 $instObj->writeToLocalconf_control($lines);
251
252 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'] = $newExtList;
253 t3lib_extMgm::removeCacheFiles();
254 }
255 }
256 ?>