TYPO3 CMS  TYPO3_6-2
UpgradeWizard.php
Go to the documentation of this file.
1 <?php
3 
19 
24 
31 
37  protected function executeAction() {
38  // ext_localconf, db and ext_tables must be loaded for the upgrade wizards
40 
41  // To make sure initialUpdateDatabaseSchema is first wizard, it is added here instead of ext_localconf.php
42  $initialUpdateDatabaseSchemaUpdateObject = $this->getUpgradeObjectInstance('TYPO3\\CMS\\Install\\Updates\\InitialDatabaseSchemaUpdate', 'initialUpdateDatabaseSchema');
43  if ($initialUpdateDatabaseSchemaUpdateObject->shouldRenderWizard()) {
44  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'] = array_merge(
45  array('initialUpdateDatabaseSchema' => 'TYPO3\\CMS\\Install\\Updates\\InitialDatabaseSchemaUpdate'),
46  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']
47  );
48  $this->needsInitialUpdateDatabaseSchema = TRUE;
49  }
50 
51  // To make sure finalUpdateDatabaseSchema is last wizard, it is added here instead of ext_localconf.php
52  $finalUpdateDatabaseSchemaUpdateObject = $this->getUpgradeObjectInstance('TYPO3\\CMS\\Install\\Updates\\FinalDatabaseSchemaUpdate', 'finalUpdateDatabaseSchema');
53  if ($finalUpdateDatabaseSchemaUpdateObject->shouldRenderWizard()) {
54  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['finalUpdateDatabaseSchema'] = 'TYPO3\\CMS\\Install\\Updates\\FinalDatabaseSchemaUpdate';
55  }
56 
57  // Perform silent cache framework table upgrades
58  $this->silentCacheFrameworkTableSchemaMigration();
59 
60  $actionMessages = array();
61 
62  if (isset($this->postValues['set']['getUserInput'])) {
63  $actionMessages[] = $this->getUserInputForUpgradeWizard();
64  $this->view->assign('updateAction', 'getUserInput');
65  } elseif (isset($this->postValues['set']['performUpdate'])) {
66  $actionMessages[] = $this->performUpdate();
67  $this->view->assign('updateAction', 'performUpdate');
68  } else {
69  $actionMessages[] = $this->listUpdates();
70  $this->view->assign('updateAction', 'listUpdates');
71  }
72 
73  $this->view->assign('actionMessages', $actionMessages);
74 
75  return $this->view->render();
76  }
77 
83  protected function listUpdates() {
84  if (empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'])) {
86  $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\WarningStatus');
87  $message->setTitle('No update wizards registered');
88  return $message;
89  }
90 
91  $availableUpdates = array();
92  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'] as $identifier => $className) {
93  $updateObject = $this->getUpgradeObjectInstance($className, $identifier);
94  if ($updateObject->shouldRenderWizard()) {
95  // $explanation is changed by reference in upgrade objects!
96  $explanation = '';
97  $updateObject->checkForUpdate($explanation);
98  $availableUpdates[$identifier] = array(
99  'identifier' => $identifier,
100  'title' => $updateObject->getTitle(),
101  'explanation' => $explanation,
102  'renderNext' => FALSE,
103  );
104  if ($identifier === 'initialUpdateDatabaseSchema') {
105  $availableUpdates['initialUpdateDatabaseSchema']['renderNext'] = $this->needsInitialUpdateDatabaseSchema;
106  } elseif ($identifier === 'finalUpdateDatabaseSchema') {
107  // Okay to check here because finalUpdateDatabaseSchema is last element in array
108  $availableUpdates['finalUpdateDatabaseSchema']['renderNext'] = count($availableUpdates) === 1;
109  } elseif (!$this->needsInitialUpdateDatabaseSchema && $updateObject->shouldRenderNextButton()) {
110  // There are upgrade wizards that only show text and don't want to be executed
111  $availableUpdates[$identifier]['renderNext'] = TRUE;
112  }
113  }
114  }
115 
116  $this->view->assign('availableUpdates', $availableUpdates);
117 
119  $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\OkStatus');
120  $message->setTitle('Show available update wizards');
121  return $message;
122  }
123 
129  protected function getUserInputForUpgradeWizard() {
130  $wizardIdentifier = $this->postValues['values']['identifier'];
131 
132  $className = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][$wizardIdentifier];
133  $updateObject = $this->getUpgradeObjectInstance($className, $wizardIdentifier);
134  $wizardHtml = '';
135  if (method_exists($updateObject, 'getUserInput')) {
136  $wizardHtml = $updateObject->getUserInput('install[values][' . $wizardIdentifier . ']');
137  }
138 
139  $upgradeWizardData = array(
140  'identifier' => $wizardIdentifier,
141  'title' => $updateObject->getTitle(),
142  'wizardHtml' => $wizardHtml,
143  );
144 
145  $this->view->assign('upgradeWizardData', $upgradeWizardData);
146 
148  $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\OkStatus');
149  $message->setTitle('Show wizard options');
150  return $message;
151  }
152 
159  protected function performUpdate() {
160  $this->getDatabaseConnection()->store_lastBuiltQuery = TRUE;
161 
162  $wizardIdentifier = $this->postValues['values']['identifier'];
163  $className = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][$wizardIdentifier];
164  $updateObject = $this->getUpgradeObjectInstance($className, $wizardIdentifier);
165 
166  $wizardData = array(
167  'identifier' => $wizardIdentifier,
168  'title' => $updateObject->getTitle(),
169  );
170 
171  // $wizardInputErrorMessage is given as reference to wizard object!
172  $wizardInputErrorMessage = '';
173  if (method_exists($updateObject, 'checkUserInput') && !$updateObject->checkUserInput($wizardInputErrorMessage)) {
175  $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
176  $message->setTitle('Input parameter broken');
177  $message->setMessage($wizardInputErrorMessage ?: 'Something went wrong!');
178  $wizardData['wizardInputBroken'] = TRUE;
179  } else {
180  if (!method_exists($updateObject, 'performUpdate')) {
181  throw new \TYPO3\CMS\Install\Exception(
182  'No performUpdate method in update wizard with identifier ' . $wizardIdentifier,
183  1371035200
184  );
185  }
186 
187  // Both variables are used by reference in performUpdate()
188  $customOutput = '';
189  $databaseQueries = array();
190  $performResult = $updateObject->performUpdate($databaseQueries, $customOutput);
191 
192  if ($performResult) {
194  $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\OkStatus');
195  $message->setTitle('Update successful');
196  } else {
198  $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
199  $message->setTitle('Update failed!');
200  if ($customOutput) {
201  $message->setMessage($customOutput);
202  }
203  }
204 
205  if ($this->postValues['values']['showDatabaseQueries'] == 1) {
206  $wizardData['queries'] = $databaseQueries;
207  }
208  }
209 
210  $this->view->assign('wizardData', $wizardData);
211 
212  $this->getDatabaseConnection()->store_lastBuiltQuery = FALSE;
213 
214  // Next update wizard, if available
215  $nextUpgradeWizard = $this->getNextUpgradeWizardInstance($updateObject);
216  $nextUpgradeWizardIdentifier = '';
217  if ($nextUpgradeWizard) {
218  $nextUpgradeWizardIdentifier = $nextUpgradeWizard->getIdentifier();
219  }
220  $this->view->assign('nextUpgradeWizardIdentifier', $nextUpgradeWizardIdentifier);
221 
222  return $message;
223  }
224 
232  protected function getUpgradeObjectInstance($className, $identifier) {
233  $formValues = $this->postValues;
234  $updateObject = GeneralUtility::getUserObj($className);
235  $updateObject->setIdentifier($identifier);
236  $updateObject->versionNumber = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version);
237  $updateObject->pObj = $this;
238  $updateObject->userInput = $formValues['values'][$identifier];
239  return $updateObject;
240  }
241 
249  protected function getNextUpgradeWizardInstance($currentObj) {
250  $isPreviousRecord = TRUE;
251  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'] as $identifier => $className) {
252  // Find the current update wizard, and then start validating the next ones
253  if ($currentObj->getIdentifier() == $identifier) {
254  $isPreviousRecord = FALSE;
255  // For the updateDatabaseSchema-wizards verify they do not have to be executed again
256  if ($identifier !== 'initialUpdateDatabaseSchema' && $identifier !== 'finalUpdateDatabaseSchema') {
257  continue;
258  }
259  }
260  if (!$isPreviousRecord) {
261  $nextUpgradeWizard = $this->getUpgradeObjectInstance($className, $identifier);
262  if ($nextUpgradeWizard->shouldRenderWizard()) {
263  return $nextUpgradeWizard;
264  }
265  }
266  }
267  return FALSE;
268  }
269 
276  protected function silentCacheFrameworkTableSchemaMigration() {
278  $sqlHandler = $this->objectManager->get('TYPO3\\CMS\\Install\\Service\\SqlSchemaMigrationService');
279 
281  $cachingFrameworkDatabaseSchemaService = $this->objectManager->get('TYPO3\\CMS\\Install\\Service\\CachingFrameworkDatabaseSchemaService');
282  $expectedSchemaString = $cachingFrameworkDatabaseSchemaService->getCachingFrameworkRequiredDatabaseSchema();
283  $cleanedExpectedSchemaString = implode(LF, $sqlHandler->getStatementArray($expectedSchemaString, TRUE, '^CREATE TABLE '));
284  $neededTableDefinition = $sqlHandler->getFieldDefinitions_fileContent($cleanedExpectedSchemaString);
285  $currentTableDefinition = $sqlHandler->getFieldDefinitions_database();
286  $updateTableDefinition = $sqlHandler->getDatabaseExtra($neededTableDefinition, $currentTableDefinition);
287  $updateStatements = $sqlHandler->getUpdateSuggestions($updateTableDefinition);
288  if (isset($updateStatements['create_table']) && count($updateStatements['create_table']) > 0) {
289  $sqlHandler->performUpdateQueries($updateStatements['create_table'], $updateStatements['create_table']);
290  }
291  if (isset($updateStatements['add']) && count($updateStatements['add']) > 0) {
292  $sqlHandler->performUpdateQueries($updateStatements['add'], $updateStatements['add']);
293  }
294  if (isset($updateStatements['change']) && count($updateStatements['change']) > 0) {
295  $sqlHandler->performUpdateQueries($updateStatements['change'], $updateStatements['change']);
296  }
297  }
298 
306  protected function getDatabaseConnection() {
307  return $GLOBALS['TYPO3_DB'];
308  }
309 }
static getUserObj($classRef, $checkPrefix='', $silent=FALSE)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]