[TASK] Doctrine: Migrate admin_get_tables in AbstractUpdate
[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 TYPO3\CMS\Core\Configuration\ConfigurationManager;
18 use TYPO3\CMS\Core\Database\ConnectionPool;
19 use TYPO3\CMS\Core\Registry;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Install\Controller\Action\Tool\UpgradeWizard;
22
23 /**
24 * Generic class that every update wizard class inherits from.
25 * Used by the update wizard in the install tool.
26 */
27 abstract class AbstractUpdate
28 {
29 /**
30 * The human-readable title of the upgrade wizard
31 *
32 * @var string
33 */
34 protected $title;
35
36 /**
37 * The update wizard identifier
38 *
39 * @var string
40 */
41 protected $identifier;
42
43 /**
44 * Parent object
45 *
46 * @var UpgradeWizard
47 */
48 public $pObj;
49
50 /**
51 * User input, set from outside
52 *
53 * @var string
54 */
55 public $userInput;
56
57 /**
58 * Current TYPO3 version number, set from outside
59 * Version number coming from \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger()
60 *
61 * @var int
62 */
63 public $versionNumber;
64
65 /**
66 * Returns the title attribute
67 *
68 * @return string The title of this update wizard
69 */
70 public function getTitle()
71 {
72 if ($this->title) {
73 return $this->title;
74 } else {
75 return $this->identifier;
76 }
77 }
78
79 /**
80 * Sets the title attribute
81 *
82 * @param string $title The title of this update wizard
83 * @return void
84 */
85 public function setTitle($title)
86 {
87 $this->title = $title;
88 }
89
90 /**
91 * Returns the identifier of this class
92 *
93 * @return string The identifier of this update wizard
94 */
95 public function getIdentifier()
96 {
97 return $this->identifier;
98 }
99
100 /**
101 * Sets the identifier attribute
102 *
103 * @param string $identifier The identifier of this update wizard
104 * @return void
105 */
106 public function setIdentifier($identifier)
107 {
108 $this->identifier = $identifier;
109 }
110
111 /**
112 * Simple wrapper function that helps dealing with the compatibility
113 * layer that some update wizards don't have a second parameter
114 * thus, it evaluates everything already
115 *
116 * @return bool If the wizard should be shown at all on the overview page
117 * @see checkForUpdate()
118 */
119 public function shouldRenderWizard()
120 {
121 $showUpdate = 0;
122 $explanation = '';
123 $result = $this->checkForUpdate($explanation, $showUpdate);
124 return $showUpdate > 0 || $result == true;
125 }
126
127 /**
128 * Simple wrapper function that helps to check whether (if)
129 * this feature is cool if you want to tell the user that the update wizard
130 * is working fine, just as output (useful for the character set / utf8 wizard)
131 *
132 * @return bool If the wizard should render the Next() button on the overview page
133 * @see checkForUpdate()
134 */
135 public function shouldRenderNextButton()
136 {
137 $showUpdate = 0;
138 $explanation = '';
139 $result = $this->checkForUpdate($explanation, $showUpdate);
140 return $showUpdate != 2 || $result;
141 }
142
143 /**
144 * Check if given table exists
145 *
146 * @param string $table
147 * @return bool
148 */
149 public function checkIfTableExists($table)
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 mixed &$customMessages Custom messages
172 * @return bool Whether everything went smoothly or not
173 */
174 abstract public function performUpdate(array &$dbQueries, &$customMessages);
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 * @return void
182 */
183 protected function installExtensions(array $extensionKeys)
184 {
185 /** @var $installUtility \TYPO3\CMS\Extensionmanager\Utility\InstallUtility */
186 $installUtility = GeneralUtility::makeInstance(
187 \TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class
188 );
189 foreach ($extensionKeys as $extension) {
190 $installUtility->install($extension);
191 }
192 }
193
194 /**
195 * Marks some wizard as being "seen" so that it not shown again.
196 *
197 * Writes the info in LocalConfiguration.php
198 *
199 * @param mixed $confValue The configuration is set to this value
200 * @return void
201 */
202 protected function markWizardAsDone($confValue = 1)
203 {
204 GeneralUtility::makeInstance(Registry::class)->set('installUpdate', get_class($this), $confValue);
205 }
206
207 /**
208 * Checks if this wizard has been "done" before
209 *
210 * @return bool TRUE if wizard has been done before, FALSE otherwise
211 */
212 protected function isWizardDone()
213 {
214 $wizardClassName = get_class($this);
215 $done = GeneralUtility::makeInstance(Registry::class)->get('installUpdate', $wizardClassName, false);
216
217 // Fall back in case the wizard for migration of "wizard done" flags to system registry was not run yet
218 if (!$done) {
219 try {
220 GeneralUtility::makeInstance(ConfigurationManager::class)
221 ->getLocalConfigurationValueByPath('INSTALL/wizardDone/' . $wizardClassName);
222 $done = true;
223 } catch (\RuntimeException $e) {
224 }
225 }
226
227 return $done;
228 }
229 }