[BUGFIX] Prevent compression of scripts that use ajax.php
[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
34 /**
35 * Class to setup values in localconf.php and verify the TYPO3 DB tables/fields
36 *
37 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
38 * @package TYPO3
39 * @subpackage t3lib
40 */
41 class t3lib_install {
42
43
44 // External, Static
45 var $updateIdentity = ''; // Set to string which identifies the script using this class.
46
47 var $dbUpdateCheckboxPrefix = 'TYPO3_INSTALL[database_update]'; // Prefix for checkbox fields when updating database.
48 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.
49 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
50 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.
51 var $backPath = '../'; // Backpath (used for icons etc.)
52
53 // Internal, dynamic:
54 var $setLocalconf = 0; // Used to indicate that a value is change in the line-array of localconf and that it should be written.
55 var $messages = array(); // Used to set (error)messages from the executing functions like mail-sending, writing Localconf and such
56 var $touchedLine = 0; // updated with line in localconf.php file that was changed.
57
58 /**
59 * @var t3lib_install_Sql Instance of SQL handler
60 */
61 protected $sqlHandler = NULL;
62
63 /**
64 * Constructor function
65 */
66 public function __construct() {
67 $this->sqlHandler = t3lib_div::makeInstance('t3lib_install_Sql');
68 }
69
70 /**
71 * Compatibility constructor.
72 *
73 * @deprecated since TYPO3 4.6 and will be removed in TYPO3 4.8. Use __construct() instead.
74 */
75 public function t3lib_install() {
76 t3lib_div::logDeprecatedFunction();
77 // Note: we cannot call $this->__construct() here because it would call the derived class constructor and cause recursion
78 // This code uses official PHP behavior (http://www.php.net/manual/en/language.oop5.basic.php) when $this in the
79 // statically called non-static method inherits $this from the caller's scope.
80 t3lib_install::__construct();
81 }
82
83
84 /**************************************
85 *
86 * Writing to localconf.php
87 *
88
89 **************************************/
90
91 /**
92 * This functions takes an array with lines from localconf.php, finds a variable and inserts the new value.
93 *
94 * @param array $line_array the localconf.php file exploded into an array by linebreaks. (see writeToLocalconf_control())
95 * @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.
96 * @param string $value Is the value to be insert for the variable
97 * @param boolean $quoteValue Whether the given value should be quoted before being written
98 * @return void
99 * @see writeToLocalconf_control()
100 */
101 public function setValueInLocalconfFile(&$line_array, $variable, $value, $quoteValue = TRUE) {
102 if (!$this->checkForBadString($value)) {
103 return 0;
104 }
105
106 // Initialize:
107 $found = 0;
108 $this->touchedLine = '';
109 $commentKey = '## ';
110 $inArray = in_array($commentKey . $this->localconf_editPointToken, $line_array);
111 $tokenSet = ($this->localconf_editPointToken && !$inArray); // Flag is set if the token should be set but is not yet...
112 $stopAtToken = ($this->localconf_editPointToken && $inArray);
113 $comment = ' Modified or inserted by ' . $this->updateIdentity . '.';
114 $replace = array('["', '"]');
115 $search = array('[\'', '\']');
116 $varDoubleQuotes = str_replace($search, $replace, $variable);
117
118 // Search for variable name:
119 if (!$this->localconf_addLinesOnly && !$tokenSet) {
120 $line_array = array_reverse($line_array);
121 foreach ($line_array as $k => $v) {
122 $v2 = trim($v);
123 if ($stopAtToken && !strcmp($v2, $commentKey . $this->localconf_editPointToken)) {
124 break;
125 } // If stopAtToken and token found, break out of the loop..
126 if (!strcmp(substr($v2, 0, strlen($variable . ' ')), $variable . ' ')) {
127 $mainparts = explode($variable, $v, 2);
128 if (count($mainparts) == 2) { // should ALWAYS be....
129 $subparts = explode('//', $mainparts[1], 2);
130 if ($quoteValue) {
131 $value = '\'' . $this->slashValueForSingleDashes($value) . '\'';
132 }
133 $line_array[$k] = $mainparts[0] . $variable . " = " . $value . "; " . ('//' . $comment . str_replace($comment, '', $subparts[1]));
134 $this->touchedLine = count($line_array) - $k - 1;
135 $found = 1;
136 break;
137 }
138 } elseif (!strcmp(substr($v2, 0, strlen($varDoubleQuotes . ' ')), $varDoubleQuotes . ' ')) {
139 // Due to a bug in the update wizard (fixed in TYPO3 4.1.7) it is possible
140 // that $TYPO3_CONF_VARS['SYS']['compat_version'] was enclosed by "" (double
141 // quotes) instead of the expected '' (single quotes) when is was written to
142 // localconf.php. The following code was added to make sure that values with
143 // double quotes are updated, too.
144 $mainparts = explode($varDoubleQuotes, $v, 2);
145 if (count($mainparts) == 2) { // should ALWAYS be....
146 $subparts = explode('//', $mainparts[1], 2);
147 if ($quoteValue) {
148 $value = '\'' . $this->slashValueForSingleDashes($value) . '\'';
149 }
150 $line_array[$k] = $mainparts[0] . $variable . " = " . $value . "; " . ('//' . $comment . str_replace($comment, '', $subparts[1]));
151 $this->touchedLine = count($line_array) - $k - 1;
152 $found = 1;
153 break;
154 }
155 }
156 }
157 $line_array = array_reverse($line_array);
158 }
159 if (!$found) {
160 if ($tokenSet) {
161 $line_array[] = $commentKey . $this->localconf_editPointToken;
162 $line_array[] = '';
163 }
164 if ($quoteValue) {
165 $value = '\'' . $this->slashValueForSingleDashes($value) . '\'';
166 }
167 $line_array[] = $variable . " = " . $value . "; // " . $comment;
168 $this->touchedLine = -1;
169 }
170 if ($variable == '$typo_db_password') {
171 $this->messages[] = 'Updated ' . $variable;
172 } else {
173 $this->messages[] = $variable . " = " . htmlspecialchars($value);
174 }
175 $this->setLocalconf = 1;
176 }
177
178 /**
179 * Takes an array with lines from localconf.php, finds a variable and inserts the new array value.
180 *
181 * @param array $lines the localconf.php file exploded into an array by line breaks. {@see writeToLocalconf_control()}
182 * @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.
183 * @param array $value value to be assigned to the variable
184 * @return void
185 * @see writeToLocalconf_control()
186 */
187 public function setArrayValueInLocalconfFile(array &$lines, $variable, array $value) {
188 $commentKey = '## ';
189 $inArray = in_array($commentKey . $this->localconf_editPointToken, $lines);
190 $tokenSet = $this->localconf_editPointToken && !$inArray; // Flag is set if the token should be set but is not yet
191 $stopAtToken = $this->localconf_editPointToken && $inArray;
192 $comment = 'Modified or inserted by ' . $this->updateIdentity . '.';
193 $format = "%s = %s;\t// " . $comment;
194
195 $insertPos = count($lines);
196 $startPos = 0;
197 if (!($this->localconf_addLinesOnly || $tokenSet)) {
198 for ($i = count($lines) - 1; $i > 0; $i--) {
199 $line = trim($lines[$i]);
200 if ($stopAtToken && t3lib_div::isFirstPartOfStr($line, $this->localconf_editPointToken)) {
201 break;
202 }
203 if (t3lib_div::isFirstPartOfStr($line, '?>')) {
204 $insertPos = $i;
205 }
206 if (t3lib_div::isFirstPartOfStr($line, $variable)) {
207 $startPos = $i;
208 break;
209 }
210 }
211 }
212 if ($startPos) {
213 $this->touchedLine = $startPos;
214 $endPos = $startPos;
215 for ($i = $startPos; $i < count($lines); $i++) {
216 $line = trim($lines[$i]);
217 if (t3lib_div::isFirstPartOfStr($line, ');')) {
218 $endPos = $i;
219 break;
220 }
221 }
222
223 $startLines = array_slice($lines, 0, $startPos);
224 $endLines = array_slice($lines, $endPos + 1);
225
226 $lines = $startLines;
227 $definition = $this->array_export($value);
228 $lines[] = sprintf($format, $variable, $definition);
229 foreach ($endLines as $line) {
230 $lines[] = $line;
231 }
232 } else {
233 $lines[$insertPos] = sprintf($format, $variable, $this->array_export($value));
234 $lines[] = '?>';
235 $this->touchedLine = -1;
236 }
237 }
238
239 /**
240 * Returns a parsable string representation of an array variable. This methods enhances
241 * standard method var_export from PHP to take TYPO3's CGL into account.
242 *
243 * @param array $variable
244 * @return string
245 */
246 protected function array_export(array $variable) {
247 $lines = explode("\n", var_export($variable, TRUE));
248 $out = 'array(';
249
250 for ($i = 1; $i < count($lines); $i++) {
251 $out .= "\n";
252 // Make the space-indented declaration tab-indented instead
253 while (substr($lines[$i], 0, 2) === ' ') {
254 $out .= "\t";
255 $lines[$i] = substr($lines[$i], 2);
256 }
257 $out .= $lines[$i];
258 // Array declaration should be next to the assignment and no space between
259 // "array" and its opening parenthesis should exist
260 if (preg_match('/\s=>\s$/', $lines[$i])) {
261 $out .= preg_replace('/^\s*array \(/', 'array(', $lines[$i + 1]);
262 $i++;
263 }
264 }
265
266 return $out;
267 }
268
269 /**
270 * Writes or returns lines from localconf.php
271 *
272 * @param mixed $inlines Array of lines to write back to localconf.php. Possibly
273 * @param string $absFullPath Absolute path of alternative file to use (Notice: this path is not validated in terms of being inside 'TYPO3 space')
274 * @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)
275 * @see setValueInLocalconfFile()
276 */
277 function writeToLocalconf_control($inlines = '', $absFullPath = '') {
278 $tmpExt = '.TMP.php';
279 $writeToLocalconf_dat = array();
280 $writeToLocalconf_dat['file'] = $absFullPath ? $absFullPath : PATH_typo3conf . 'localconf.php';
281 $writeToLocalconf_dat['tmpfile'] = $writeToLocalconf_dat['file'] . $tmpExt;
282
283 // Checking write state of localconf.php:
284 if (!$this->allowUpdateLocalConf) {
285 throw new RuntimeException(
286 'TYPO3 Fatal Error: ->allowUpdateLocalConf flag in the install object is not set and therefore "localconf.php" cannot be altered.',
287 1270853915
288 );
289 }
290 if (!@is_writable($writeToLocalconf_dat['file'])) {
291 throw new RuntimeException(
292 'TYPO3 Fatal Error: ' . $writeToLocalconf_dat['file'] . ' is not writable!',
293 1270853916
294 );
295 }
296
297 // Splitting localconf.php file into lines:
298 $lines = explode(LF, str_replace(CR, '', trim(t3lib_div::getUrl($writeToLocalconf_dat['file']))));
299 $writeToLocalconf_dat['endLine'] = array_pop($lines); // Getting "? >" ending.
300
301 // Checking if "updated" line was set by this tool - if so remove old line.
302 $updatedLine = array_pop($lines);
303 $writeToLocalconf_dat['updatedText'] = '// Updated by ' . $this->updateIdentity . ' ';
304
305 if (!strstr($updatedLine, $writeToLocalconf_dat['updatedText'])) {
306 array_push($lines, $updatedLine);
307 }
308
309 if (is_array($inlines)) { // Setting a line and write:
310 // Setting configuration
311 $updatedLine = $writeToLocalconf_dat['updatedText'] . date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' H:i:s');
312 array_push($inlines, $updatedLine);
313 array_push($inlines, $writeToLocalconf_dat['endLine']);
314
315 if ($this->setLocalconf) {
316 $success = $this->writeToLocalconf($inlines, $absFullPath);
317
318 if ($success) {
319 return 'continue';
320 } else {
321 return 'nochange';
322 }
323 } else {
324 return 'nochange';
325 }
326 } else { // Return lines found in localconf.php
327 return $lines;
328 }
329 }
330
331 /**
332 * Writes lines to localconf.php.
333 *
334 * @param array $lines Array of lines to write back to localconf.php
335 * @param string $absFullPath Absolute path of alternative file to use (Notice: this path is not validated in terms of being inside 'TYPO3 space')
336 * @return boolean TRUE if method succeeded, otherwise FALSE
337 */
338 public function writeToLocalconf(array $lines, $absFullPath = '') {
339 $tmpExt = '.TMP.php';
340 $writeToLocalconf_dat = array();
341 $writeToLocalconf_dat['file'] = $absFullPath ? $absFullPath : PATH_typo3conf . 'localconf.php';
342 $writeToLocalconf_dat['tmpfile'] = $writeToLocalconf_dat['file'] . $tmpExt;
343
344 // Checking write state of localconf.php:
345 if (!$this->allowUpdateLocalConf) {
346 throw new RuntimeException(
347 'TYPO3 Fatal Error: ->allowUpdateLocalConf flag in the install object is not set and therefore "localconf.php" cannot be altered.',
348 1270853915
349 );
350 }
351 if (!@is_writable($writeToLocalconf_dat['file'])) {
352 throw new RuntimeException(
353 'TYPO3 Fatal Error: ' . $writeToLocalconf_dat['file'] . ' is not writable!',
354 1270853916
355 );
356 }
357
358 $writeToLocalconf_dat['endLine'] = array_pop($lines); // Getting "? >" ending.
359 if (!strstr('?' . '>', $writeToLocalconf_dat['endLine'])) {
360 $lines[] = $writeToLocalconf_dat['endLine'];
361 $writeToLocalconf_dat['endLine'] = '?' . '>';
362 }
363 // Checking if "updated" line was set by this tool - if so remove old line.
364 $updatedLine = array_pop($lines);
365 $writeToLocalconf_dat['updatedText'] = '// Updated by ' . $this->updateIdentity . ' ';
366
367 if (!strstr($updatedLine, $writeToLocalconf_dat['updatedText'])) {
368 $lines[] = $updatedLine;
369 }
370
371 $updatedLine = $writeToLocalconf_dat['updatedText'] . date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' H:i:s');
372 $lines[] = $updatedLine;
373 $lines[] = $writeToLocalconf_dat['endLine'];
374
375 $success = FALSE;
376 if (!t3lib_div::writeFile($writeToLocalconf_dat['tmpfile'], implode(LF, $lines))) {
377 $msg = 'typo3conf/localconf.php' . $tmpExt . ' could not be written - maybe a write access problem?';
378 }
379 elseif (strcmp(t3lib_div::getUrl($writeToLocalconf_dat['tmpfile']), implode(LF, $lines))) {
380 @unlink($writeToLocalconf_dat['tmpfile']);
381 $msg = 'typo3conf/localconf.php' . $tmpExt . ' was NOT written properly (written content didn\'t match file content) - maybe a disk space problem?';
382 }
383 elseif (!@copy($writeToLocalconf_dat['tmpfile'], $writeToLocalconf_dat['file'])) {
384 $msg = 'typo3conf/localconf.php could not be replaced by typo3conf/localconf.php' . $tmpExt . ' - maybe a write access problem?';
385 }
386 else {
387 @unlink($writeToLocalconf_dat['tmpfile']);
388 $success = TRUE;
389 $msg = 'Configuration written to typo3conf/localconf.php';
390 }
391 $this->messages[] = $msg;
392
393 if (!$success) {
394 t3lib_div::sysLog($msg, 'Core', 3);
395 }
396
397 return $success;
398 }
399
400 /**
401 * Checking for linebreaks in the string
402 *
403 * @param string String to test
404 * @return boolean Returns TRUE if string is OK
405 * @see setValueInLocalconfFile()
406 */
407 function checkForBadString($string) {
408 return preg_match('/[' . LF . CR . ']/', $string) ? FALSE : TRUE;
409 }
410
411 /**
412 * Replaces ' with \' and \ with \\
413 *
414 * @param string $value Input value
415 * @return string Output value
416 * @see setValueInLocalconfFile()
417 */
418 function slashValueForSingleDashes($value) {
419 $value = str_replace("'.LF.'", '###INSTALL_TOOL_LINEBREAK###', $value);
420 $value = str_replace("'", "\'", str_replace('\\', '\\\\', $value));
421 $value = str_replace('###INSTALL_TOOL_LINEBREAK###', "'.LF.'", $value);
422
423 return $value;
424 }
425
426
427 /*************************************
428 *
429 * SQL
430 *
431 *************************************/
432
433 /**
434 * Reads the field definitions for the input SQL-file string
435 *
436 * @param $fileContent string Should be a string read from an SQL-file made with 'mysqldump [database_name] -d'
437 * @return array Array with information about table.
438 * @deprecated Since TYPO3 4.6, will be removed in 4.8, use method from t3lib_install_Sql instead
439 */
440 function getFieldDefinitions_fileContent($fileContent) {
441 t3lib_div::logDeprecatedFunction();
442 return $this->sqlHandler->getFieldDefinitions_fileContent($fileContent);
443 }
444
445 /**
446 * Multiplies varchars/tinytext fields in size according to $this->multiplySize
447 * 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.
448 *
449 * @param array $total Total array (from getFieldDefinitions_fileContent())
450 * @return void
451 * @access private
452 * @see getFieldDefinitions_fileContent()
453 * @deprecated Since TYPO3 4.6, will be removed in 4.8
454 */
455 function getFieldDefinitions_sqlContent_parseTypes(&$total) {
456 // This method is protected in t3lib_install_Sql
457 t3lib_div::logDeprecatedFunction();
458 }
459
460 /**
461 * Look up the default collation for specified character set based on "SHOW CHARACTER SET" output
462 *
463 * @param string $charset Character set
464 * @return string Corresponding default collation
465 * @deprecated Since TYPO3 4.6, will be removed in 4.8, use method from t3lib_install_Sql instead
466 */
467 function getCollationForCharset($charset) {
468 t3lib_div::logDeprecatedFunction();
469 return $this->sqlHandler->getCollationForCharset($charset);
470 }
471
472 /**
473 * Reads the field definitions for the current database
474 *
475 * @return array Array with information about table.
476 * @deprecated Since TYPO3 4.6, will be removed in 4.8, use method from t3lib_install_Sql instead
477 */
478 function getFieldDefinitions_database() {
479 t3lib_div::logDeprecatedFunction();
480 return $this->sqlHandler->getFieldDefinitions_database();
481 }
482
483 /**
484 * Compares two arrays with field information and returns information about fields that are MISSING and fields that have CHANGED.
485 * FDsrc and FDcomp can be switched if you want the list of stuff to remove rather than update.
486 *
487 * @param array $FDsrc Field definitions, source (from getFieldDefinitions_fileContent())
488 * @param array $FDcomp Field definitions, comparison. (from getFieldDefinitions_database())
489 * @param string $onlyTableList Table names (in list) which is the ONLY one observed.
490 * @param boolean $ignoreNotNullWhenComparing 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.
491 * @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
492 * @deprecated Since TYPO3 4.6, will be removed in 4.8, use method from t3lib_install_Sql instead
493 */
494 function getDatabaseExtra($FDsrc, $FDcomp, $onlyTableList = '', $ignoreNotNullWhenComparing = TRUE) {
495 t3lib_div::logDeprecatedFunction();
496 return $this->sqlHandler->getDatabaseExtra($FDsrc, $FDcomp, $onlyTableList, $ignoreNotNullWhenComparing);
497 }
498
499 /**
500 * Returns an array with SQL-statements that is needed to update according to the diff-array
501 *
502 * @param array $diffArr Array with differences of current and needed DB settings. (from getDatabaseExtra())
503 * @param string $keyList List of fields in diff array to take notice of.
504 * @return array Array of SQL statements (organized in keys depending on type)
505 * @deprecated Since TYPO3 4.6, will be removed in 4.8, use method from t3lib_install_Sql instead
506 */
507 function getUpdateSuggestions($diffArr, $keyList = 'extra,diff') {
508 t3lib_div::logDeprecatedFunction();
509 return $this->sqlHandler->getUpdateSuggestions($diffArr, $keyList);
510 }
511
512 /**
513 * Converts a result row with field information into the SQL field definition string
514 *
515 * @param array $row MySQL result row
516 * @return string Field definition
517 * @deprecated Since TYPO3 4.6, will be removed in 4.8, use method from t3lib_install_Sql instead
518 */
519 function assembleFieldDefinition($row) {
520 t3lib_div::logDeprecatedFunction();
521 return $this->sqlHandler->assembleFieldDefinition($row);
522 }
523
524 /**
525 * Returns an array where every entry is a single SQL-statement. Input must be formatted like an ordinary MySQL-dump files.
526 *
527 * @param string $sqlcode 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.
528 * @param boolean $removeNonSQL If set, non-SQL content (like comments and blank lines) is not included in the final output
529 * @param string $query_regex Regex to filter SQL lines to include
530 * @return array Array of SQL statements
531 * @deprecated Since TYPO3 4.6, will be removed in 4.8, use method from t3lib_install_Sql instead
532 */
533 function getStatementArray($sqlcode, $removeNonSQL = FALSE, $query_regex = '') {
534 t3lib_div::logDeprecatedFunction();
535 return $this->sqlHandler->getStatementArray($sqlcode, $removeNonSQL, $query_regex);
536 }
537
538 /**
539 * Returns tables to create and how many records in each
540 *
541 * @param array $statements Array of SQL statements to analyse.
542 * @param boolean $insertCountFlag If set, will count number of INSERT INTO statements following that table definition
543 * @return array Array with table definitions in index 0 and count in index 1
544 * @deprecated Since TYPO3 4.6, will be removed in 4.8, use method from t3lib_install_Sql instead
545 */
546 function getCreateTables($statements, $insertCountFlag = FALSE) {
547 t3lib_div::logDeprecatedFunction();
548 return $this->sqlHandler->getCreateTables($statements, $insertCountFlag);
549 }
550
551 /**
552 * Extracts all insert statements from $statement array where content is inserted into $table
553 *
554 * @param array $statements Array of SQL statements
555 * @param string $table Table name
556 * @return array Array of INSERT INTO statements where table match $table
557 * @deprecated Since TYPO3 4.6, will be removed in 4.8, use method from t3lib_install_Sql instead
558 */
559 function getTableInsertStatements($statements, $table) {
560 t3lib_div::logDeprecatedFunction();
561 $this->sqlHandler->getTableInsertStatements($statements, $table);
562 }
563
564 /**
565 * Performs the queries passed from the input array.
566 *
567 * @param array $arr Array of SQL queries to execute.
568 * @param array $keyArr 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)
569 * @return mixed Array with error message from database if any occured. Otherwise TRUE if everything was executed successfully.
570 * @deprecated Since TYPO3 4.6, will be removed in 4.8, use method from t3lib_install_Sql instead
571 */
572 function performUpdateQueries($arr, $keyArr) {
573 t3lib_div::logDeprecatedFunction();
574 $this->sqlHandler->performUpdateQueries($arr, $keyArr);
575 }
576
577 /**
578 * Returns list of tables in the database
579 *
580 * @return array List of tables.
581 * @see t3lib_db::admin_get_tables()
582 * @deprecated Since TYPO3 4.6, will be removed in 4.8, use method from t3lib_install_Sql instead
583 */
584 function getListOfTables() {
585 t3lib_div::logDeprecatedFunction();
586 $this->sqlHandler->getListOfTables();
587 }
588
589 /**
590 * Creates a table which checkboxes for updating database.
591 *
592 * @param array $arr Array of statements (key / value pairs where key is used for the checkboxes)
593 * @param string $label Label for the table.
594 * @param boolean $checked If set, then checkboxes are set by default.
595 * @param boolean $iconDis If set, then icons are shown.
596 * @param array $currentValue Array of "current values" for each key/value pair in $arr. Shown if given.
597 * @param boolean $cVfullMsg If set, will show the prefix "Current value" if $currentValue is given.
598 * @return string HTML table with checkboxes for update. Must be wrapped in a form.
599 */
600 function generateUpdateDatabaseForm_checkboxes($arr, $label, $checked = TRUE, $iconDis = FALSE, $currentValue = array(), $cVfullMsg = FALSE) {
601 $out = array();
602 if (is_array($arr)) {
603 $tableId = uniqid('table');
604 if (count($arr) > 1) {
605 $out[] = '
606 <tr class="update-db-fields-batch">
607 <td valign="top">
608 <input type="checkbox" id="' . $tableId . '-checkbox"' . ($checked ? ' checked="checked"' : '') . '
609 onclick="$(\'' . $tableId . '\').select(\'input[type=checkbox]\').invoke(\'setValue\', $(this).checked);" />
610 </td>
611 <td nowrap="nowrap"><label for="' . $tableId . '-checkbox" style="cursor:pointer"><strong>select/deselect all</strong></label></td>
612 </tr>';
613 }
614 foreach ($arr as $key => $string) {
615 $ico = '';
616 $warnings = array();
617
618 if ($iconDis) {
619 if (preg_match('/^TRUNCATE/i', $string)) {
620 $ico .= '<img src="' . $this->backPath . 'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong> </strong>';
621 $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.';
622 } elseif (stristr($string, ' user_')) {
623 $ico .= '<img src="' . $this->backPath . 'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(USER) </strong>';
624 } elseif (stristr($string, ' app_')) {
625 $ico .= '<img src="' . $this->backPath . 'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(APP) </strong>';
626 } elseif (stristr($string, ' ttx_') || stristr($string, ' tx_')) {
627 $ico .= '<img src="' . $this->backPath . 'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(EXT) </strong>';
628 }
629 }
630 $out[] = '
631 <tr>
632 <td valign="top"><input type="checkbox" id="db-' . $key . '" name="' . $this->dbUpdateCheckboxPrefix . '[' . $key . ']" value="1"' . ($checked ? ' checked="checked"' : '') . ' /></td>
633 <td nowrap="nowrap"><label for="db-' . $key . '">' . nl2br($ico . htmlspecialchars($string)) . '</label></td>
634 </tr>';
635 if (isset($currentValue[$key])) {
636 $out[] = '
637 <tr>
638 <td valign="top"></td>
639 <td nowrap="nowrap" style="color:#666666;">' . nl2br((!$cVfullMsg ? "Current value: " : "") . '<em>' . $currentValue[$key] . '</em>') . '</td>
640 </tr>';
641 }
642 }
643 if (count($warnings)) {
644 $out[] = '
645 <tr>
646 <td valign="top"></td>
647 <td style="color:#666666;"><em>' . implode('<br />', $warnings) . '</em></td>
648 </tr>';
649 }
650
651 // Compile rows:
652 $content = '
653 <!-- Update database fields / tables -->
654 <h3>' . $label . '</h3>
655 <table border="0" cellpadding="2" cellspacing="2" id="' . $tableId . '" class="update-db-fields">' . implode('', $out) . '
656 </table>';
657 }
658
659 return $content;
660 }
661 }
662
663 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_install.php'])) {
664 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_install.php']);
665 }
666
667 ?>