Fixed bug #16445: Performance Tuning: Replace exec_SELECTgetRows with exec_SELECTgetS...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_install.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Class to setup values in localconf.php and verify the TYPO3 DB tables/fields
29 *
30 * $Id$
31 *
32 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
33 */
34 /**
35 * [CLASS/FUNCTION INDEX of SCRIPT]
36 *
37 *
38 *
39 * 83: class t3lib_install
40 * 108: function t3lib_install()
41 *
42 * SECTION: Writing to localconf.php
43 * 132: function setValueInLocalconfFile(&$line_array, $variable, $value)
44 * 183: function writeToLocalconf_control($inlines='',$absFullPath='')
45 * 253: function checkForBadString($string)
46 * 266: function slashValueForSingleDashes($value)
47 *
48 * SECTION: SQL
49 * 291: function getFieldDefinitions_fileContent($fileContent)
50 * 359: function getFieldDefinitions_sqlContent_parseTypes(&$total)
51 * 406: function getFieldDefinitions_database()
52 * 450: function getDatabaseExtra($FDsrc, $FDcomp, $onlyTableList='')
53 * 496: function getUpdateSuggestions($diffArr,$keyList='extra,diff')
54 * 589: function assembleFieldDefinition($row)
55 * 611: function getStatementArray($sqlcode,$removeNonSQL=0,$query_regex='')
56 * 649: function getCreateTables($statements, $insertCountFlag=0)
57 * 683: function getTableInsertStatements($statements, $table)
58 * 704: function performUpdateQueries($arr,$keyArr)
59 * 720: function getListOfTables()
60 * 736: function generateUpdateDatabaseForm_checkboxes($arr,$label,$checked=1,$iconDis=0,$currentValue=array(),$cVfullMsg=0)
61 *
62 * TOTAL FUNCTIONS: 17
63 * (This index is automatically created/updated by the extension "extdeveval")
64 *
65 */
66
67
68 /**
69 * Class to setup values in localconf.php and verify the TYPO3 DB tables/fields
70 *
71 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
72 * @package TYPO3
73 * @subpackage t3lib
74 */
75 class t3lib_install {
76
77
78 // External, Static
79 var $updateIdentity = ''; // Set to string which identifies the script using this class.
80 var $deletedPrefixKey = 'zzz_deleted_'; // Prefix used for tables/fields when deleted/renamed.
81 var $dbUpdateCheckboxPrefix = 'TYPO3_INSTALL[database_update]'; // Prefix for checkbox fields when updating database.
82 var $localconf_addLinesOnly = 0; // If this is set, modifications to localconf.php is done by adding new lines to the array only. If unset, existing values are recognized and changed.
83 var $localconf_editPointToken = 'INSTALL SCRIPT EDIT POINT TOKEN - all lines after this points may be changed by the install script!'; // If set and addLinesOnly is disabled, lines will be change only if they are after this token (on a single line!) in the file
84 var $allowUpdateLocalConf = 0; // If true, this class will allow the user to update the localconf.php file. Is set true in the init.php file.
85 var $backPath = '../'; // Backpath (used for icons etc.)
86
87 var $multiplySize = 1; // Multiplier of SQL field size (for char, varchar and text fields)
88 var $character_sets = array(); // Caching output of $GLOBALS['TYPO3_DB']->admin_get_charsets()
89
90 // Internal, dynamic:
91 var $setLocalconf = 0; // Used to indicate that a value is change in the line-array of localconf and that it should be written.
92 var $messages = array(); // Used to set (error)messages from the executing functions like mail-sending, writing Localconf and such
93 var $touchedLine = 0; // updated with line in localconf.php file that was changed.
94
95
96 /**
97 * Constructor function
98 *
99 * @return void
100 */
101 function t3lib_install() {
102 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['multiplyDBfieldSize'] >= 1 && $GLOBALS['TYPO3_CONF_VARS']['SYS']['multiplyDBfieldSize'] <= 5) {
103 $this->multiplySize = (double) $GLOBALS['TYPO3_CONF_VARS']['SYS']['multiplyDBfieldSize'];
104 }
105 }
106
107
108 /**************************************
109 *
110 * Writing to localconf.php
111 *
112
113 **************************************/
114
115 /**
116 * This functions takes an array with lines from localconf.php, finds a variable and inserts the new value.
117 *
118 * @param array $line_array the localconf.php file exploded into an array by linebreaks. (see writeToLocalconf_control())
119 * @param string $variable The variable name to find and substitute. This string must match the first part of a trimmed line in the line-array. Matching is done backwards so the last appearing line will be substituted.
120 * @param string $value Is the value to be insert for the variable
121 * @param boolean $quoteValue Whether the given value should be quoted before being written
122 * @return void
123 * @see writeToLocalconf_control()
124 */
125 public function setValueInLocalconfFile(&$line_array, $variable, $value, $quoteValue = TRUE) {
126 if (!$this->checkForBadString($value)) {
127 return 0;
128 }
129
130 // Initialize:
131 $found = 0;
132 $this->touchedLine = '';
133 $commentKey = '## ';
134 $inArray = in_array($commentKey . $this->localconf_editPointToken, $line_array);
135 $tokenSet = ($this->localconf_editPointToken && !$inArray); // Flag is set if the token should be set but is not yet...
136 $stopAtToken = ($this->localconf_editPointToken && $inArray);
137 $comment = ' Modified or inserted by ' . $this->updateIdentity . '.';
138 $replace = array('["', '"]');
139 $search = array('[\'', '\']');
140 $varDoubleQuotes = str_replace($search, $replace, $variable);
141
142 // Search for variable name:
143 if (!$this->localconf_addLinesOnly && !$tokenSet) {
144 $line_array = array_reverse($line_array);
145 foreach ($line_array as $k => $v) {
146 $v2 = trim($v);
147 if ($stopAtToken && !strcmp($v2, $commentKey . $this->localconf_editPointToken)) {
148 break;
149 } // If stopAtToken and token found, break out of the loop..
150 if (!strcmp(substr($v2, 0, strlen($variable . ' ')), $variable . ' ')) {
151 $mainparts = explode($variable, $v, 2);
152 if (count($mainparts) == 2) { // should ALWAYS be....
153 $subparts = explode('//', $mainparts[1], 2);
154 if ($quoteValue) {
155 $value = '\'' . $this->slashValueForSingleDashes($value) . '\'';
156 }
157 $line_array[$k] = $mainparts[0] . $variable . " = " . $value . "; " . ('//' . $comment . str_replace($comment, '', $subparts[1]));
158 $this->touchedLine = count($line_array) - $k - 1;
159 $found = 1;
160 break;
161 }
162 } elseif (!strcmp(substr($v2, 0, strlen($varDoubleQuotes . ' ')), $varDoubleQuotes . ' ')) {
163 // Due to a bug in the update wizard (fixed in TYPO3 4.1.7) it is possible
164 // that $TYPO3_CONF_VARS['SYS']['compat_version'] was enclosed by "" (double
165 // quotes) instead of the expected '' (single quotes) when is was written to
166 // localconf.php. The following code was added to make sure that values with
167 // double quotes are updated, too.
168 $mainparts = explode($varDoubleQuotes, $v, 2);
169 if (count($mainparts) == 2) { // should ALWAYS be....
170 $subparts = explode('//', $mainparts[1], 2);
171 if ($quoteValue) {
172 $value = '\'' . $this->slashValueForSingleDashes($value) . '\'';
173 }
174 $line_array[$k] = $mainparts[0] . $variable . " = " . $value . "; " . ('//' . $comment . str_replace($comment, '', $subparts[1]));
175 $this->touchedLine = count($line_array) - $k - 1;
176 $found = 1;
177 break;
178 }
179 }
180 }
181 $line_array = array_reverse($line_array);
182 }
183 if (!$found) {
184 if ($tokenSet) {
185 $line_array[] = $commentKey . $this->localconf_editPointToken;
186 $line_array[] = '';
187 }
188 if ($quoteValue) {
189 $value = '\'' . $this->slashValueForSingleDashes($value) . '\'';
190 }
191 $line_array[] = $variable . " = " . $value . "; // " . $comment;
192 $this->touchedLine = -1;
193 }
194 if ($variable == '$typo_db_password') {
195 $this->messages[] = 'Updated ' . $variable;
196 } else {
197 $this->messages[] = $variable . " = " . htmlspecialchars($value);
198 }
199 $this->setLocalconf = 1;
200 }
201
202 /**
203 * Takes an array with lines from localconf.php, finds a variable and inserts the new array value.
204 *
205 * @param array $lines the localconf.php file exploded into an array by line breaks. {@see writeToLocalconf_control()}
206 * @param string $variable the variable name to find and substitute. This string must match the first part of a trimmed line in the line-array. Matching is done backwards so the last appearing line will be substituted.
207 * @param array $value value to be assigned to the variable
208 * @return void
209 * @see writeToLocalconf_control()
210 */
211 public function setArrayValueInLocalconfFile(array &$lines, $variable, array $value) {
212 $commentKey = '## ';
213 $inArray = in_array($commentKey . $this->localconf_editPointToken, $lines);
214 $tokenSet = $this->localconf_editPointToken && !$inArray; // Flag is set if the token should be set but is not yet
215 $stopAtToken = $this->localconf_editPointToken && $inArray;
216 $comment = 'Modified or inserted by ' . $this->updateIdentity . '.';
217 $format = "%s = %s;\t// " . $comment;
218
219 $insertPos = count($lines);
220 $startPos = 0;
221 if (!($this->localconf_addLinesOnly || $tokenSet)) {
222 for ($i = count($lines) - 1; $i > 0; $i--) {
223 $line = trim($lines[$i]);
224 if ($stopAtToken && t3lib_div::isFirstPartOfStr($line, $this->localconf_editPointToken)) {
225 break;
226 }
227 if (t3lib_div::isFirstPartOfStr($line, '?>')) {
228 $insertPos = $i;
229 }
230 if (t3lib_div::isFirstPartOfStr($line, $variable)) {
231 $startPos = $i;
232 break;
233 }
234 }
235 }
236 if ($startPos) {
237 $this->touchedLine = $startPos;
238 $endPos = $startPos;
239 for ($i = $startPos; $i < count($lines); $i++) {
240 $line = trim($lines[$i]);
241 if (t3lib_div::isFirstPartOfStr($line, ');')) {
242 $endPos = $i;
243 break;
244 }
245 }
246
247 $startLines = array_slice($lines, 0, $startPos);
248 $endLines = array_slice($lines, $endPos + 1);
249
250 $lines = $startLines;
251 $definition = $this->array_export($value);
252 $lines[] = sprintf($format, $variable, $definition);
253 foreach ($endLines as $line) {
254 $lines[] = $line;
255 }
256 } else {
257 $lines[$insertPos] = sprintf($format, $variable, $this->array_export($value));
258 $lines[] = '?>';
259 $this->touchedLine = -1;
260 }
261 }
262
263 /**
264 * Returns a parsable string representation of an array variable. This methods enhances
265 * standard method var_export from PHP to take TYPO3's CGL into account.
266 *
267 * @param array $variable
268 * @return string
269 */
270 protected function array_export(array $variable) {
271 $lines = explode("\n", var_export($variable, TRUE));
272 $out = 'array(';
273
274 for ($i = 1; $i < count($lines); $i++) {
275 $out .= "\n";
276 // Make the space-indented declaration tab-indented instead
277 while (substr($lines[$i], 0, 2) === ' ') {
278 $out .= "\t";
279 $lines[$i] = substr($lines[$i], 2);
280 }
281 $out .= $lines[$i];
282 // Array declaration should be next to the assignment and no space between
283 // "array" and its opening parenthesis should exist
284 if (preg_match('/\s=>\s$/', $lines[$i])) {
285 $out .= preg_replace('/^\s*array \(/', 'array(', $lines[$i + 1]);
286 $i++;
287 }
288 }
289
290 return $out;
291 }
292
293 /**
294 * Writes or returns lines from localconf.php
295 *
296 * @param array Array of lines to write back to localconf.php. Possibly
297 * @param string Absolute path of alternative file to use (Notice: this path is not validated in terms of being inside 'TYPO3 space')
298 * @return mixed If $inlines is not an array it will return an array with the lines from localconf.php. Otherwise it will return a status string, either "continue" (updated) or "nochange" (not updated)
299 * @see setValueInLocalconfFile()
300 */
301 function writeToLocalconf_control($inlines = '', $absFullPath = '') {
302 $tmpExt = '.TMP.php';
303 $writeToLocalconf_dat = array();
304 $writeToLocalconf_dat['file'] = $absFullPath ? $absFullPath : PATH_typo3conf . 'localconf.php';
305 $writeToLocalconf_dat['tmpfile'] = $writeToLocalconf_dat['file'] . $tmpExt;
306
307 // Checking write state of localconf.php:
308 if (!$this->allowUpdateLocalConf) {
309 throw new RuntimeException(
310 'TYPO3 Fatal Error: ->allowUpdateLocalConf flag in the install object is not set and therefore "localconf.php" cannot be altered.',
311 1270853915
312 );
313 }
314 if (!@is_writable($writeToLocalconf_dat['file'])) {
315 throw new RuntimeException(
316 'TYPO3 Fatal Error: ' . $writeToLocalconf_dat['file'] . ' is not writable!',
317 1270853916
318 );
319 }
320
321 // Splitting localconf.php file into lines:
322 $lines = explode(LF, str_replace(CR, '', trim(t3lib_div::getUrl($writeToLocalconf_dat['file']))));
323 $writeToLocalconf_dat['endLine'] = array_pop($lines); // Getting "? >" ending.
324
325 // Checking if "updated" line was set by this tool - if so remove old line.
326 $updatedLine = array_pop($lines);
327 $writeToLocalconf_dat['updatedText'] = '// Updated by ' . $this->updateIdentity . ' ';
328
329 if (!strstr($updatedLine, $writeToLocalconf_dat['updatedText'])) {
330 array_push($lines, $updatedLine);
331 }
332
333 if (is_array($inlines)) { // Setting a line and write:
334 // Setting configuration
335 $updatedLine = $writeToLocalconf_dat['updatedText'] . date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' H:i:s');
336 array_push($inlines, $updatedLine);
337 array_push($inlines, $writeToLocalconf_dat['endLine']);
338
339 if ($this->setLocalconf) {
340 $success = $this->writeToLocalconf($inlines, $absFullPath);
341
342 if ($success) {
343 return 'continue';
344 } else {
345 return 'nochange';
346 }
347 } else {
348 return 'nochange';
349 }
350 } else { // Return lines found in localconf.php
351 return $lines;
352 }
353 }
354
355 /**
356 * Writes lines to localconf.php.
357 *
358 * @param array Array of lines to write back to localconf.php
359 * @param string Absolute path of alternative file to use (Notice: this path is not validated in terms of being inside 'TYPO3 space')
360 * @return boolean TRUE if method succeeded, otherwise FALSE
361 */
362 public function writeToLocalconf(array $lines, $absFullPath = '') {
363 $tmpExt = '.TMP.php';
364 $writeToLocalconf_dat = array();
365 $writeToLocalconf_dat['file'] = $absFullPath ? $absFullPath : PATH_typo3conf . 'localconf.php';
366 $writeToLocalconf_dat['tmpfile'] = $writeToLocalconf_dat['file'] . $tmpExt;
367
368 // Checking write state of localconf.php:
369 if (!$this->allowUpdateLocalConf) {
370 throw new RuntimeException(
371 'TYPO3 Fatal Error: ->allowUpdateLocalConf flag in the install object is not set and therefore "localconf.php" cannot be altered.',
372 1270853915
373 );
374 }
375 if (!@is_writable($writeToLocalconf_dat['file'])) {
376 throw new RuntimeException(
377 'TYPO3 Fatal Error: ' . $writeToLocalconf_dat['file'] . ' is not writable!',
378 1270853916
379 );
380 }
381
382 $writeToLocalconf_dat['endLine'] = array_pop($lines); // Getting "? >" ending.
383 if (!strstr('?' . '>', $writeToLocalconf_dat['endLine'])) {
384 $lines[] = $writeToLocalconf_dat['endLine'];
385 $writeToLocalconf_dat['endLine'] = '?' . '>';
386 }
387 // Checking if "updated" line was set by this tool - if so remove old line.
388 $updatedLine = array_pop($lines);
389 $writeToLocalconf_dat['updatedText'] = '// Updated by ' . $this->updateIdentity . ' ';
390
391 if (!strstr($updatedLine, $writeToLocalconf_dat['updatedText'])) {
392 $lines[] = $updatedLine;
393 }
394
395 $updatedLine = $writeToLocalconf_dat['updatedText'] . date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' H:i:s');
396 $lines[] = $updatedLine;
397 $lines[] = $writeToLocalconf_dat['endLine'];
398
399 $success = FALSE;
400 if (!t3lib_div::writeFile($writeToLocalconf_dat['tmpfile'], implode(LF, $lines))) {
401 $msg = 'typo3conf/localconf.php' . $tmpExt . ' could not be written - maybe a write access problem?';
402 }
403 elseif (strcmp(t3lib_div::getUrl($writeToLocalconf_dat['tmpfile']), implode(LF, $lines))) {
404 @unlink($writeToLocalconf_dat['tmpfile']);
405 $msg = 'typo3conf/localconf.php' . $tmpExt . ' was NOT written properly (written content didn\'t match file content) - maybe a disk space problem?';
406 }
407 elseif (!@copy($writeToLocalconf_dat['tmpfile'], $writeToLocalconf_dat['file'])) {
408 $msg = 'typo3conf/localconf.php could not be replaced by typo3conf/localconf.php' . $tmpExt . ' - maybe a write access problem?';
409 }
410 else {
411 @unlink($writeToLocalconf_dat['tmpfile']);
412 $success = TRUE;
413 $msg = 'Configuration written to typo3conf/localconf.php';
414 }
415 $this->messages[] = $msg;
416
417 if (!$success) {
418 t3lib_div::sysLog($msg, 'Core', 3);
419 }
420
421 return $success;
422 }
423
424 /**
425 * Checking for linebreaks in the string
426 *
427 * @param string String to test
428 * @return boolean Returns TRUE if string is OK
429 * @see setValueInLocalconfFile()
430 */
431 function checkForBadString($string) {
432 return preg_match('/[' . LF . CR . ']/', $string) ? FALSE : TRUE;
433 }
434
435 /**
436 * Replaces ' with \' and \ with \\
437 *
438 * @param string Input value
439 * @return string Output value
440 * @see setValueInLocalconfFile()
441 */
442 function slashValueForSingleDashes($value) {
443 $value = str_replace("'.LF.'", '###INSTALL_TOOL_LINEBREAK###', $value);
444 $value = str_replace("'", "\'", str_replace('\\', '\\\\', $value));
445 $value = str_replace('###INSTALL_TOOL_LINEBREAK###', "'.LF.'", $value);
446
447 return $value;
448 }
449
450
451 /*************************************
452 *
453 * SQL
454 *
455 *************************************/
456
457 /**
458 * Reads the field definitions for the input SQL-file string
459 *
460 * @param string Should be a string read from an SQL-file made with 'mysqldump [database_name] -d'
461 * @return array Array with information about table.
462 */
463 function getFieldDefinitions_fileContent($fileContent) {
464 $lines = t3lib_div::trimExplode(LF, $fileContent, 1);
465 $table = '';
466 $total = array();
467
468 foreach ($lines as $value) {
469 if (substr($value, 0, 1) == '#') {
470 continue; // Ignore comments
471 }
472
473 if (!strlen($table)) {
474 $parts = t3lib_div::trimExplode(' ', $value, TRUE);
475 if (strtoupper($parts[0]) === 'CREATE' && strtoupper($parts[1]) === 'TABLE') {
476 $table = str_replace('`', '', $parts[2]);
477 if (TYPO3_OS == 'WIN') { // tablenames are always lowercase on windows!
478 $table = strtolower($table);
479 }
480 }
481 } else {
482 if (substr($value, 0, 1) == ')' && substr($value, -1) == ';') {
483 $ttype = array();
484 if (preg_match('/(ENGINE|TYPE)[ ]*=[ ]*([a-zA-Z]*)/', $value, $ttype)) {
485 $total[$table]['extra']['ENGINE'] = $ttype[2];
486 } // Otherwise, just do nothing: If table engine is not defined, just accept the system default.
487
488 // Set the collation, if specified
489 if (preg_match('/(COLLATE)[ ]*=[ ]*([a-zA-z0-9_-]+)/', $value, $tcollation)) {
490 $total[$table]['extra']['COLLATE'] = $tcollation[2];
491 } else {
492 // Otherwise, get the CHARACTER SET and try to find the default collation for it as returned by "SHOW CHARACTER SET" query (for details, see http://dev.mysql.com/doc/refman/5.1/en/charset-table.html)
493 if (preg_match('/(CHARSET|CHARACTER SET)[ ]*=[ ]*([a-zA-z0-9_-]+)/', $value, $tcharset)) { // Note: Keywords "DEFAULT CHARSET" and "CHARSET" are the same, so "DEFAULT" can just be ignored
494 $charset = $tcharset[2];
495 } else {
496 $charset = $GLOBALS['TYPO3_DB']->default_charset; // Fallback to default charset
497 }
498 $total[$table]['extra']['COLLATE'] = $this->getCollationForCharset($charset);
499 }
500
501 $table = ''; // Remove table marker and start looking for the next "CREATE TABLE" statement
502 } else {
503 $lineV = preg_replace('/,$/', '', $value); // Strip trailing commas
504 $lineV = str_replace('`', '', $lineV);
505 $lineV = str_replace(' ', ' ', $lineV); // Remove double blanks
506
507 $parts = explode(' ', $lineV, 2);
508 if (!preg_match('/(PRIMARY|UNIQUE|FULLTEXT|INDEX|KEY)/', $parts[0])) { // Field definition
509
510 // Make sure there is no default value when auto_increment is set
511 if (stristr($parts[1], 'auto_increment')) {
512 $parts[1] = preg_replace('/ default \'0\'/i', '', $parts[1]);
513 }
514 // "default" is always lower-case
515 if (stristr($parts[1], ' DEFAULT ')) {
516 $parts[1] = str_ireplace(' DEFAULT ', ' default ', $parts[1]);
517 }
518
519 // Change order of "default" and "null" statements
520 $parts[1] = preg_replace('/(.*) (default .*) (NOT NULL)/', '$1 $3 $2', $parts[1]);
521 $parts[1] = preg_replace('/(.*) (default .*) (NULL)/', '$1 $3 $2', $parts[1]);
522
523 $key = $parts[0];
524 $total[$table]['fields'][$key] = $parts[1];
525
526 } else { // Key definition
527 $search = array('/UNIQUE (INDEX|KEY)/', '/FULLTEXT (INDEX|KEY)/', '/INDEX/');
528 $replace = array('UNIQUE', 'FULLTEXT', 'KEY');
529 $lineV = preg_replace($search, $replace, $lineV);
530
531 if (preg_match('/PRIMARY|UNIQUE|FULLTEXT/', $parts[0])) {
532 $parts[1] = preg_replace('/^(KEY|INDEX) /', '', $parts[1]);
533 }
534
535 $newParts = explode(' ', $parts[1], 2);
536 $key = $parts[0] == 'PRIMARY' ? $parts[0] : $newParts[0];
537
538 $total[$table]['keys'][$key] = $lineV;
539
540 // This is a protection against doing something stupid: Only allow clearing of cache_* and index_* tables.
541 if (preg_match('/^(cache|index)_/', $table)) {
542 // Suggest to truncate (clear) this table
543 $total[$table]['extra']['CLEAR'] = 1;
544 }
545 }
546 }
547 }
548 }
549
550 $this->getFieldDefinitions_sqlContent_parseTypes($total);
551 return $total;
552 }
553
554 /**
555 * Multiplies varchars/tinytext fields in size according to $this->multiplySize
556 * Useful if you want to use UTF-8 in the database and needs to extend the field sizes in the database so UTF-8 chars are not discarded. For most charsets available as single byte sets, multiplication with 2 should be enough. For chinese, use 3.
557 *
558 * @param array Total array (from getFieldDefinitions_fileContent())
559 * @return void
560 * @access private
561 * @see getFieldDefinitions_fileContent()
562 */
563 function getFieldDefinitions_sqlContent_parseTypes(&$total) {
564
565 $mSize = (double) $this->multiplySize;
566 if ($mSize > 1) {
567
568 // Init SQL parser:
569 $sqlParser = t3lib_div::makeInstance('t3lib_sqlparser');
570 foreach ($total as $table => $cfg) {
571 if (is_array($cfg['fields'])) {
572 foreach ($cfg['fields'] as $fN => $fType) {
573 $orig_fType = $fType;
574 $fInfo = $sqlParser->parseFieldDef($fType);
575
576 switch ($fInfo['fieldType']) {
577 case 'char':
578 case 'varchar':
579 $newSize = round($fInfo['value'] * $mSize);
580
581 if ($newSize <= 255) {
582 $fInfo['value'] = $newSize;
583 } else {
584 $fInfo = array(
585 'fieldType' => 'text',
586 'featureIndex' => array(
587 'NOTNULL' => array(
588 'keyword' => 'NOT NULL'
589 )
590 )
591 );
592 // Change key definition if necessary (must use "prefix" on TEXT columns)
593 if (is_array($cfg['keys'])) {
594 foreach ($cfg['keys'] as $kN => $kType) {
595 $match = array();
596 preg_match('/^([^(]*)\(([^)]+)\)(.*)/', $kType, $match);
597 $keys = array();
598 foreach (t3lib_div::trimExplode(',', $match[2]) as $kfN) {
599 if ($fN == $kfN) {
600 $kfN .= '(' . $newSize . ')';
601 }
602 $keys[] = $kfN;
603 }
604 $total[$table]['keys'][$kN] = $match[1] . '(' . implode(',', $keys) . ')' . $match[3];
605 }
606 }
607 }
608 break;
609 case 'tinytext':
610 $fInfo['fieldType'] = 'text';
611 break;
612 }
613
614 $total[$table]['fields'][$fN] = $sqlParser->compileFieldCfg($fInfo);
615 if ($sqlParser->parse_error) {
616 throw new RuntimeException(
617 'TYPO3 Fatal Error: ' . $sqlParser->parse_error,
618 1270853961
619 );
620 }
621 }
622 }
623 }
624 }
625 }
626
627 /**
628 * Look up the default collation for specified character set based on "SHOW CHARACTER SET" output
629 *
630 * @param string Character set
631 * @return string Corresponding default collation
632 */
633 function getCollationForCharset($charset) {
634 // Load character sets, if not cached already
635 if (!count($this->character_sets)) {
636 if (method_exists($GLOBALS['TYPO3_DB'], 'admin_get_charsets')) {
637 $this->character_sets = $GLOBALS['TYPO3_DB']->admin_get_charsets();
638 } else {
639 $this->character_sets[$charset] = array(); // Add empty element to avoid that the check will be repeated
640 }
641 }
642
643 $collation = '';
644 if (isset($this->character_sets[$charset]['Default collation'])) {
645 $collation = $this->character_sets[$charset]['Default collation'];
646 }
647
648 return $collation;
649 }
650
651 /**
652 * Reads the field definitions for the current database
653 *
654 * @return array Array with information about table.
655 */
656 function getFieldDefinitions_database() {
657 $total = array();
658 $tempKeys = array();
659 $tempKeysPrefix = array();
660
661 $GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db);
662 echo $GLOBALS['TYPO3_DB']->sql_error();
663
664 $tables = $GLOBALS['TYPO3_DB']->admin_get_tables(TYPO3_db);
665 foreach ($tables as $tableName => $tableStatus) {
666
667 // Fields:
668 $fieldInformation = $GLOBALS['TYPO3_DB']->admin_get_fields($tableName);
669 foreach ($fieldInformation as $fN => $fieldRow) {
670 $total[$tableName]['fields'][$fN] = $this->assembleFieldDefinition($fieldRow);
671 }
672
673 // Keys:
674 $keyInformation = $GLOBALS['TYPO3_DB']->admin_get_keys($tableName);
675
676 foreach ($keyInformation as $keyRow) {
677 $keyName = $keyRow['Key_name'];
678 $colName = $keyRow['Column_name'];
679 if ($keyRow['Sub_part']) {
680 $colName .= '(' . $keyRow['Sub_part'] . ')';
681 }
682 $tempKeys[$tableName][$keyName][$keyRow['Seq_in_index']] = $colName;
683 if ($keyName == 'PRIMARY') {
684 $prefix = 'PRIMARY KEY';
685 } else {
686 if ($keyRow['Index_type'] == 'FULLTEXT') {
687 $prefix = 'FULLTEXT';
688 } elseif ($keyRow['Non_unique']) {
689 $prefix = 'KEY';
690 } else {
691 $prefix = 'UNIQUE';
692 }
693 $prefix .= ' ' . $keyName;
694 }
695 $tempKeysPrefix[$tableName][$keyName] = $prefix;
696 }
697
698 // Table status (storage engine, collaction, etc.)
699 if (is_array($tableStatus)) {
700 $tableExtraFields = array(
701 'Engine' => 'ENGINE',
702 'Collation' => 'COLLATE',
703 );
704
705 foreach ($tableExtraFields as $mysqlKey => $internalKey) {
706 if (isset($tableStatus[$mysqlKey])) {
707 $total[$tableName]['extra'][$internalKey] = $tableStatus[$mysqlKey];
708 }
709 }
710 }
711 }
712
713 // Compile key information:
714 if (count($tempKeys)) {
715 foreach ($tempKeys as $table => $keyInf) {
716 foreach ($keyInf as $kName => $index) {
717 ksort($index);
718 $total[$table]['keys'][$kName] = $tempKeysPrefix[$table][$kName] . ' (' . implode(',', $index) . ')';
719 }
720 }
721 }
722
723 return $total;
724 }
725
726 /**
727 * Compares two arrays with field information and returns information about fields that are MISSING and fields that have CHANGED.
728 * FDsrc and FDcomp can be switched if you want the list of stuff to remove rather than update.
729 *
730 * @param array Field definitions, source (from getFieldDefinitions_fileContent())
731 * @param array Field definitions, comparison. (from getFieldDefinitions_database())
732 * @param string Table names (in list) which is the ONLY one observed.
733 * @param boolean If set, this function ignores NOT NULL statements of the SQL file field definition when comparing current field definition from database with field definition from SQL file. This way, NOT NULL statements will be executed when the field is initially created, but the SQL parser will never complain about missing NOT NULL statements afterwards.
734 * @return array Returns an array with 1) all elements from $FDsrc that is not in $FDcomp (in key 'extra') and 2) all elements from $FDsrc that is different from the ones in $FDcomp
735 */
736 function getDatabaseExtra($FDsrc, $FDcomp, $onlyTableList = '', $ignoreNotNullWhenComparing = TRUE) {
737 $extraArr = array();
738 $diffArr = array();
739
740 if (is_array($FDsrc)) {
741 foreach ($FDsrc as $table => $info) {
742 if (!strlen($onlyTableList) || t3lib_div::inList($onlyTableList, $table)) {
743 if (!isset($FDcomp[$table])) {
744 $extraArr[$table] = $info; // If the table was not in the FDcomp-array, the result array is loaded with that table.
745 $extraArr[$table]['whole_table'] = 1;
746 } else {
747 $keyTypes = explode(',', 'extra,fields,keys');
748 foreach ($keyTypes as $theKey) {
749 if (is_array($info[$theKey])) {
750 foreach ($info[$theKey] as $fieldN => $fieldC) {
751 $fieldN = str_replace('`', '', $fieldN);
752 if ($fieldN == 'COLLATE') {
753 continue; // TODO: collation support is currently disabled (needs more testing)
754 }
755
756 if (!isset($FDcomp[$table][$theKey][$fieldN])) {
757 $extraArr[$table][$theKey][$fieldN] = $fieldC;
758 } else {
759 $fieldC = trim($fieldC);
760 if ($ignoreNotNullWhenComparing) {
761 $fieldC = str_replace(' NOT NULL', '', $fieldC);
762 $FDcomp[$table][$theKey][$fieldN] = str_replace(' NOT NULL', '', $FDcomp[$table][$theKey][$fieldN]);
763 }
764 if ($fieldC !== $FDcomp[$table][$theKey][$fieldN]) {
765 $diffArr[$table][$theKey][$fieldN] = $fieldC;
766 $diffArr_cur[$table][$theKey][$fieldN] = $FDcomp[$table][$theKey][$fieldN];
767 }
768 }
769 }
770 }
771 }
772 }
773 }
774 }
775 }
776
777 $output = array(
778 'extra' => $extraArr,
779 'diff' => $diffArr,
780 'diff_currentValues' => $diffArr_cur
781 );
782
783 return $output;
784 }
785
786 /**
787 * Returns an array with SQL-statements that is needed to update according to the diff-array
788 *
789 * @param array Array with differences of current and needed DB settings. (from getDatabaseExtra())
790 * @param string List of fields in diff array to take notice of.
791 * @return array Array of SQL statements (organized in keys depending on type)
792 */
793 function getUpdateSuggestions($diffArr, $keyList = 'extra,diff') {
794 $statements = array();
795 $deletedPrefixKey = $this->deletedPrefixKey;
796 $remove = 0;
797 if ($keyList == 'remove') {
798 $remove = 1;
799 $keyList = 'extra';
800 }
801 $keyList = explode(',', $keyList);
802 foreach ($keyList as $theKey) {
803 if (is_array($diffArr[$theKey])) {
804 foreach ($diffArr[$theKey] as $table => $info) {
805 $whole_table = array();
806 if (is_array($info['fields'])) {
807 foreach ($info['fields'] as $fN => $fV) {
808 if ($info['whole_table']) {
809 $whole_table[] = $fN . ' ' . $fV;
810 } else {
811 // Special case to work around MySQL problems when adding auto_increment fields:
812 if (stristr($fV, 'auto_increment')) {
813 // The field can only be set "auto_increment" if there exists a PRIMARY key of that field already.
814 // The check does not look up which field is primary but just assumes it must be the field with the auto_increment value...
815 if (isset($diffArr['extra'][$table]['keys']['PRIMARY'])) {
816 // Remove "auto_increment" from the statement - it will be suggested in a 2nd step after the primary key was created
817 $fV = str_replace(' auto_increment', '', $fV);
818 } else {
819 // In the next step, attempt to clear the table once again (2 = force)
820 $info['extra']['CLEAR'] = 2;
821 }
822 }
823 if ($theKey == 'extra') {
824 if ($remove) {
825 if (substr($fN, 0, strlen($deletedPrefixKey)) != $deletedPrefixKey) {
826 $statement = 'ALTER TABLE ' . $table . ' CHANGE ' . $fN . ' ' . $deletedPrefixKey . $fN . ' ' . $fV . ';';
827 $statements['change'][md5($statement)] = $statement;
828 } else {
829 $statement = 'ALTER TABLE ' . $table . ' DROP ' . $fN . ';';
830 $statements['drop'][md5($statement)] = $statement;
831 }
832 } else {
833 $statement = 'ALTER TABLE ' . $table . ' ADD ' . $fN . ' ' . $fV . ';';
834 $statements['add'][md5($statement)] = $statement;
835 }
836 } elseif ($theKey == 'diff') {
837 $statement = 'ALTER TABLE ' . $table . ' CHANGE ' . $fN . ' ' . $fN . ' ' . $fV . ';';
838 $statements['change'][md5($statement)] = $statement;
839 $statements['change_currentValue'][md5($statement)] = $diffArr['diff_currentValues'][$table]['fields'][$fN];
840 }
841 }
842 }
843 }
844 if (is_array($info['keys'])) {
845 foreach ($info['keys'] as $fN => $fV) {
846 if ($info['whole_table']) {
847 $whole_table[] = $fV;
848 } else {
849 if ($theKey == 'extra') {
850 if ($remove) {
851 $statement = 'ALTER TABLE ' . $table . ($fN == 'PRIMARY' ? ' DROP PRIMARY KEY' : ' DROP KEY ' . $fN) . ';';
852 $statements['drop'][md5($statement)] = $statement;
853 } else {
854 $statement = 'ALTER TABLE ' . $table . ' ADD ' . $fV . ';';
855 $statements['add'][md5($statement)] = $statement;
856 }
857 } elseif ($theKey == 'diff') {
858 $statement = 'ALTER TABLE ' . $table . ($fN == 'PRIMARY' ? ' DROP PRIMARY KEY' : ' DROP KEY ' . $fN) . ';';
859 $statements['change'][md5($statement)] = $statement;
860 $statement = 'ALTER TABLE ' . $table . ' ADD ' . $fV . ';';
861 $statements['change'][md5($statement)] = $statement;
862 }
863 }
864 }
865 }
866 if (is_array($info['extra'])) {
867 $extras = array();
868 $extras_currentValue = array();
869 $clear_table = FALSE;
870
871 foreach ($info['extra'] as $fN => $fV) {
872
873 // Only consider statements which are missing in the database but don't remove existing properties
874 if (!$remove) {
875 if (!$info['whole_table']) { // If the whole table is created at once, we take care of this later by imploding all elements of $info['extra']
876 if ($fN == 'CLEAR') {
877 // Truncate table must happen later, not now
878 // Valid values for CLEAR: 1=only clear if keys are missing, 2=clear anyway (force)
879 if (count($info['keys']) || $fV == 2) {
880 $clear_table = TRUE;
881 }
882 continue;
883 } else {
884 $extras[] = $fN . '=' . $fV;
885 $extras_currentValue[] = $fN . '=' . $diffArr['diff_currentValues'][$table]['extra'][$fN];
886 }
887 }
888 }
889 }
890 if ($clear_table) {
891 $statement = 'TRUNCATE TABLE ' . $table . ';';
892 $statements['clear_table'][md5($statement)] = $statement;
893 }
894 if (count($extras)) {
895 $statement = 'ALTER TABLE ' . $table . ' ' . implode(' ', $extras) . ';';
896 $statements['change'][md5($statement)] = $statement;
897 $statements['change_currentValue'][md5($statement)] = implode(' ', $extras_currentValue);
898 }
899 }
900 if ($info['whole_table']) {
901 if ($remove) {
902 if (substr($table, 0, strlen($deletedPrefixKey)) != $deletedPrefixKey) {
903 $statement = 'ALTER TABLE ' . $table . ' RENAME ' . $deletedPrefixKey . $table . ';';
904 $statements['change_table'][md5($statement)] = $statement;
905 } else {
906 $statement = 'DROP TABLE ' . $table . ';';
907 $statements['drop_table'][md5($statement)] = $statement;
908 }
909 // count:
910 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', $table);
911 $statements['tables_count'][md5($statement)] = $count ? 'Records in table: ' . $count : '';
912 } else {
913 $statement = 'CREATE TABLE ' . $table . " (\n" . implode(",\n", $whole_table) . "\n)";
914 if ($info['extra']) {
915 foreach ($info['extra'] as $k => $v) {
916 if ($k == 'COLLATE' || $k == 'CLEAR') {
917 continue; // Skip these special statements. TODO: collation support is currently disabled (needs more testing)
918 }
919 $statement .= ' ' . $k . '=' . $v; // Add extra attributes like ENGINE, CHARSET, etc.
920 }
921 }
922 $statement .= ';';
923 $statements['create_table'][md5($statement)] = $statement;
924 }
925 }
926 }
927 }
928 }
929
930 return $statements;
931 }
932
933 /**
934 * Converts a result row with field information into the SQL field definition string
935 *
936 * @param array MySQL result row
937 * @return string Field definition
938 */
939 function assembleFieldDefinition($row) {
940 $field = array($row['Type']);
941
942 if ($row['Null'] == 'NO') {
943 $field[] = 'NOT NULL';
944 }
945 if (!strstr($row['Type'], 'blob') && !strstr($row['Type'], 'text')) {
946 // Add a default value if the field is not auto-incremented (these fields never have a default definition)
947 if (!stristr($row['Extra'], 'auto_increment')) {
948 $field[] = 'default \'' . addslashes($row['Default']) . '\'';
949 }
950 }
951 if ($row['Extra']) {
952 $field[] = $row['Extra'];
953 }
954
955 return implode(' ', $field);
956 }
957
958 /**
959 * Returns an array where every entry is a single SQL-statement. Input must be formatted like an ordinary MySQL-dump files.
960 *
961 * @param string The SQL-file content. Provided that 1) every query in the input is ended with ';' and that a line in the file contains only one query or a part of a query.
962 * @param boolean If set, non-SQL content (like comments and blank lines) is not included in the final output
963 * @param string Regex to filter SQL lines to include
964 * @return array Array of SQL statements
965 */
966 function getStatementArray($sqlcode, $removeNonSQL = 0, $query_regex = '') {
967 $sqlcodeArr = explode(LF, $sqlcode);
968
969 // Based on the assumption that the sql-dump has
970 $statementArray = array();
971 $statementArrayPointer = 0;
972
973 foreach ($sqlcodeArr as $line => $lineContent) {
974 $is_set = 0;
975
976 // auto_increment fields cannot have a default value!
977 if (stristr($lineContent, 'auto_increment')) {
978 $lineContent = preg_replace('/ default \'0\'/i', '', $lineContent);
979 }
980
981 if (!$removeNonSQL || (strcmp(trim($lineContent), '') && substr(trim($lineContent), 0, 1) != '#' && substr(trim($lineContent), 0, 2) != '--')) { // '--' is seen as mysqldump comments from server version 3.23.49
982 $statementArray[$statementArrayPointer] .= $lineContent;
983 $is_set = 1;
984 }
985 if (substr(trim($lineContent), -1) == ';') {
986 if (isset($statementArray[$statementArrayPointer])) {
987 if (!trim($statementArray[$statementArrayPointer]) || ($query_regex && !preg_match('/' . $query_regex . '/i', trim($statementArray[$statementArrayPointer])))) {
988 unset($statementArray[$statementArrayPointer]);
989 }
990 }
991 $statementArrayPointer++;
992
993 } elseif ($is_set) {
994 $statementArray[$statementArrayPointer] .= LF;
995 }
996 }
997
998 return $statementArray;
999 }
1000
1001 /**
1002 * Returns tables to create and how many records in each
1003 *
1004 * @param array Array of SQL statements to analyse.
1005 * @param boolean If set, will count number of INSERT INTO statements following that table definition
1006 * @return array Array with table definitions in index 0 and count in index 1
1007 */
1008 function getCreateTables($statements, $insertCountFlag = 0) {
1009 $crTables = array();
1010 $insertCount = array();
1011 foreach ($statements as $line => $lineContent) {
1012 $reg = array();
1013 if (preg_match('/^create[[:space:]]*table[[:space:]]*[`]?([[:alnum:]_]*)[`]?/i', substr($lineContent, 0, 100), $reg)) {
1014 $table = trim($reg[1]);
1015 if ($table) {
1016 // table names are always lowercase on Windows!
1017 if (TYPO3_OS == 'WIN') {
1018 $table = strtolower($table);
1019 }
1020 $sqlLines = explode(LF, $lineContent);
1021 foreach ($sqlLines as $k => $v) {
1022 if (stristr($v, 'auto_increment')) {
1023 $sqlLines[$k] = preg_replace('/ default \'0\'/i', '', $v);
1024 }
1025 }
1026 $lineContent = implode(LF, $sqlLines);
1027 $crTables[$table] = $lineContent;
1028 }
1029 } elseif ($insertCountFlag && preg_match('/^insert[[:space:]]*into[[:space:]]*[`]?([[:alnum:]_]*)[`]?/i', substr($lineContent, 0, 100), $reg)) {
1030 $nTable = trim($reg[1]);
1031 $insertCount[$nTable]++;
1032 }
1033 }
1034
1035 return array($crTables, $insertCount);
1036 }
1037
1038 /**
1039 * Extracts all insert statements from $statement array where content is inserted into $table
1040 *
1041 * @param array Array of SQL statements
1042 * @param string Table name
1043 * @return array Array of INSERT INTO statements where table match $table
1044 */
1045 function getTableInsertStatements($statements, $table) {
1046 $outStatements = array();
1047 foreach ($statements as $line => $lineContent) {
1048 $reg = array();
1049 if (preg_match('/^insert[[:space:]]*into[[:space:]]*[`]?([[:alnum:]_]*)[`]?/i', substr($lineContent, 0, 100), $reg)) {
1050 $nTable = trim($reg[1]);
1051 if ($nTable && !strcmp($table, $nTable)) {
1052 $outStatements[] = $lineContent;
1053 }
1054 }
1055 }
1056 return $outStatements;
1057 }
1058
1059 /**
1060 * Performs the queries passed from the input array.
1061 *
1062 * @param array Array of SQL queries to execute.
1063 * @param array Array with keys that must match keys in $arr. Only where a key in this array is set and true will the query be executed (meant to be passed from a form checkbox)
1064 * @return mixed Array with error message from database if any occured. Otherwise true if everything was executed successfully.
1065 */
1066 function performUpdateQueries($arr, $keyArr) {
1067 $result = array();
1068 if (is_array($arr)) {
1069 foreach ($arr as $key => $string) {
1070 if (isset($keyArr[$key]) && $keyArr[$key]) {
1071 $res = $GLOBALS['TYPO3_DB']->admin_query($string);
1072 if ($res === FALSE) {
1073 $result[$key] = $GLOBALS['TYPO3_DB']->sql_error();
1074 } elseif (is_resource($res)) {
1075 $GLOBALS['TYPO3_DB']->sql_free_result($res);
1076 }
1077 }
1078 }
1079 }
1080 if (count($result) > 0) {
1081 return $result;
1082 } else {
1083 return TRUE;
1084 }
1085 }
1086
1087 /**
1088 * Returns list of tables in the database
1089 *
1090 * @return array List of tables.
1091 * @see t3lib_db::admin_get_tables()
1092 */
1093 function getListOfTables() {
1094 $whichTables = $GLOBALS['TYPO3_DB']->admin_get_tables(TYPO3_db);
1095 foreach ($whichTables as $key => &$value) {
1096 $value = $key;
1097 }
1098 return $whichTables;
1099 }
1100
1101 /**
1102 * Creates a table which checkboxes for updating database.
1103 *
1104 * @param array Array of statements (key / value pairs where key is used for the checkboxes)
1105 * @param string Label for the table.
1106 * @param boolean If set, then checkboxes are set by default.
1107 * @param boolean If set, then icons are shown.
1108 * @param array Array of "current values" for each key/value pair in $arr. Shown if given.
1109 * @param boolean If set, will show the prefix "Current value" if $currentValue is given.
1110 * @return string HTML table with checkboxes for update. Must be wrapped in a form.
1111 */
1112 function generateUpdateDatabaseForm_checkboxes($arr, $label, $checked = 1, $iconDis = 0, $currentValue = array(), $cVfullMsg = 0) {
1113 $out = array();
1114 if (is_array($arr)) {
1115 $tableId = uniqid('table');
1116 if (count($arr) > 1) {
1117 $out[] = '
1118 <tr class="update-db-fields-batch">
1119 <td valign="top">
1120 <input type="checkbox" id="' . $tableId . '-checkbox"' . ($checked ? ' checked="checked"' : '') . '
1121 onclick="$(\'' . $tableId . '\').select(\'input[type=checkbox]\').invoke(\'setValue\', $(this).checked);" />
1122 </td>
1123 <td nowrap="nowrap"><label for="' . $tableId . '-checkbox" style="cursor:pointer"><strong>select/deselect all</strong></label></td>
1124 </tr>';
1125 }
1126 foreach ($arr as $key => $string) {
1127 $ico = '';
1128 $warnings = array();
1129
1130 if ($iconDis) {
1131 if (preg_match('/^TRUNCATE/i', $string)) {
1132 $ico .= '<img src="' . $this->backPath . 'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong> </strong>';
1133 $warnings['clear_table_info'] = 'Clearing the table is sometimes neccessary when adding new keys. In case of cache_* tables this should not hurt at all. However, use it with care.';
1134 } elseif (stristr($string, ' user_')) {
1135 $ico .= '<img src="' . $this->backPath . 'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(USER) </strong>';
1136 } elseif (stristr($string, ' app_')) {
1137 $ico .= '<img src="' . $this->backPath . 'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(APP) </strong>';
1138 } elseif (stristr($string, ' ttx_') || stristr($string, ' tx_')) {
1139 $ico .= '<img src="' . $this->backPath . 'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(EXT) </strong>';
1140 }
1141 }
1142 $out[] = '
1143 <tr>
1144 <td valign="top"><input type="checkbox" id="db-' . $key . '" name="' . $this->dbUpdateCheckboxPrefix . '[' . $key . ']" value="1"' . ($checked ? ' checked="checked"' : '') . ' /></td>
1145 <td nowrap="nowrap"><label for="db-' . $key . '">' . nl2br($ico . htmlspecialchars($string)) . '</label></td>
1146 </tr>';
1147 if (isset($currentValue[$key])) {
1148 $out[] = '
1149 <tr>
1150 <td valign="top"></td>
1151 <td nowrap="nowrap" style="color:#666666;">' . nl2br((!$cVfullMsg ? "Current value: " : "") . '<em>' . $currentValue[$key] . '</em>') . '</td>
1152 </tr>';
1153 }
1154 }
1155 if (count($warnings)) {
1156 $out[] = '
1157 <tr>
1158 <td valign="top"></td>
1159 <td style="color:#666666;"><em>' . implode('<br />', $warnings) . '</em></td>
1160 </tr>';
1161 }
1162
1163 // Compile rows:
1164 $content = '
1165 <!-- Update database fields / tables -->
1166 <h3>' . $label . '</h3>
1167 <table border="0" cellpadding="2" cellspacing="2" id="' . $tableId . '" class="update-db-fields">' . implode('', $out) . '
1168 </table>';
1169 }
1170
1171 return $content;
1172 }
1173
1174 /**
1175 * Reads the field definitions for the input SQL-file string
1176 *
1177 * @param string Should be a string read from an SQL-file made with 'mysqldump [database_name] -d'
1178 * @return array Array with information about table.
1179 * @deprecated since TYPO3 4.2, this function will be removed in TYPO3 4.6, use ->getFieldDefinitions_fileContent() instead!
1180 */
1181 function getFieldDefinitions_sqlContent($fileContent) {
1182 t3lib_div::logDeprecatedFunction();
1183
1184 return $this->getFieldDefinitions_fileContent($fileContent);
1185 }
1186 }
1187
1188 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_install.php']) {
1189 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_install.php']);
1190 }
1191
1192 ?>