TYPO3 CMS  TYPO3_6-2
InitialDatabaseSchemaUpdate.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: Create tables and fields';
30  }
31 
38  public function checkForUpdate(&$description) {
39  $description = 'There are tables or fields in the database which need to be created.<br /><br />' .
40  'You have to run this update wizard before you can run any other update wizard to make sure all needed tables and fields are present.';
41 
42  $databaseDifferences = $this->getDatabaseDifferences();
43  $updateSuggestions = $this->schemaMigrationService->getUpdateSuggestions($databaseDifferences);
44 
45  return isset($updateSuggestions['create_table']) || isset($updateSuggestions['add']);
46  }
47 
54  public function getUserInput($inputPrefix) {
55  $result = '';
56 
57  $databaseDifferences = $this->getDatabaseDifferences();
58  $updateSuggestions = $this->schemaMigrationService->getUpdateSuggestions($databaseDifferences);
59 
60  if (isset($updateSuggestions['create_table'])) {
61  $list = '
62  <p>
63  Add the following tables:
64  </p>
65  <fieldset>
66  <ol class="t3-install-form-label-after">%s</ol>
67  </fieldset>';
68  $item = '
69  <li class="labelAfter">
70  <label><strong>%1$s</strong></label>
71  </li>';
72 
73  $items = array();
74  foreach ($databaseDifferences['extra'] as $tableName => $difference) {
75  if ($difference['whole_table'] == 1) {
76  $items[] = sprintf($item, $tableName);
77  }
78  }
79  $result .= sprintf($list, implode('', $items));
80  }
81 
82  if (isset($updateSuggestions['add'])) {
83  $fieldsList = '
84  <p>
85  Add the following fields to tables:
86  </p>
87  <fieldset>
88  <ol class="t3-install-form-label-after">%s</ol>
89  </fieldset>';
90  $keysList = '
91  <p>
92  Add the following keys to tables:
93  </p>
94  <fieldset>
95  <ol class="t3-install-form-label-after">%s</ol>
96  </fieldset>';
97  $item = '
98  <li class="labelAfter">
99  <label><strong>%1$s</strong>: %2$s</label>
100  </li>';
101 
102  $fieldItems = array();
103  $keyItems = array();
104  foreach ($databaseDifferences['extra'] as $tableName => $difference) {
105  if ($difference['whole_table'] != 1) {
106  if ($difference['fields']) {
107  $fieldNames = array();
108  foreach ($difference['fields'] as $fieldName => $sql) {
109  $fieldNames[] = $fieldName;
110  }
111  $fieldItems[] = sprintf($item, $tableName, implode(', ', $fieldNames));
112  }
113  if ($difference['keys']) {
114  $keyNames = array();
115  foreach ($difference['keys'] as $keyName => $sql) {
116  $keyNames[] = $keyName;
117  }
118  $keyItems[] = sprintf($item, $tableName, implode(', ', $keyNames));
119  }
120  }
121  }
122  if (!empty($fieldItems)) {
123  $result .= sprintf($fieldsList, implode('', $fieldItems));
124  }
125  if (!empty($keyItems)) {
126  $result .= sprintf($keysList, implode('', $keyItems));
127  }
128  }
129 
130  return $result;
131  }
132 
133 
141  public function performUpdate(array &$dbQueries, &$customMessages) {
142 
143  // First perform all add update statements to database
144  $databaseDifferences = $this->getDatabaseDifferences();
145  $updateStatements = $this->schemaMigrationService->getUpdateSuggestions($databaseDifferences);
146 
147  foreach ((array)$updateStatements['create_table'] as $query) {
148  $GLOBALS['TYPO3_DB']->admin_query($query);
149  $dbQueries[] = $query;
150  if ($GLOBALS['TYPO3_DB']->sql_error()) {
151  $customMessages = 'SQL-ERROR: ' . htmlspecialchars($GLOBALS['TYPO3_DB']->sql_error());
152  return FALSE;
153  }
154  }
155 
156  foreach ((array)$updateStatements['add'] as $query) {
157  $GLOBALS['TYPO3_DB']->admin_query($query);
158  $dbQueries[] = $query;
159  if ($GLOBALS['TYPO3_DB']->sql_error()) {
160  $customMessages = 'SQL-ERROR: ' . htmlspecialchars($GLOBALS['TYPO3_DB']->sql_error());
161  return FALSE;
162  }
163  }
164 
165  return TRUE;
166  }
167 }
$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'][]