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