[TASK] Merge submodule version into core
[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 textfile 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 * Generic class that every update wizard class inherits from.
31 * Used by the update wizard in the install tool.
32 *
33 * @author Benjamin Mack <benni@typo3.org>
34 */
35 abstract class AbstractUpdate {
36
37 /**
38 * the human-readable title of the upgrade wizard
39 */
40 protected $title;
41
42 /**
43 * parent object
44 *
45 * @var \TYPO3\CMS\Install\Installer
46 */
47 public $pObj;
48
49 /**
50 * user input, set from outside
51 */
52 public $userInput;
53
54 /**
55 * current TYPO3 version number, set from outside
56 * version number coming from \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger()
57 */
58 public $versionNumber;
59
60 /**
61 * Helper functions, getters and setters
62 */
63 /**
64 * returns the title attribute
65 *
66 * @return the title of this update wizard
67 */
68 public function getTitle() {
69 if ($this->title) {
70 return $this->title;
71 } else {
72 return $this->identifier;
73 }
74 }
75
76 /**
77 * sets the title attribute
78 *
79 * @param $title the title of this update wizard
80 * @return void
81 */
82 public function setTitle($title) {
83 $this->title = $title;
84 }
85
86 /**
87 * returns the identifier of this class
88 *
89 * @return the identifier of this update wizard
90 */
91 public function getIdentifier() {
92 return $this->identifier;
93 }
94
95 /**
96 * sets the identifier attribute
97 *
98 * @param $identifier the identifier of this update wizard
99 * @return void
100 */
101 public function setIdentifier($identifier) {
102 $this->identifier = $identifier;
103 }
104
105 /**
106 * simple wrapper function that helps dealing with the compatibility
107 * layer that some update wizards don't have a second parameter
108 * thus, it evaluates everything already
109 *
110 * @return boolean if the wizard should be shown at all on the overview page
111 * @see checkForUpdate()
112 */
113 public function shouldRenderWizard() {
114 $showUpdate = 0;
115 $explanation = '';
116 $res = $this->checkForUpdate($explanation, $showUpdate);
117 return $showUpdate > 0 || $res == TRUE;
118 }
119
120 /**
121 * simple wrapper function that helps to check whether (if)
122 * this feature is cool if you want to tell the user that the update wizard
123 * is working fine, just as output (useful for the character set / utf8 wizard)
124 *
125 * @return boolean if the wizard should render the Next() button on the overview page
126 * @see checkForUpdate()
127 */
128 public function shouldRenderNextButton() {
129 $showUpdate = 0;
130 $explanation = '';
131 $res = $this->checkForUpdate($explanation, $showUpdate);
132 return $showUpdate != 2 || $res == TRUE;
133 }
134
135 /**
136 * Checks whether updates are required.
137 *
138 * @param string &$description: The description for the update
139 * @return boolean Whether an update is required (TRUE) or not (FALSE)
140 */
141 abstract public function checkForUpdate(&$description);
142
143 /**
144 * Performs the accordant updates.
145 *
146 * @param array &$dbQueries: queries done in this update
147 * @param mixed &$customMessages: custom messages
148 * @return boolean Whether everything went smoothly or not
149 */
150 abstract public function performUpdate(array &$dbQueries, &$customMessages);
151
152 /**
153 * This method can be called to install extensions following all proper processes
154 * (e.g. installing in extList, respecting priority, etc.)
155 *
156 * @param array $extensionKeys List of keys of extensions to install
157 * @return void
158 */
159 protected function installExtensions($extensionKeys) {
160 /** @var $installUtility \TYPO3\CMS\Extensionmanager\Utility\InstallUtility */
161 $installUtility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
162 'TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility'
163 );
164 foreach ($extensionKeys as $extension) {
165 $installUtility->install($extension);
166 }
167 }
168
169 /**
170 * Marks some wizard as being "seen" so that it not shown again.
171 *
172 * Writes the info in LocalConfiguration.php
173 *
174 * @param mixed $confValue The configuration is set to this value
175 * @return void
176 */
177 protected function markWizardAsDone($confValue = 1) {
178 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager')->setLocalConfigurationValueByPath('INSTALL/wizardDone/' . get_class($this), $confValue);
179 }
180
181 /**
182 * Checks if this wizard has been "done" before
183 *
184 * @return boolean TRUE if wizard has been done before, FALSE otherwise
185 */
186 protected function isWizardDone() {
187 $wizardClassName = get_class($this);
188 $done = FALSE;
189 if (isset($GLOBALS['TYPO3_CONF_VARS']['INSTALL']['wizardDone'][$wizardClassName]) && $GLOBALS['TYPO3_CONF_VARS']['INSTALL']['wizardDone'][$wizardClassName]) {
190 $done = TRUE;
191 }
192 return $done;
193 }
194
195 }
196
197
198 ?>