Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / updates / class.tx_coreupdates_compatversion.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Sebastian Kurfürst <sebastian@garbage-group.de>
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 * Contains the update class for the compatibility version. Used by the update wizard in the install tool.
30 *
31 * @author Sebastian Kurfürst <sebastian@garbage-group.de
32 * @version $Id$
33 */
34 class tx_coreupdates_compatversion extends Tx_Install_Updates_Base {
35 protected $title = 'Version Compatibility';
36
37 /**
38 * Function which checks if update is needed. Called in the beginning of an update process.
39 *
40 * @param string pointer to description for the update
41 * @return boolean true if update is needs to be performed, false otherwise.
42 */
43 function checkForUpdate(&$description) {
44 global $TYPO3_CONF_VARS;
45
46 if ($this->compatVersionIsCurrent()) {
47 $description = '
48 <p>
49 <strong>Up to date!</strong>
50 <br />
51 If you do not use the wizard, your current TYPO3
52 installation is configured to use all the features included
53 in the current release ' . TYPO3_version . '.
54 <br />
55 There are two possibilities that you see this screen:
56 </p>
57 <ol>
58 <li>
59 <strong>You just updated from a previous version of
60 TYPO3:</strong>
61 Because of some new features, the frontend output of
62 your site might have changed. To emulate the "old"
63 frontend behavior, change the compatibility version
64 by continuing to step 2.
65 This is <strong>recommended</strong> after every update
66 to make sure the frontend output is not altered. When
67 re-running the wizard, you will see the changes needed
68 for using the new features.
69 <em>Please continue to step two.</em>
70 </li>
71 <li>
72 <strong>You just made a fresh install of TYPO3:</strong>
73 Perfect! All new features will be used.
74 <em>You can stop here and do not need this wizard now.</em>
75 </li>
76 </ol>
77 ';
78
79 if (!$TYPO3_CONF_VARS['SYS']['compat_version']) {
80 $description .= '
81 <p>
82 The compatibility version has been set to the current
83 TYPO3 version. This is a stamp and has no impact for
84 your installation.
85 </p>
86 ';
87 }
88 } else {
89 $description = '
90 <p>
91 Your current TYPO3 installation is configured to
92 <strong>behave like version
93 ' . htmlspecialchars($TYPO3_CONF_VARS['SYS']['compat_version']) . '
94 </strong> of TYPO3. If you just upgraded from this version,
95 you most likely want to <strong>use new features</strong> as
96 well.
97 </p>
98 <p>
99 In the next step, you will see the things that need to be
100 adjusted to make your installation compatible with the new
101 features.
102 </p>
103 ';
104 }
105
106 return 1; // Return 1 in any case so user has possibility to switch back to a previous compat_version.
107 }
108
109 /**
110 * second step: get user input if needed
111 *
112 * @param string input prefix, all names of form fields have to start with this. Append custom name in [ ... ]
113 * @return string HTML output
114 */
115 function getUserInput($inputPrefix) {
116 global $TYPO3_CONF_VARS;
117 if ($this->compatVersionIsCurrent()) {
118 $content = '
119 <fieldset>
120 <ol>
121 <li>
122 <strong>You updated from an older version of TYPO3</strong>:
123 </li>
124 <li>
125 <label for="version">Select the version where you have upgraded from:</label>
126 <select name="' . $inputPrefix . '[version]" id="version">
127 ';
128 $versions = array(
129 '3.8' => '<= 3.8',
130 '4.1' => '<= 4.1',
131 '4.2' => '<= 4.2',
132 '4.3' => '<= 4.3',
133 '4.4' => '<= 4.4'
134 );
135 foreach ($versions as $singleVersion => $caption) {
136 $content .= '
137 <option value="'.$singleVersion.'">'.$caption.'</option>
138 ';
139 }
140 $content .= '
141 </select>
142 </li>
143 </ol>
144 </fieldset>
145 ';
146 } else {
147 $content = '
148 <p>
149 TYPO3 output is currently compatible to version ' . htmlspecialchars($TYPO3_CONF_VARS['SYS']['compat_version']) . '.
150 To use all the new features in the current TYPO3 version,
151 make sure you follow the guidelines below to upgrade without
152 problems.
153 </p>
154 <p>
155 <strong>
156 Follow the steps below carefully and confirm every step!
157 </strong>
158 <br />
159 You will see this list again after you performed the update.
160 </p>
161 ';
162
163 $content .= $this->showChangesNeeded($inputPrefix);
164
165 $content.= '
166 <fieldset>
167 <ol>
168 <li class="labelAfter">
169 <input type="checkbox" name="' . $inputPrefix . '[compatVersion][all]" id="compatVersionAll" value="1" />
170 <label for="compatVersionAll">Check all (ignore selection above)</label>
171 </li>
172 <li>
173 WARNING: this might break the output of your website.
174 </li>
175 </ol>
176 </fieldset>
177 ';
178 }
179 return $content;
180 }
181
182 /**
183 * Checks if user input is valid
184 *
185 * @param string pointer to output custom messages
186 * @return boolean true if user input is correct, then the update is performed. When false, return to getUserInput
187 */
188 function checkUserInput(&$customMessages) {
189 global $TYPO3_CONF_VARS;
190
191 if ($this->compatVersionIsCurrent()) {
192 return 1;
193 } else {
194 if ($this->userInput['compatVersion']['all']) {
195 return 1;
196 } else {
197 $performUpdate = 1;
198 $oldVersion = t3lib_div::int_from_ver($TYPO3_CONF_VARS['SYS']['compat_version']);
199 $currentVersion = t3lib_div::int_from_ver(TYPO3_branch);
200
201 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['compat_version'] as $internalName => $details) {
202 if ($details['version'] > $oldVersion && $details['version'] <= $currentVersion) {
203 if (!$this->userInput['compatVersion'][$internalName]) {
204 $performUpdate = 0;
205 $customMessages = 'If you want to update the compatibility version, you need to confirm all checkboxes on the previous page.';
206 break;
207 }
208 }
209 }
210 return $performUpdate;
211 }
212 }
213 }
214
215 /**
216 * Performs the update itself
217 *
218 * @param array pointer where to insert all DB queries made, so they can be shown to the user if wanted
219 * @param string pointer to output custom messages
220 * @return boolean true if update succeeded, false otherwise
221 */
222 function performUpdate(&$dbQueries, &$customMessages) {
223 $customMessages = '';
224
225 // if we just set it to an older version
226 if ($this->userInput['version']) {
227 $customMessages .= 'If you want to see what you need to do to use the new features, run the update wizard again!';
228 }
229
230 $linesArr = $this->pObj->writeToLocalconf_control();
231 $version = $this->userInput['version'] ? $this->userInput['version'] : TYPO3_branch;
232 $this->pObj->setValueInLocalconfFile($linesArr, '$TYPO3_CONF_VARS[\'SYS\'][\'compat_version\']', $version);
233 $this->pObj->writeToLocalconf_control($linesArr,0);
234 $customMessages.= '<br />The compatibility version has been set to '.$version.'.';
235
236 return 1;
237 }
238
239
240 /**********************
241 *
242 * HELPER FUNCTIONS - just used in this update method
243 *
244 **********************/
245 /**
246 * checks if compatibility version is set to current version
247 *
248 * @return boolean true if compat version is equal the current version
249 */
250 function compatVersionIsCurrent() {
251 global $TYPO3_CONF_VARS;
252 if (TYPO3_branch != $TYPO3_CONF_VARS['SYS']['compat_version']) {
253 return 0;
254 } else {
255 return 1;
256 }
257 }
258
259 /**
260 * show changes needed
261 *
262 * @param string input prefix to prepend all form fields with.
263 * @return string HTML output
264 */
265 function showChangesNeeded($inputPrefix = '') {
266 global $TYPO3_CONF_VARS;
267 $oldVersion = t3lib_div::int_from_ver($TYPO3_CONF_VARS['SYS']['compat_version']);
268 $currentVersion = t3lib_div::int_from_ver(TYPO3_branch);
269
270 $tableContents = '';
271
272 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['compat_version'])) {
273 $updateWizardBoxes = '';
274 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['compat_version'] as $internalName => $details) {
275 if ($details['version'] > $oldVersion && $details['version'] <= $currentVersion) {
276 $description = str_replace(chr(10),'<br />',$details['description']);
277 $description_acknowledge = (isset($details['description_acknowledge']) ? str_replace(chr(10),'<br />',$details['description_acknowledge']) : '');
278
279 $updateWizardBoxes.= '
280 <div style="border: 1px solid; padding: 10px; margin: 10px; padding-top: 0px; width: 500px;">
281 <h3>'.(isset($details['title'])?$details['title']:$internalName).'</h3>
282 ' . $description .
283 (strlen($description_acknowledge) ? '<p>'.$description_acknowledge.'</p>' : '').
284 (strlen($inputPrefix) ? '
285 <fieldset>
286 <ol>
287 <li class="labelAfter">
288 <input type="checkbox" name="' . $inputPrefix . '[compatVersion][' . $internalName . ']" id="compatVersion' . $internalName . '" value="1" />
289 <label for="compatVersion' . $internalName . '">Acknowledged</label>
290 </li>
291 </ol>
292 </fieldset>
293 ' : '').'
294 </div>';
295 }
296 }
297 }
298 if (strlen($updateWizardBoxes)) {
299 return $updateWizardBoxes;
300 }
301 return '';
302 }
303 }
304 ?>