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