00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 class t3lib_install {
00083
00084
00085
00086 var $updateIdentity = '';
00087 var $deletedPrefixKey = 'zzz_deleted_';
00088 var $dbUpdateCheckboxPrefix = 'TYPO3_INSTALL[database_update]';
00089 var $localconf_addLinesOnly = 0;
00090 var $localconf_editPointToken = 'INSTALL SCRIPT EDIT POINT TOKEN - all lines after this points may be changed by the install script!';
00091 var $allowUpdateLocalConf = 0;
00092 var $backPath = '../';
00093
00094 var $multiplySize = 1;
00095 var $character_sets = array();
00096
00097
00098 var $setLocalconf = 0;
00099 var $messages = array();
00100 var $touchedLine = 0;
00101
00102
00103
00104
00105
00106
00107
00108 function t3lib_install() {
00109 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['multiplyDBfieldSize']>= 1 && $GLOBALS['TYPO3_CONF_VARS']['SYS']['multiplyDBfieldSize']<=5) {
00110 $this->multiplySize = (double)$GLOBALS['TYPO3_CONF_VARS']['SYS']['multiplyDBfieldSize'];
00111 }
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 public function setValueInLocalconfFile(&$line_array, $variable, $value, $quoteValue = TRUE) {
00134 if (!$this->checkForBadString($value)) return 0;
00135
00136
00137 $found = 0;
00138 $this->touchedLine = '';
00139 $commentKey = '## ';
00140 $inArray = in_array($commentKey.$this->localconf_editPointToken,$line_array);
00141 $tokenSet = ($this->localconf_editPointToken && !$inArray);
00142 $stopAtToken = ($this->localconf_editPointToken && $inArray);
00143 $comment = ' Modified or inserted by '.$this->updateIdentity.'.';
00144 $replace = array('["', '"]');
00145 $search = array('[\'', '\']');
00146 $varDoubleQuotes = str_replace($search, $replace, $variable);
00147
00148
00149 if (!$this->localconf_addLinesOnly && !$tokenSet) {
00150 $line_array = array_reverse($line_array);
00151 foreach($line_array as $k => $v) {
00152 $v2 = trim($v);
00153 if ($stopAtToken && !strcmp($v2,$commentKey.$this->localconf_editPointToken)) break;
00154 if (!strcmp(substr($v2,0,strlen($variable.' ')),$variable.' ')) {
00155 $mainparts = explode($variable,$v,2);
00156 if (count($mainparts)==2) {
00157 $subparts = explode('
00158 if ($quoteValue) {
00159 $value = '\'' . $this->slashValueForSingleDashes($value) . '\'';
00160 }
00161 $line_array[$k] = $mainparts[0] . $variable . " = " . $value . "; " . ('
00162 $this->touchedLine = count($line_array)-$k-1;
00163 $found = 1;
00164 break;
00165 }
00166 } elseif (!strcmp(substr($v2, 0, strlen($varDoubleQuotes . ' ')), $varDoubleQuotes . ' ')) {
00167
00168
00169
00170
00171
00172 $mainparts = explode($varDoubleQuotes, $v, 2);
00173 if (count($mainparts) == 2) {
00174 $subparts = explode('
00175 if ($quoteValue) {
00176 $value = '\'' . $this->slashValueForSingleDashes($value) . '\'';
00177 }
00178 $line_array[$k] = $mainparts[0] . $variable . " = " . $value . "; " . ('
00179 $this->touchedLine = count($line_array) - $k - 1;
00180 $found = 1;
00181 break;
00182 }
00183 }
00184 }
00185 $line_array = array_reverse($line_array);
00186 }
00187 if (!$found) {
00188 if ($tokenSet) {
00189 $line_array[] = $commentKey.$this->localconf_editPointToken;
00190 $line_array[] = '';
00191 }
00192 if ($quoteValue) {
00193 $value = '\'' . $this->slashValueForSingleDashes($value) . '\'';
00194 }
00195 $line_array[] = $variable . " = " . $value . "; // " . $comment;
00196 $this->touchedLine = -1;
00197 }
00198 if ($variable == '$typo_db_password') {
00199 $this->messages[] = 'Updated ' . $variable;
00200 } else {
00201 $this->messages[] = $variable . " = " . htmlspecialchars($value);
00202 }
00203 $this->setLocalconf = 1;
00204 }
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 function writeToLocalconf_control($inlines='',$absFullPath='') {
00215 $tmpExt = '.TMP.php';
00216 $writeToLocalconf_dat = array();
00217 $writeToLocalconf_dat['file'] = $absFullPath ? $absFullPath : PATH_typo3conf.'localconf.php';
00218 $writeToLocalconf_dat['tmpfile'] = $writeToLocalconf_dat['file'].$tmpExt;
00219
00220
00221 if (!$this->allowUpdateLocalConf) {
00222 throw new RuntimeException(
00223 'TYPO3 Fatal Error: ->allowUpdateLocalConf flag in the install object is not set and therefore "localconf.php" cannot be altered.',
00224 1270853915
00225 );
00226 }
00227 if (!@is_writable($writeToLocalconf_dat['file'])) {
00228 throw new RuntimeException(
00229 'TYPO3 Fatal Error: ' . $writeToLocalconf_dat['file'] . ' is not writable!',
00230 1270853916
00231 );
00232 }
00233
00234
00235 $lines = explode(LF,str_replace(CR,'',trim(t3lib_div::getUrl($writeToLocalconf_dat['file']))));
00236 $writeToLocalconf_dat['endLine'] = array_pop($lines);
00237
00238
00239 $updatedLine = array_pop($lines);
00240 $writeToLocalconf_dat['updatedText'] = '
00241
00242 if (!strstr($updatedLine, $writeToLocalconf_dat['updatedText'])) {
00243 array_push($lines,$updatedLine);
00244 }
00245
00246 if (is_array($inlines)) {
00247
00248 $updatedLine = $writeToLocalconf_dat['updatedText'].date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'].' H:i:s');
00249 array_push($inlines,$updatedLine);
00250 array_push($inlines,$writeToLocalconf_dat['endLine']);
00251
00252 if ($this->setLocalconf) {
00253 $success = FALSE;
00254 if (!t3lib_div::writeFile($writeToLocalconf_dat['tmpfile'],implode(LF,$inlines))) {
00255 $msg = 'typo3conf/localconf.php'.$tmpExt.' could not be written - maybe a write access problem?';
00256 }
00257 elseif (strcmp(t3lib_div::getUrl($writeToLocalconf_dat['tmpfile']), implode(LF,$inlines))) {
00258 @unlink($writeToLocalconf_dat['tmpfile']);
00259 $msg = 'typo3conf/localconf.php'.$tmpExt.' was NOT written properly (written content didn\'t match file content) - maybe a disk space problem?';
00260 }
00261 elseif (!@copy($writeToLocalconf_dat['tmpfile'],$writeToLocalconf_dat['file'])) {
00262 $msg = 'typo3conf/localconf.php could not be replaced by typo3conf/localconf.php'.$tmpExt.' - maybe a write access problem?';
00263 }
00264 else {
00265 @unlink($writeToLocalconf_dat['tmpfile']);
00266 $success = TRUE;
00267 $msg = 'Configuration written to typo3conf/localconf.php';
00268 }
00269 $this->messages[] = $msg;
00270
00271 if ($success) {
00272 return 'continue';
00273 } else {
00274 t3lib_div::sysLog($msg, 'Core', 3);
00275 return 'nochange';
00276 }
00277 } else {
00278 return 'nochange';
00279 }
00280 } else {
00281 return $lines;
00282 }
00283 }
00284
00285
00286
00287
00288
00289
00290
00291
00292 function checkForBadString($string) {
00293 return preg_match('/['.LF.CR.']/',$string) ? FALSE : TRUE;
00294 }
00295
00296
00297
00298
00299
00300
00301
00302
00303 function slashValueForSingleDashes($value) {
00304 $value = str_replace("'.LF.'", '###INSTALL_TOOL_LINEBREAK###', $value);
00305 $value = str_replace("'","\'",str_replace('\\','\\\\',$value));
00306 $value = str_replace('###INSTALL_TOOL_LINEBREAK###', "'.LF.'", $value);
00307
00308 return $value;
00309 }
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 function getFieldDefinitions_fileContent($fileContent) {
00333 $lines = t3lib_div::trimExplode(LF, $fileContent, 1);
00334 $table = '';
00335 $total = array();
00336
00337 foreach ($lines as $value) {
00338 if (substr($value,0,1)=='#') {
00339 continue;
00340 }
00341
00342 if (!strlen($table)) {
00343 $parts = t3lib_div::trimExplode(' ', $value, TRUE);
00344 if (strtoupper($parts[0]) === 'CREATE' && strtoupper($parts[1]) === 'TABLE') {
00345 $table = str_replace( '`', '', $parts[2]);
00346 if (TYPO3_OS=='WIN') {
00347 $table = strtolower($table);
00348 }
00349 }
00350 } else {
00351 if (substr($value,0,1)==')' && substr($value,-1)==';') {
00352 $ttype = array();
00353 if (preg_match('/(ENGINE|TYPE)[ ]*=[ ]*([a-zA-Z]*)/',$value,$ttype)) {
00354 $total[$table]['extra']['ENGINE'] = $ttype[2];
00355 }
00356
00357
00358 if (preg_match('/(COLLATE)[ ]*=[ ]*([a-zA-z0-9_-]+)/', $value, $tcollation)) {
00359 $total[$table]['extra']['COLLATE'] = $tcollation[2];
00360 } else {
00361
00362 if (preg_match('/(CHARSET|CHARACTER SET)[ ]*=[ ]*([a-zA-z0-9_-]+)/', $value, $tcharset)) {
00363 $charset = $tcharset[2];
00364 } else {
00365 $charset = $GLOBALS['TYPO3_DB']->default_charset;
00366 }
00367 $total[$table]['extra']['COLLATE'] = $this->getCollationForCharset($charset);
00368 }
00369
00370 $table = '';
00371 } else {
00372 $lineV = preg_replace('/,$/','',$value);
00373 $lineV = str_replace('`', '', $lineV);
00374 $lineV = str_replace(' ', ' ', $lineV);
00375
00376 $parts = explode(' ', $lineV, 2);
00377 if (!preg_match('/(PRIMARY|UNIQUE|FULLTEXT|INDEX|KEY)/',$parts[0])) {
00378
00379
00380 if (stristr($parts[1],'auto_increment')) {
00381 $parts[1] = preg_replace('/ default \'0\'/i','',$parts[1]);
00382 }
00383
00384 if (stristr($parts[1], ' DEFAULT ')) {
00385 $parts[1] = str_ireplace(' DEFAULT ', ' default ', $parts[1]);
00386 }
00387
00388
00389 $parts[1] = preg_replace('/(.*) (default .*) (NOT NULL)/', '$1 $3 $2', $parts[1]);
00390 $parts[1] = preg_replace('/(.*) (default .*) (NULL)/', '$1 $3 $2', $parts[1]);
00391
00392 $key = $parts[0];
00393 $total[$table]['fields'][$key] = $parts[1];
00394
00395 } else {
00396 $search = array('/UNIQUE (INDEX|KEY)/', '/FULLTEXT (INDEX|KEY)/', '/INDEX/');
00397 $replace = array('UNIQUE', 'FULLTEXT', 'KEY');
00398 $lineV = preg_replace($search, $replace, $lineV);
00399
00400 if (preg_match('/PRIMARY|UNIQUE|FULLTEXT/', $parts[0])) {
00401 $parts[1] = preg_replace('/^(KEY|INDEX) /', '', $parts[1]);
00402 }
00403
00404 $newParts = explode(' ',$parts[1],2);
00405 $key = $parts[0]=='PRIMARY' ? $parts[0] : $newParts[0];
00406
00407 $total[$table]['keys'][$key] = $lineV;
00408
00409
00410 if (preg_match('/^(cache|index)_/',$table)) {
00411
00412 $total[$table]['extra']['CLEAR'] = 1;
00413 }
00414 }
00415 }
00416 }
00417 }
00418
00419 $this->getFieldDefinitions_sqlContent_parseTypes($total);
00420 return $total;
00421 }
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432 function getFieldDefinitions_sqlContent_parseTypes(&$total) {
00433
00434 $mSize = (double)$this->multiplySize;
00435 if ($mSize > 1) {
00436
00437
00438 $sqlParser = t3lib_div::makeInstance('t3lib_sqlparser');
00439 foreach($total as $table => $cfg) {
00440 if (is_array($cfg['fields'])) {
00441 foreach($cfg['fields'] as $fN => $fType) {
00442 $orig_fType = $fType;
00443 $fInfo = $sqlParser->parseFieldDef($fType);
00444
00445 switch($fInfo['fieldType']) {
00446 case 'char':
00447 case 'varchar':
00448 $newSize = round($fInfo['value']*$mSize);
00449
00450 if ($newSize <= 255) {
00451 $fInfo['value'] = $newSize;
00452 } else {
00453 $fInfo = array(
00454 'fieldType' => 'text',
00455 'featureIndex' => array(
00456 'NOTNULL' => array(
00457 'keyword' => 'NOT NULL'
00458 )
00459 )
00460 );
00461
00462 if (is_array($cfg['keys'])) {
00463 foreach ($cfg['keys'] as $kN => $kType) {
00464 $match = array();
00465 preg_match('/^([^(]*)\(([^)]+)\)(.*)/', $kType, $match);
00466 $keys = array();
00467 foreach (t3lib_div::trimExplode(',',$match[2]) as $kfN) {
00468 if ($fN == $kfN) {
00469 $kfN .= '('.$newSize.')';
00470 }
00471 $keys[] = $kfN;
00472 }
00473 $total[$table]['keys'][$kN] = $match[1].'('.implode(',',$keys).')'.$match[3];
00474 }
00475 }
00476 }
00477 break;
00478 case 'tinytext':
00479 $fInfo['fieldType'] = 'text';
00480 break;
00481 }
00482
00483 $total[$table]['fields'][$fN] = $sqlParser->compileFieldCfg($fInfo);
00484 if ($sqlParser->parse_error) {
00485 throw new RuntimeException(
00486 'TYPO3 Fatal Error: ' . $sqlParser->parse_error,
00487 1270853961
00488 );
00489 }
00490 }
00491 }
00492 }
00493 }
00494 }
00495
00496
00497
00498
00499
00500
00501
00502 function getCollationForCharset($charset) {
00503
00504 if (!count($this->character_sets)) {
00505 if (method_exists($GLOBALS['TYPO3_DB'],'admin_get_charsets')) {
00506 $this->character_sets = $GLOBALS['TYPO3_DB']->admin_get_charsets();
00507 } else {
00508 $this->character_sets[$charset] = array();
00509 }
00510 }
00511
00512 $collation = '';
00513 if (isset($this->character_sets[$charset]['Default collation'])) {
00514 $collation = $this->character_sets[$charset]['Default collation'];
00515 }
00516
00517 return $collation;
00518 }
00519
00520
00521
00522
00523
00524
00525 function getFieldDefinitions_database() {
00526 $total = array();
00527 $tempKeys = array();
00528 $tempKeysPrefix = array();
00529
00530 $GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db);
00531 echo $GLOBALS['TYPO3_DB']->sql_error();
00532
00533 $tables = $GLOBALS['TYPO3_DB']->admin_get_tables(TYPO3_db);
00534 foreach ($tables as $tableName => $tableStatus) {
00535
00536
00537 $fieldInformation = $GLOBALS['TYPO3_DB']->admin_get_fields($tableName);
00538 foreach ($fieldInformation as $fN => $fieldRow) {
00539 $total[$tableName]['fields'][$fN] = $this->assembleFieldDefinition($fieldRow);
00540 }
00541
00542
00543 $keyInformation = $GLOBALS['TYPO3_DB']->admin_get_keys($tableName);
00544
00545 foreach ($keyInformation as $keyRow) {
00546 $keyName = $keyRow['Key_name'];
00547 $colName = $keyRow['Column_name'];
00548 if ($keyRow['Sub_part']) {
00549 $colName.= '('.$keyRow['Sub_part'].')';
00550 }
00551 $tempKeys[$tableName][$keyName][$keyRow['Seq_in_index']] = $colName;
00552 if ($keyName=='PRIMARY') {
00553 $prefix = 'PRIMARY KEY';
00554 } else {
00555 if ($keyRow['Index_type']=='FULLTEXT') {
00556 $prefix = 'FULLTEXT';
00557 } elseif ($keyRow['Non_unique']) {
00558 $prefix = 'KEY';
00559 } else {
00560 $prefix = 'UNIQUE';
00561 }
00562 $prefix.= ' '.$keyName;
00563 }
00564 $tempKeysPrefix[$tableName][$keyName] = $prefix;
00565 }
00566
00567
00568 if (is_array($tableStatus)) {
00569 $tableExtraFields = array(
00570 'Engine' => 'ENGINE',
00571 'Collation' => 'COLLATE',
00572 );
00573
00574 foreach ($tableExtraFields as $mysqlKey=>$internalKey) {
00575 if (isset($tableStatus[$mysqlKey])) {
00576 $total[$tableName]['extra'][$internalKey] = $tableStatus[$mysqlKey];
00577 }
00578 }
00579 }
00580 }
00581
00582
00583 if (count($tempKeys)) {
00584 foreach ($tempKeys as $table => $keyInf) {
00585 foreach ($keyInf as $kName => $index) {
00586 ksort($index);
00587 $total[$table]['keys'][$kName] = $tempKeysPrefix[$table][$kName].' ('.implode(',',$index).')';
00588 }
00589 }
00590 }
00591
00592 return $total;
00593 }
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605 function getDatabaseExtra($FDsrc, $FDcomp, $onlyTableList='',$ignoreNotNullWhenComparing=true) {
00606 $extraArr = array();
00607 $diffArr = array();
00608
00609 if (is_array($FDsrc)) {
00610 foreach ($FDsrc as $table => $info) {
00611 if (!strlen($onlyTableList) || t3lib_div::inList($onlyTableList, $table)) {
00612 if (!isset($FDcomp[$table])) {
00613 $extraArr[$table] = $info;
00614 $extraArr[$table]['whole_table']=1;
00615 } else {
00616 $keyTypes = explode(',','extra,fields,keys');
00617 foreach ($keyTypes as $theKey) {
00618 if (is_array($info[$theKey])) {
00619 foreach ($info[$theKey] as $fieldN => $fieldC) {
00620 $fieldN = str_replace('`','',$fieldN);
00621 if ($fieldN=='COLLATE') {
00622 continue;
00623 }
00624
00625 if (!isset($FDcomp[$table][$theKey][$fieldN])) {
00626 $extraArr[$table][$theKey][$fieldN] = $fieldC;
00627 } else {
00628 $fieldC = trim($fieldC);
00629 if ($ignoreNotNullWhenComparing) {
00630 $fieldC = str_replace(' NOT NULL', '', $fieldC);
00631 $FDcomp[$table][$theKey][$fieldN] = str_replace(' NOT NULL', '', $FDcomp[$table][$theKey][$fieldN]);
00632 }
00633 if ($fieldC !== $FDcomp[$table][$theKey][$fieldN]) {
00634 $diffArr[$table][$theKey][$fieldN] = $fieldC;
00635 $diffArr_cur[$table][$theKey][$fieldN] = $FDcomp[$table][$theKey][$fieldN];
00636 }
00637 }
00638 }
00639 }
00640 }
00641 }
00642 }
00643 }
00644 }
00645
00646 $output = array(
00647 'extra' => $extraArr,
00648 'diff' => $diffArr,
00649 'diff_currentValues' => $diffArr_cur
00650 );
00651
00652 return $output;
00653 }
00654
00655
00656
00657
00658
00659
00660
00661
00662 function getUpdateSuggestions($diffArr,$keyList='extra,diff') {
00663 $statements = array();
00664 $deletedPrefixKey = $this->deletedPrefixKey;
00665 $remove = 0;
00666 if ($keyList == 'remove') {
00667 $remove = 1;
00668 $keyList = 'extra';
00669 }
00670 $keyList = explode(',',$keyList);
00671 foreach ($keyList as $theKey) {
00672 if (is_array($diffArr[$theKey])) {
00673 foreach ($diffArr[$theKey] as $table => $info) {
00674 $whole_table = array();
00675 if (is_array($info['fields'])) {
00676 foreach ($info['fields'] as $fN => $fV) {
00677 if ($info['whole_table']) {
00678 $whole_table[]=$fN.' '.$fV;
00679 } else {
00680
00681 if (stristr($fV, 'auto_increment')) {
00682
00683
00684 if (isset($diffArr['extra'][$table]['keys']['PRIMARY'])) {
00685
00686 $fV = str_replace(' auto_increment', '', $fV);
00687 } else {
00688
00689 $info['extra']['CLEAR'] = 2;
00690 }
00691 }
00692 if ($theKey=='extra') {
00693 if ($remove) {
00694 if (substr($fN,0,strlen($deletedPrefixKey))!=$deletedPrefixKey) {
00695 $statement = 'ALTER TABLE '.$table.' CHANGE '.$fN.' '.$deletedPrefixKey.$fN.' '.$fV.';';
00696 $statements['change'][md5($statement)] = $statement;
00697 } else {
00698 $statement = 'ALTER TABLE '.$table.' DROP '.$fN.';';
00699 $statements['drop'][md5($statement)] = $statement;
00700 }
00701 } else {
00702 $statement = 'ALTER TABLE '.$table.' ADD '.$fN.' '.$fV.';';
00703 $statements['add'][md5($statement)] = $statement;
00704 }
00705 } elseif ($theKey=='diff') {
00706 $statement = 'ALTER TABLE '.$table.' CHANGE '.$fN.' '.$fN.' '.$fV.';';
00707 $statements['change'][md5($statement)] = $statement;
00708 $statements['change_currentValue'][md5($statement)] = $diffArr['diff_currentValues'][$table]['fields'][$fN];
00709 }
00710 }
00711 }
00712 }
00713 if (is_array($info['keys'])) {
00714 foreach ($info['keys'] as $fN => $fV) {
00715 if ($info['whole_table']) {
00716 $whole_table[] = $fV;
00717 } else {
00718 if ($theKey=='extra') {
00719 if ($remove) {
00720 $statement = 'ALTER TABLE '.$table.($fN=='PRIMARY' ? ' DROP PRIMARY KEY' : ' DROP KEY '.$fN).';';
00721 $statements['drop'][md5($statement)] = $statement;
00722 } else {
00723 $statement = 'ALTER TABLE '.$table.' ADD '.$fV.';';
00724 $statements['add'][md5($statement)] = $statement;
00725 }
00726 } elseif ($theKey=='diff') {
00727 $statement = 'ALTER TABLE '.$table.($fN=='PRIMARY' ? ' DROP PRIMARY KEY' : ' DROP KEY '.$fN).';';
00728 $statements['change'][md5($statement)] = $statement;
00729 $statement = 'ALTER TABLE '.$table.' ADD '.$fV.';';
00730 $statements['change'][md5($statement)] = $statement;
00731 }
00732 }
00733 }
00734 }
00735 if (is_array($info['extra'])) {
00736 $extras = array();
00737 $extras_currentValue = array();
00738 $clear_table = false;
00739
00740 foreach ($info['extra'] as $fN => $fV) {
00741
00742
00743 if (!$remove) {
00744 if (!$info['whole_table']) {
00745 if ($fN=='CLEAR') {
00746
00747
00748 if (count($info['keys']) || $fV==2) {
00749 $clear_table = true;
00750 }
00751 continue;
00752 } else {
00753 $extras[] = $fN.'='.$fV;
00754 $extras_currentValue[] = $fN.'='.$diffArr['diff_currentValues'][$table]['extra'][$fN];
00755 }
00756 }
00757 }
00758 }
00759 if ($clear_table) {
00760 $statement = 'TRUNCATE TABLE '.$table.';';
00761 $statements['clear_table'][md5($statement)] = $statement;
00762 }
00763 if (count($extras)) {
00764 $statement = 'ALTER TABLE '.$table.' '.implode(' ',$extras).';';
00765 $statements['change'][md5($statement)] = $statement;
00766 $statements['change_currentValue'][md5($statement)] = implode(' ',$extras_currentValue);
00767 }
00768 }
00769 if ($info['whole_table']) {
00770 if ($remove) {
00771 if (substr($table,0,strlen($deletedPrefixKey))!=$deletedPrefixKey) {
00772 $statement = 'ALTER TABLE '.$table.' RENAME '.$deletedPrefixKey.$table.';';
00773 $statements['change_table'][md5($statement)] = $statement;
00774 } else {
00775 $statement = 'DROP TABLE '.$table.';';
00776 $statements['drop_table'][md5($statement)] = $statement;
00777 }
00778
00779 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', $table);
00780 $statements['tables_count'][md5($statement)] = $count?'Records in table: '.$count:'';
00781 } else {
00782 $statement = 'CREATE TABLE '.$table." (\n".implode(",\n",$whole_table)."\n)";
00783 if ($info['extra']) {
00784 foreach ($info['extra'] as $k=>$v) {
00785 if ($k=='COLLATE' || $k=='CLEAR') {
00786 continue;
00787 }
00788 $statement.= ' '.$k.'='.$v;
00789 }
00790 }
00791 $statement.= ';';
00792 $statements['create_table'][md5($statement)] = $statement;
00793 }
00794 }
00795 }
00796 }
00797 }
00798
00799 return $statements;
00800 }
00801
00802
00803
00804
00805
00806
00807
00808 function assembleFieldDefinition($row) {
00809 $field = array($row['Type']);
00810
00811 if ($row['Null']=='NO') {
00812 $field[] = 'NOT NULL';
00813 }
00814 if (!strstr($row['Type'],'blob') && !strstr($row['Type'],'text')) {
00815
00816 if (!stristr($row['Extra'],'auto_increment')) {
00817 $field[] = 'default \''.addslashes($row['Default']).'\'';
00818 }
00819 }
00820 if ($row['Extra']) {
00821 $field[] = $row['Extra'];
00822 }
00823
00824 return implode(' ',$field);
00825 }
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835 function getStatementArray($sqlcode,$removeNonSQL=0,$query_regex='') {
00836 $sqlcodeArr = explode(LF, $sqlcode);
00837
00838
00839 $statementArray = array();
00840 $statementArrayPointer = 0;
00841
00842 foreach ($sqlcodeArr as $line => $lineContent) {
00843 $is_set = 0;
00844
00845
00846 if (stristr($lineContent,'auto_increment')) {
00847 $lineContent = preg_replace('/ default \'0\'/i', '', $lineContent);
00848 }
00849
00850 if (!$removeNonSQL || (strcmp(trim($lineContent),'') && substr(trim($lineContent),0,1)!='#' && substr(trim($lineContent),0,2)!='--')) {
00851 $statementArray[$statementArrayPointer].= $lineContent;
00852 $is_set = 1;
00853 }
00854 if (substr(trim($lineContent),-1)==';') {
00855 if (isset($statementArray[$statementArrayPointer])) {
00856 if (!trim($statementArray[$statementArrayPointer]) || ($query_regex && !preg_match('/'.$query_regex.'/i',trim($statementArray[$statementArrayPointer])))) {
00857 unset($statementArray[$statementArrayPointer]);
00858 }
00859 }
00860 $statementArrayPointer++;
00861
00862 } elseif ($is_set) {
00863 $statementArray[$statementArrayPointer].= LF;
00864 }
00865 }
00866
00867 return $statementArray;
00868 }
00869
00870
00871
00872
00873
00874
00875
00876
00877 function getCreateTables($statements, $insertCountFlag=0) {
00878 $crTables = array();
00879 $insertCount = array();
00880 foreach ($statements as $line => $lineContent) {
00881 $reg = array();
00882 if (preg_match('/^create[[:space:]]*table[[:space:]]*[`]?([[:alnum:]_]*)[`]?/i',substr($lineContent,0,100),$reg)) {
00883 $table = trim($reg[1]);
00884 if ($table) {
00885
00886 if (TYPO3_OS == 'WIN') {
00887 $table = strtolower($table);
00888 }
00889 $sqlLines = explode(LF, $lineContent);
00890 foreach ($sqlLines as $k=>$v) {
00891 if (stristr($v,'auto_increment')) {
00892 $sqlLines[$k] = preg_replace('/ default \'0\'/i', '', $v);
00893 }
00894 }
00895 $lineContent = implode(LF, $sqlLines);
00896 $crTables[$table] = $lineContent;
00897 }
00898 } elseif ($insertCountFlag && preg_match('/^insert[[:space:]]*into[[:space:]]*[`]?([[:alnum:]_]*)[`]?/i',substr($lineContent,0,100),$reg)) {
00899 $nTable = trim($reg[1]);
00900 $insertCount[$nTable]++;
00901 }
00902 }
00903
00904 return array($crTables,$insertCount);
00905 }
00906
00907
00908
00909
00910
00911
00912
00913
00914 function getTableInsertStatements($statements, $table) {
00915 $outStatements=array();
00916 foreach($statements as $line => $lineContent) {
00917 $reg = array();
00918 if (preg_match('/^insert[[:space:]]*into[[:space:]]*[`]?([[:alnum:]_]*)[`]?/i',substr($lineContent,0,100),$reg)) {
00919 $nTable = trim($reg[1]);
00920 if ($nTable && !strcmp($table,$nTable)) {
00921 $outStatements[] = $lineContent;
00922 }
00923 }
00924 }
00925 return $outStatements;
00926 }
00927
00928
00929
00930
00931
00932
00933
00934
00935 function performUpdateQueries($arr,$keyArr) {
00936 $result = array();
00937 if (is_array($arr)) {
00938 foreach($arr as $key => $string) {
00939 if (isset($keyArr[$key]) && $keyArr[$key]) {
00940 $res = $GLOBALS['TYPO3_DB']->admin_query($string);
00941 if ($res === false) {
00942 $result[$key] = $GLOBALS['TYPO3_DB']->sql_error();
00943 } elseif (is_resource($res)) {
00944 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00945 }
00946 }
00947 }
00948 }
00949 if (count($result) > 0) {
00950 return $result;
00951 } else {
00952 return true;
00953 }
00954 }
00955
00956
00957
00958
00959
00960
00961
00962 function getListOfTables() {
00963 $whichTables = $GLOBALS['TYPO3_DB']->admin_get_tables(TYPO3_db);
00964 foreach ($whichTables as $key=>&$value) {
00965 $value = $key;
00966 }
00967 return $whichTables;
00968 }
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981 function generateUpdateDatabaseForm_checkboxes($arr,$label,$checked=1,$iconDis=0,$currentValue=array(),$cVfullMsg=0) {
00982 $out = array();
00983 if (is_array($arr)) {
00984 $tableId = uniqid('table');
00985 if (count($arr) > 1) {
00986 $out[] = '
00987 <tr class="update-db-fields-batch">
00988 <td valign="top">
00989 <input type="checkbox" id="' . $tableId . '-checkbox"' . ($checked ? ' checked="checked"' : '') . '
00990 onclick="$(\'' . $tableId . '\').select(\'input[type=checkbox]\').invoke(\'setValue\', $(this).checked);" />
00991 </td>
00992 <td nowrap="nowrap"><label for="' . $tableId . '-checkbox" style="cursor:pointer"><strong>select/deselect all</strong></label></td>
00993 </tr>';
00994 }
00995 foreach($arr as $key => $string) {
00996 $ico = '';
00997 $warnings = array();
00998
00999 if ($iconDis) {
01000 if (preg_match('/^TRUNCATE/i',$string)) {
01001 $ico.= '<img src="'.$this->backPath.'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong> </strong>';
01002 $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.';
01003 } elseif (stristr($string,' user_')) {
01004 $ico.= '<img src="'.$this->backPath.'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(USER) </strong>';
01005 } elseif (stristr($string,' app_')) {
01006 $ico.= '<img src="'.$this->backPath.'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(APP) </strong>';
01007 } elseif (stristr($string,' ttx_') || stristr($string,' tx_')) {
01008 $ico.= '<img src="'.$this->backPath.'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(EXT) </strong>';
01009 }
01010 }
01011 $out[]='
01012 <tr>
01013 <td valign="top"><input type="checkbox" id="db-'.$key.'" name="'.$this->dbUpdateCheckboxPrefix.'['.$key.']" value="1"'.($checked?' checked="checked"':'').' /></td>
01014 <td nowrap="nowrap"><label for="db-'.$key.'">'.nl2br($ico.htmlspecialchars($string)).'</label></td>
01015 </tr>';
01016 if (isset($currentValue[$key])) {
01017 $out[]='
01018 <tr>
01019 <td valign="top"></td>
01020 <td nowrap="nowrap" style="color:#666666;">'.nl2br((!$cVfullMsg?"Current value: ":"").'<em>'.$currentValue[$key].'</em>').'</td>
01021 </tr>';
01022 }
01023 }
01024 if (count($warnings)) {
01025 $out[] = '
01026 <tr>
01027 <td valign="top"></td>
01028 <td style="color:#666666;"><em>' . implode('<br />',$warnings) . '</em></td>
01029 </tr>';
01030 }
01031
01032
01033 $content = '
01034 <!-- Update database fields / tables -->
01035 <h3>'.$label.'</h3>
01036 <table border="0" cellpadding="2" cellspacing="2" id="' . $tableId . '" class="update-db-fields">' . implode('', $out) . '
01037 </table>';
01038 }
01039
01040 return $content;
01041 }
01042
01043
01044
01045
01046
01047
01048
01049
01050 function getFieldDefinitions_sqlContent($fileContent) {
01051 t3lib_div::logDeprecatedFunction();
01052
01053 return $this->getFieldDefinitions_fileContent($fileContent);
01054 }
01055 }
01056
01057 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_install.php']) {
01058 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_install.php']);
01059 }
01060
01061 ?>