TYPO3 CMS  TYPO3_6-2
FinalDatabaseSchemaUpdate.php
Go to the documentation of this file.
1 <?php
3 
23 
27  public function __construct() {
28  parent::__construct();
29  $this->title = 'Update database schema: Modify tables and fields';
30  }
31 
38  public function checkForUpdate(&$description) {
39  $contextService = $this->objectManager->get('TYPO3\\CMS\\Install\\Service\\ContextService');
40  $description = 'There are tables or fields in the database which need to be changed.<br /><br />' .
41  'This update wizard can be run only when there are no other update wizards left to make sure they have all needed fields unchanged.<br /><br />' .
42  'If you want to apply changes selectively, <a href="Install.php?install[action]=importantActions&amp;install[context]=' . $contextService->getContextString() . '&amp;install[controller]=tool">go to Database Analyzer</a>.';
43 
44  $databaseDifferences = $this->getDatabaseDifferences();
45  $updateSuggestions = $this->schemaMigrationService->getUpdateSuggestions($databaseDifferences);
46 
47  return isset($updateSuggestions['change']);
48  }
49 
56  public function getUserInput($inputPrefix) {
57  $result = '';
58 
59  $databaseDifferences = $this->getDatabaseDifferences();
60  $updateSuggestions = $this->schemaMigrationService->getUpdateSuggestions($databaseDifferences);
61 
62  if (!isset($updateSuggestions['change'])) {
63  return $result;
64  }
65 
66  $fieldsList = '
67  <p>
68  Change the following fields in tables:
69  </p>
70  <fieldset>
71  <ol class="t3-install-form-label-after">%s</ol>
72  </fieldset>';
73  $keysList = '
74  <p>
75  Change the following keys in tables:
76  </p>
77  <fieldset>
78  <ol class="t3-install-form-label-after">%s</ol>
79  </fieldset>';
80  $item = '
81  <li class="labelAfter">
82  <label><strong>%1$s</strong>: %2$s</label>
83  </li>';
84 
85  $fieldItems = array();
86  $keyItems = array();
87  foreach ($databaseDifferences['diff'] as $tableName => $difference) {
88  if ($difference['fields']) {
89  $fieldNames = array();
90  foreach ($difference['fields'] as $fieldName => $sql) {
91  $fieldNames[] = $fieldName;
92  }
93  $fieldItems[] = sprintf($item, $tableName, implode(', ', $fieldNames));
94  }
95  if ($difference['keys']) {
96  $keyNames = array();
97  foreach ($difference['keys'] as $keyName => $sql) {
98  $keyNames[] = $keyName;
99  }
100  $keyItems[] = sprintf($item, $tableName, implode(', ', $keyNames));
101  }
102  }
103  if (!empty($fieldItems)) {
104  $result .= sprintf($fieldsList, implode('', $fieldItems));
105  }
106  if (!empty($keyItems)) {
107  $result .= sprintf($keysList, implode('', $keyItems));
108  }
109 
110  return $result;
111  }
112 
113 
121  public function performUpdate(array &$dbQueries, &$customMessages) {
122  // First perform all add update statements to database
123  $databaseDifferences = $this->getDatabaseDifferences();
124  $updateStatements = $this->schemaMigrationService->getUpdateSuggestions($databaseDifferences);
125 
126  $customMessagesArray = array();
127  foreach ((array)$updateStatements['change'] as $query) {
128  $GLOBALS['TYPO3_DB']->admin_query($query);
129  $dbQueries[] = $query;
130  if ($GLOBALS['TYPO3_DB']->sql_error()) {
131  $customMessagesArray[] = 'SQL-ERROR: ' . htmlspecialchars($GLOBALS['TYPO3_DB']->sql_error());
132  }
133  }
134 
135  if (!empty($customMessagesArray)) {
136  $customMessages = 'Update process not fully processed. This can happen because of dependencies of table fields and ' .
137  'indexes. Please repeat this step! Following errors occurred:' . LF . LF . implode(LF, $customMessagesArray);
138  }
139 
140  return count($customMessagesArray) === 0;
141  }
142 }
$sql
Definition: server.php:82
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]