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