8bcdb50bb8eed86fce7eda9260d4fa17c2359598
[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\Database\ConnectionPool;
18 use TYPO3\CMS\Core\Registry;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21 /**
22 * Generic class that every update wizard class inherits from.
23 * Used by the update wizard in the install tool.
24 */
25 abstract class AbstractUpdate
26 {
27 /**
28 * The human-readable title of the upgrade wizard
29 *
30 * @var string
31 */
32 protected $title;
33
34 /**
35 * The update wizard identifier
36 *
37 * @var string
38 */
39 protected $identifier;
40
41 /**
42 * User input, set from outside
43 *
44 * @var string
45 */
46 public $userInput;
47
48 /**
49 * Returns the title attribute
50 *
51 * @return string The title of this update wizard
52 */
53 public function getTitle()
54 {
55 if ($this->title) {
56 return $this->title;
57 }
58 return $this->identifier;
59 }
60
61 /**
62 * Sets the title attribute
63 *
64 * @param string $title The title of this update wizard
65 */
66 public function setTitle($title)
67 {
68 $this->title = $title;
69 }
70
71 /**
72 * Returns the identifier of this class
73 *
74 * @return string The identifier of this update wizard
75 */
76 public function getIdentifier()
77 {
78 return $this->identifier;
79 }
80
81 /**
82 * Sets the identifier attribute
83 *
84 * @param string $identifier The identifier of this update wizard
85 */
86 public function setIdentifier($identifier)
87 {
88 $this->identifier = $identifier;
89 }
90
91 /**
92 * Simple wrapper function that helps dealing with the compatibility
93 * layer that some update wizards don't have a second parameter
94 * thus, it evaluates everything already
95 *
96 * @return bool If the wizard should be shown at all on the overview page
97 * @see checkForUpdate()
98 */
99 public function shouldRenderWizard()
100 {
101 $explanation = '';
102 $result = $this->checkForUpdate($explanation);
103 return (bool)$result === true;
104 }
105
106 /**
107 * Check if given table exists
108 *
109 * @param string $table
110 * @return bool
111 */
112 protected function checkIfTableExists($table)
113 {
114 $tableExists = GeneralUtility::makeInstance(ConnectionPool::class)
115 ->getConnectionForTable($table)
116 ->getSchemaManager()
117 ->tablesExist([$table]);
118
119 return $tableExists;
120 }
121
122 /**
123 * Checks whether updates are required.
124 *
125 * @param string &$description The description for the update
126 * @return bool Whether an update is required (TRUE) or not (FALSE)
127 */
128 abstract public function checkForUpdate(&$description);
129
130 /**
131 * Performs the accordant updates.
132 *
133 * @param array &$dbQueries Queries done in this update
134 * @param string &$customMessage Custom message
135 * @return bool Whether everything went smoothly or not
136 */
137 abstract public function performUpdate(array &$dbQueries, &$customMessage);
138
139 /**
140 * This method can be called to install extensions following all proper processes
141 * (e.g. installing in extList, respecting priority, etc.)
142 *
143 * @param array $extensionKeys List of keys of extensions to install
144 */
145 protected function installExtensions(array $extensionKeys)
146 {
147 /** @var $installUtility \TYPO3\CMS\Extensionmanager\Utility\InstallUtility */
148 $installUtility = GeneralUtility::makeInstance(
149 \TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class
150 );
151 foreach ($extensionKeys as $extension) {
152 $installUtility->install($extension);
153 }
154 }
155
156 /**
157 * Marks some wizard as being "seen" so that it not shown again.
158 *
159 * Writes the info in LocalConfiguration.php
160 *
161 * @param mixed $confValue The configuration is set to this value
162 */
163 protected function markWizardAsDone($confValue = 1)
164 {
165 GeneralUtility::makeInstance(Registry::class)->set('installUpdate', static::class, $confValue);
166 }
167
168 /**
169 * Checks if this wizard has been "done" before
170 *
171 * @return bool TRUE if wizard has been done before, FALSE otherwise
172 */
173 protected function isWizardDone()
174 {
175 $wizardClassName = static::class;
176 return GeneralUtility::makeInstance(Registry::class)->get('installUpdate', $wizardClassName, false);
177 }
178 }