60fcc15dba451319e75cb50b019af639c968d4b2
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / CompatVersionUpdate.php
1 <?php
2 namespace TYPO3\CMS\Install\Updates;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Sebastian Kurfürst <sebastian@garbage-group.de>
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 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Contains the update class for the compatibility version.
32 * Used by the update wizard in the install tool.
33 *
34 * @author Sebastian Kurfürst <sebastian@garbage-group.de
35 */
36 class CompatVersionUpdate extends AbstractUpdate {
37
38 /**
39 * @var string
40 */
41 protected $title = 'Version Compatibility';
42
43 /**
44 * Function which checks if update is needed. Called in the beginning of an update process.
45 *
46 * @param string &$description Pointer to description for the update
47 * @return boolean TRUE if update is needs to be performed, FALSE otherwise.
48 */
49 public function checkForUpdate(&$description) {
50 if (!$this->compatVersionIsCurrent()) {
51 $description = '
52 <p>
53 Your current TYPO3 installation is configured to
54 <strong>behave like version
55 ' . htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version']) . '
56 </strong> of TYPO3. If you just upgraded from this version,
57 you most likely want to <strong>use new features</strong> as
58 well.
59 </p>
60 <p>
61 In the next step, you will see the things that need to be
62 adjusted to make your installation compatible with the new
63 features.
64 </p>
65 ';
66 return TRUE;
67 }
68 return FALSE;
69 }
70
71 /**
72 * Second step: get user input if needed
73 *
74 * @param string Input prefix, all names of form fields have to start with this. Append custom name in [ ... ]
75 * @return string HTML output
76 */
77 public function getUserInput($inputPrefix) {
78 if ($this->compatVersionIsCurrent()) {
79 $content = '
80 <fieldset>
81 <ol>
82 <li>
83 <strong>You updated from an older version of TYPO3</strong>:
84 </li>
85 <li>
86 <label for="version">Select the version where you have upgraded from:</label>
87 <select name="' . $inputPrefix . '[version]" id="version">
88 ';
89 $versions = array(
90 '3.8' => '<= 3.8',
91 '4.1' => '<= 4.1',
92 '4.2' => '<= 4.2',
93 '4.3' => '<= 4.3',
94 '4.4' => '<= 4.4',
95 '4.5' => '<= 4.5'
96 );
97 foreach ($versions as $singleVersion => $caption) {
98 $content .= '
99 <option value="' . $singleVersion . '">' . $caption . '</option>
100 ';
101 }
102 $content .= '
103 </select>
104 </li>
105 </ol>
106 </fieldset>
107 ';
108 } else {
109 $content = '
110 <p>
111 TYPO3 output is currently compatible to version ' . htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version']) . '.
112 To use all the new features in the current TYPO3 version,
113 make sure you follow the guidelines below to upgrade without
114 problems.
115 </p>
116 <p>
117 <strong>
118 Follow the steps below carefully and confirm every step!
119 </strong>
120 <br />
121 You will see this list again after you performed the update.
122 </p>
123 ';
124 $content .= $this->showChangesNeeded($inputPrefix);
125 $content .= '
126 <fieldset>
127 <ol>
128 <li class="labelAfter">
129 <input type="checkbox" name="' . $inputPrefix . '[compatVersion][all]" id="compatVersionAll" value="1" />
130 <label for="compatVersionAll">Check all (ignore selection above)</label>
131 </li>
132 <li>
133 WARNING: this might break the output of your website.
134 </li>
135 </ol>
136 </fieldset>
137 ';
138 }
139 return $content;
140 }
141
142 /**
143 * Checks if user input is valid
144 *
145 * @param string Pointer to output custom messages
146 * @return boolean TRUE if user input is correct, then the update is performed. When FALSE, return to getUserInput
147 */
148 public function checkUserInput(&$customMessages) {
149 if ($this->compatVersionIsCurrent()) {
150 return TRUE;
151 } else {
152 if ($this->userInput['compatVersion']['all']) {
153 return TRUE;
154 } else {
155 $performUpdate = TRUE;
156 $oldVersion = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger($GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version']);
157 $currentVersion = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_branch);
158 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['compat_version'] as $internalName => $details) {
159 if ($details['version'] > $oldVersion && $details['version'] <= $currentVersion) {
160 if (!$this->userInput['compatVersion'][$internalName]) {
161 $performUpdate = FALSE;
162 $customMessages = 'If you want to update the compatibility version, you need to confirm all checkboxes on the previous page.';
163 break;
164 }
165 }
166 }
167 return $performUpdate;
168 }
169 }
170 }
171
172 /**
173 * Performs the update itself
174 *
175 * @param array $dbQueries where to insert all DB queries made, so they can be shown to the user if wanted
176 * @param string $customMessages to output custom messages
177 * @return boolean TRUE if update succeeded, FALSE otherwise
178 */
179 public function performUpdate(array &$dbQueries, &$customMessages) {
180 $customMessages = '';
181 // If we just set it to an older version
182 if ($this->userInput['version']) {
183 $customMessages .= 'If you want to see what you need to do to use the new features, run the update wizard again!';
184 }
185 $version = $this->userInput['version'] ? $this->userInput['version'] : TYPO3_branch;
186 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager')->setLocalConfigurationValueByPath('SYS/compat_version', $version);
187 $customMessages .= '<br />The compatibility version has been set to ' . $version . '.';
188 return TRUE;
189 }
190
191 /**
192 * Checks if compatibility version is set to current version
193 *
194 * @return boolean TRUE if compat version is equal the current version
195 */
196 protected function compatVersionIsCurrent() {
197 if (TYPO3_branch != $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version']) {
198 return FALSE;
199 } else {
200 return TRUE;
201 }
202 }
203
204 /**
205 * Show changes needed
206 *
207 * @param string Input prefix to prepend all form fields with.
208 * @return string HTML output
209 */
210 protected function showChangesNeeded($inputPrefix = '') {
211 $oldVersion = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger($GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version']);
212 $currentVersion = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_branch);
213 $tableContents = '';
214 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['compat_version'])) {
215 $upgradeWizardBoxes = '';
216 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['compat_version'] as $internalName => $details) {
217 if ($details['version'] > $oldVersion && $details['version'] <= $currentVersion) {
218 $description = str_replace(chr(10), '<br />', $details['description']);
219 $description_acknowledge = isset($details['description_acknowledge']) ? str_replace(chr(10), '<br />', $details['description_acknowledge']) : '';
220 $upgradeWizardBoxes .= '
221 <div style="border: 1px solid; padding: 10px; margin: 10px; padding-top: 0px; width: 500px;">
222 <h3>' . (isset($details['title']) ? $details['title'] : $internalName) . '</h3>
223 ' . $description . (strlen($description_acknowledge) ? '<p>' . $description_acknowledge . '</p>' : '') . (strlen($inputPrefix) ? '
224 <fieldset>
225 <ol>
226 <li class="labelAfter">
227 <input type="checkbox" name="' . $inputPrefix . '[compatVersion][' . $internalName . ']" id="compatVersion' . $internalName . '" value="1" />
228 <label for="compatVersion' . $internalName . '">Acknowledged</label>
229 </li>
230 </ol>
231 </fieldset>
232 ' : '') . '
233 </div>';
234 }
235 }
236 }
237 if (strlen($upgradeWizardBoxes)) {
238 return $upgradeWizardBoxes;
239 }
240 return '';
241 }
242
243 }