487853f0de6c00ab0ce176843d95b0b174002a5f
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / AbstractUpdate.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 use Symfony\Component\Console\Output\OutputInterface;
18 use TYPO3\CMS\Core\Database\ConnectionPool;
19 use TYPO3\CMS\Core\Registry;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 /**
23 * Generic class that every update wizard class inherits from.
24 * Used by the update wizard in the install tool.
25 *
26 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0
27 */
28 abstract class AbstractUpdate implements UpgradeWizardInterface, ChattyInterface
29 {
30 public function __construct()
31 {
32 trigger_error('Deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, use UpgradeWizardInterface directly. affected class: ' . get_class($this), E_USER_DEPRECATED);
33 }
34 /**
35 * The human-readable title of the upgrade wizard
36 *
37 * @var string
38 */
39 protected $title;
40
41 /**
42 * The update wizard identifier
43 *
44 * @var string
45 */
46 protected $identifier;
47
48 /**
49 * User input, set from outside
50 *
51 * @var string
52 */
53 public $userInput;
54
55 /**
56 * @var OutputInterface
57 */
58 protected $output;
59
60 /**
61 * Returns the title attribute
62 *
63 * @deprecated Deprecated since TYPO3 v9
64 * @return string The title of this update wizard
65 */
66 public function getTitle(): string
67 {
68 trigger_error(
69 'Deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, use UpgradeWizardInterface directly. affected class: ' . get_class($this),
70 E_USER_DEPRECATED
71 );
72 if ($this->title) {
73 return $this->title;
74 }
75 return $this->identifier;
76 }
77
78 /**
79 * Sets the title attribute
80 *
81 * @param string $title The title of this update wizard
82 */
83 public function setTitle($title)
84 {
85 trigger_error(
86 'Deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, use UpgradeWizardInterface directly. affected class: ' . get_class($this),
87 E_USER_DEPRECATED
88 );
89 $this->title = $title;
90 }
91
92 /**
93 * Returns the identifier of this class
94 *
95 * @return string The identifier of this update wizard
96 */
97 public function getIdentifier(): string
98 {
99 trigger_error(
100 'Deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, use UpgradeWizardInterface directly. affected class: ' . get_class($this),
101 E_USER_DEPRECATED
102 );
103 return $this->identifier ?? static::class;
104 }
105
106 /**
107 * Sets the identifier attribute
108 *
109 * @param string $identifier The identifier of this update wizard
110 */
111 public function setIdentifier($identifier)
112 {
113 trigger_error(
114 'Deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, use UpgradeWizardInterface directly. affected class: ' . get_class($this),
115 E_USER_DEPRECATED
116 );
117 $this->identifier = $identifier;
118 }
119
120 /**
121 * Simple wrapper function that helps dealing with the compatibility
122 * layer that some update wizards don't have a second parameter
123 * thus, it evaluates everything already
124 *
125 * @return bool If the wizard should be shown at all on the overview page
126 * @see checkForUpdate()
127 */
128 public function shouldRenderWizard()
129 {
130 trigger_error(
131 'Deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, use UpgradeWizardInterface directly. affected class: ' . get_class($this),
132 E_USER_DEPRECATED
133 );
134 $explanation = '';
135 $result = $this->checkForUpdate($explanation);
136 return (bool)$result === true;
137 }
138
139 /**
140 * Check if given table exists
141 *
142 * @param string $table
143 * @return bool
144 */
145 protected function checkIfTableExists($table)
146 {
147 trigger_error(
148 'Deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, use UpgradeWizardInterface directly. affected class: ' . get_class($this),
149 E_USER_DEPRECATED
150 );
151 $tableExists = GeneralUtility::makeInstance(ConnectionPool::class)
152 ->getConnectionForTable($table)
153 ->getSchemaManager()
154 ->tablesExist([$table]);
155
156 return $tableExists;
157 }
158
159 /**
160 * Checks whether updates are required.
161 *
162 * @param string &$description The description for the update
163 * @return bool Whether an update is required (TRUE) or not (FALSE)
164 */
165 abstract public function checkForUpdate(&$description);
166
167 /**
168 * Performs the accordant updates.
169 *
170 * @param array &$dbQueries Queries done in this update
171 * @param string &$customMessage Custom message
172 * @return bool Whether everything went smoothly or not
173 */
174 abstract public function performUpdate(array &$dbQueries, &$customMessage);
175
176 /**
177 * This method can be called to install extensions following all proper processes
178 * (e.g. installing in extList, respecting priority, etc.)
179 *
180 * @param array $extensionKeys List of keys of extensions to install
181 */
182 protected function installExtensions(array $extensionKeys)
183 {
184 trigger_error(
185 'Deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, use UpgradeWizardInterface directly. affected class: ' . get_class($this),
186 E_USER_DEPRECATED
187 );
188 /** @var \TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility */
189 $installUtility = GeneralUtility::makeInstance(
190 \TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class
191 );
192 $installUtility->install($extensionKeys);
193 }
194
195 /**
196 * Marks some wizard as being "seen" so that it not shown again.
197 *
198 * Writes the info in LocalConfiguration.php
199 *
200 * @param mixed $confValue The configuration is set to this value
201 */
202 protected function markWizardAsDone($confValue = 1)
203 {
204 trigger_error(
205 'Deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, use UpgradeWizardInterface directly. affected class: ' . get_class($this),
206 E_USER_DEPRECATED
207 );
208 GeneralUtility::makeInstance(Registry::class)->set('installUpdate', static::class, $confValue);
209 }
210
211 /**
212 * Checks if this wizard has been "done" before
213 *
214 * @return bool TRUE if wizard has been done before, FALSE otherwise
215 */
216 protected function isWizardDone()
217 {
218 trigger_error(
219 'Deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, use UpgradeWizardInterface directly. affected class: ' . get_class($this),
220 E_USER_DEPRECATED
221 );
222 $wizardClassName = static::class;
223 return GeneralUtility::makeInstance(Registry::class)->get('installUpdate', $wizardClassName, false);
224 }
225
226 /**
227 * Return the description for this wizard
228 *
229 * @return string
230 */
231 public function getDescription(): string
232 {
233 trigger_error(
234 'Deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, use UpgradeWizardInterface directly. affected class: ' . get_class($this),
235 E_USER_DEPRECATED
236 );
237 return '';
238 }
239
240 /**
241 * Execute the update
242 * Called when a wizard reports that an update is necessary
243 *
244 * @return bool
245 */
246 public function executeUpdate(): bool
247 {
248 trigger_error(
249 'Deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, use UpgradeWizardInterface directly. affected class: ' . get_class($this),
250 E_USER_DEPRECATED
251 );
252 $queries = [];
253 $message = '';
254 $result = $this->performUpdate($queries, $message);
255 $this->output->write($message);
256 return $result;
257 }
258
259 /**
260 * Is an update necessary?
261 * Is used to determine whether a wizard needs to be run.
262 * Check if data for migration exists.
263 *
264 * @return bool
265 */
266 public function updateNecessary(): bool
267 {
268 trigger_error(
269 'Deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, use UpgradeWizardInterface directly. affected class: ' . get_class($this),
270 E_USER_DEPRECATED
271 );
272 $description = '';
273 $result = $this->checkForUpdate($description);
274 $this->output->write($description);
275 return $result;
276 }
277
278 /**
279 * Returns an array of class names of Prerequisite classes
280 * This way a wizard can define dependencies like "database up-to-date" or
281 * "reference index updated"
282 *
283 * @return string[]
284 */
285 public function getPrerequisites(): array
286 {
287 trigger_error(
288 'Deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, use UpgradeWizardInterface directly. affected class: ' . get_class($this),
289 E_USER_DEPRECATED
290 );
291 return [
292 DatabaseUpdatedPrerequisite::class
293 ];
294 }
295
296 /**
297 * Setter injection for output into upgrade wizards
298 *
299 * @param OutputInterface $output
300 */
301 public function setOutput(OutputInterface $output): void
302 {
303 trigger_error(
304 'Deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, use UpgradeWizardInterface directly. affected class: ' . get_class($this),
305 E_USER_DEPRECATED
306 );
307 $this->output = $output;
308 }
309 }