0fce40eaf7ae146026f217b68a28e69e2f99cd9d
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / AbstractUpdate.php
1 <?php
2 namespace TYPO3\CMS\Install\Updates;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Benjamin Mack <benni@typo3.org>
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 * Generic class that every update wizard class inherits from.
32 * Used by the update wizard in the install tool.
33 *
34 * @author Benjamin Mack <benni@typo3.org>
35 */
36 abstract class AbstractUpdate {
37
38 /**
39 * The human-readable title of the upgrade wizard
40 *
41 * @var string
42 */
43 protected $title;
44
45 /**
46 * The update wizard identifier
47 *
48 * @var string
49 */
50 protected $identifier;
51
52 /**
53 * Parent object
54 *
55 * @var \TYPO3\CMS\Install\Installer
56 */
57 public $pObj;
58
59 /**
60 * User input, set from outside
61 *
62 * @var string
63 */
64 public $userInput;
65
66 /**
67 * Current TYPO3 version number, set from outside
68 * Version number coming from \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger()
69 *
70 * @var integer
71 */
72 public $versionNumber;
73
74 /**
75 * Returns the title attribute
76 *
77 * @return string The title of this update wizard
78 */
79 public function getTitle() {
80 if ($this->title) {
81 return $this->title;
82 } else {
83 return $this->identifier;
84 }
85 }
86
87 /**
88 * Sets the title attribute
89 *
90 * @param string $title The title of this update wizard
91 * @return void
92 */
93 public function setTitle($title) {
94 $this->title = $title;
95 }
96
97 /**
98 * Returns the identifier of this class
99 *
100 * @return string The identifier of this update wizard
101 */
102 public function getIdentifier() {
103 return $this->identifier;
104 }
105
106 /**
107 * Sets the identifier attribute
108 *
109 * @param string $identifier The identifier of this update wizard
110 * @return void
111 */
112 public function setIdentifier($identifier) {
113 $this->identifier = $identifier;
114 }
115
116 /**
117 * Simple wrapper function that helps dealing with the compatibility
118 * layer that some update wizards don't have a second parameter
119 * thus, it evaluates everything already
120 *
121 * @return boolean If the wizard should be shown at all on the overview page
122 * @see checkForUpdate()
123 */
124 public function shouldRenderWizard() {
125 $showUpdate = 0;
126 $explanation = '';
127 $result = $this->checkForUpdate($explanation, $showUpdate);
128 return $showUpdate > 0 || $result == TRUE;
129 }
130
131 /**
132 * Simple wrapper function that helps to check whether (if)
133 * this feature is cool if you want to tell the user that the update wizard
134 * is working fine, just as output (useful for the character set / utf8 wizard)
135 *
136 * @return boolean If the wizard should render the Next() button on the overview page
137 * @see checkForUpdate()
138 */
139 public function shouldRenderNextButton() {
140 $showUpdate = 0;
141 $explanation = '';
142 $result = $this->checkForUpdate($explanation, $showUpdate);
143 return $showUpdate != 2 || $result == TRUE;
144 }
145
146 /**
147 * Check if given table exists
148 *
149 * @param string $table
150 * @return boolean
151 */
152 public function checkIfTableExists($table) {
153 $databaseTables = $GLOBALS['TYPO3_DB']->admin_get_tables();
154 if (array_key_exists($table, $databaseTables)) {
155 return TRUE;
156 }
157 return FALSE;
158 }
159
160 /**
161 * Checks whether updates are required.
162 *
163 * @param string &$description The description for the update
164 * @return boolean Whether an update is required (TRUE) or not (FALSE)
165 */
166 abstract public function checkForUpdate(&$description);
167
168 /**
169 * Performs the accordant updates.
170 *
171 * @param array &$dbQueries Queries done in this update
172 * @param mixed &$customMessages Custom messages
173 * @return boolean Whether everything went smoothly or not
174 */
175 abstract public function performUpdate(array &$dbQueries, &$customMessages);
176
177 /**
178 * This method can be called to install extensions following all proper processes
179 * (e.g. installing in extList, respecting priority, etc.)
180 *
181 * @param array $extensionKeys List of keys of extensions to install
182 * @return void
183 */
184 protected function installExtensions(array $extensionKeys) {
185 /** @var $installUtility \TYPO3\CMS\Extensionmanager\Utility\InstallUtility */
186 $installUtility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
187 'TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility'
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 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager')->setLocalConfigurationValueByPath('INSTALL/wizardDone/' . get_class($this), $confValue);
204 }
205
206 /**
207 * Checks if this wizard has been "done" before
208 *
209 * @return boolean TRUE if wizard has been done before, FALSE otherwise
210 */
211 protected function isWizardDone() {
212 $wizardClassName = get_class($this);
213 $done = FALSE;
214 if (
215 isset($GLOBALS['TYPO3_CONF_VARS']['INSTALL']['wizardDone'][$wizardClassName])
216 && $GLOBALS['TYPO3_CONF_VARS']['INSTALL']['wizardDone'][$wizardClassName]
217 ) {
218 $done = TRUE;
219 }
220 return $done;
221 }
222
223 }