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