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