"TYPO3 4.0.1: typo3_src-4.0.1/t3lib/class.t3lib_install.php Source File", "datetime" => "Sat Dec 2 19:22:18 2006", "date" => "2 Dec 2006", "doxygenversion" => "1.4.6", "projectname" => "TYPO3 4.0.1", "projectnumber" => "4.0.1" ); get_header($doxygen_vars); ?>

class.t3lib_install.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00074 require_once(PATH_t3lib.'class.t3lib_sqlparser.php');
00075 
00083 class t3lib_install {
00084 
00085 
00086                 // External, Static
00087         var $updateIdentity = '';                                       // Set to string which identifies the script using this class.
00088         var $deletedPrefixKey = 'zzz_deleted_';         // Prefix used for tables/fields when deleted/renamed.
00089         var $dbUpdateCheckboxPrefix = 'TYPO3_INSTALL[database_update]'; // Prefix for checkbox fields when updating database.
00090         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.
00091         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
00092         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.
00093         var $backPath = '../';                          // Backpath (used for icons etc.)
00094 
00095         var $multiplySize = 1;                          // Multiplier of SQL field size (for char, varchar and text fields)
00096 
00097                 // Internal, dynamic:
00098         var $setLocalconf = 0;                          // Used to indicate that a value is change in the line-array of localconf and that it should be written.
00099         var $messages = array();                        // Used to set (error)messages from the executing functions like mail-sending, writing Localconf and such
00100         var $touchedLine = 0;                           // updated with line in localconf.php file that was changed.
00101 
00102 
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          * Writing to localconf.php
00119          *
00120 
00121          **************************************/
00122 
00132         function setValueInLocalconfFile(&$line_array, $variable, $value)       {
00133                 if (!$this->checkForBadString($value))  return 0;
00134 
00135                         // Initialize:
00136                 $found = 0;
00137                 $this->touchedLine = '';
00138                 $commentKey = '## ';
00139                 $inArray = in_array($commentKey.$this->localconf_editPointToken,$line_array);
00140                 $tokenSet = ($this->localconf_editPointToken && !$inArray);             // Flag is set if the token should be set but is not yet...
00141                 $stopAtToken = ($this->localconf_editPointToken && $inArray);
00142                 $comment = ' Modified or inserted by '.$this->updateIdentity.'.';
00143 
00144                         // Search for variable name:
00145                 if (!$this->localconf_addLinesOnly && !$tokenSet)       {
00146                         $line_array = array_reverse($line_array);
00147                         foreach($line_array as $k => $v)        {
00148                                 $v2 = trim($v);
00149                                 if ($stopAtToken && !strcmp($v2,$commentKey.$this->localconf_editPointToken))   break;          // If stopAtToken and token found, break out of the loop..
00150                                 if (!strcmp(substr($v2,0,strlen($variable.' ')),$variable.' ')) {
00151                                         $mainparts = explode($variable,$v,2);
00152                                         if (count($mainparts)==2)       {       // should ALWAYS be....
00153                                                 $subparts = explode('//',$mainparts[1],2);
00154                                                 $line_array[$k] = $mainparts[0].$variable." = '".$this->slashValueForSingleDashes($value)."';       ".('//'.$comment.str_replace($comment,'',$subparts[1]));
00155                                                 $this->touchedLine = count($line_array)-$k-1;
00156                                                 $found = 1;
00157                                                 break;
00158                                         }
00159                                 }
00160                         }
00161                         $line_array = array_reverse($line_array);
00162                 }
00163                 if (!$found)    {
00164                         if ($tokenSet)          {
00165                                 $line_array[] = $commentKey.$this->localconf_editPointToken;
00166                                 $line_array[] = '';
00167                         }
00168                         $line_array[] = $variable." = '".$this->slashValueForSingleDashes($value)."';   // ".$comment;
00169                         $this->touchedLine = -1;
00170                 }
00171                 $this->messages[] = $variable." = '".htmlspecialchars($value)."'";
00172                 $this->setLocalconf = 1;
00173         }
00174 
00183         function writeToLocalconf_control($inlines='',$absFullPath='')  {
00184                 $tmpExt = '.TMP.php';
00185                 $writeToLocalconf_dat['file'] = $absFullPath ? $absFullPath : PATH_typo3conf.'localconf.php';
00186                 $writeToLocalconf_dat['tmpfile'] = $writeToLocalconf_dat['file'].$tmpExt;
00187 
00188                         // Checking write state of localconf.php:
00189                 if (!$this->allowUpdateLocalConf)       {
00190                         die("->allowUpdateLocalConf flag in the install object is not set and therefore 'localconf.php' cannot be altered.");
00191                 }
00192                 if (!@is_writable($writeToLocalconf_dat['file']))       {
00193                         die($writeToLocalconf_dat['file'].' is not writable!');
00194                 }
00195 
00196                                 // Splitting localconf.php file into lines:
00197                 $lines = explode(chr(10),str_replace(chr(13),'',trim(t3lib_div::getUrl($writeToLocalconf_dat['file']))));
00198                 $writeToLocalconf_dat['endLine'] = array_pop($lines);   // Getting "? >" ending.
00199 
00200                         // Checking if "updated" line was set by this tool - if so remove old line.
00201                 $updatedLine = array_pop($lines);
00202                 $writeToLocalconf_dat['updatedText'] = '// Updated by '.$this->updateIdentity.' ';
00203                 if (!strstr($updatedLine, $writeToLocalconf_dat['updatedText']))        {
00204                         array_push($lines,$updatedLine);
00205                 }
00206 
00207                 if (is_array($inlines)) {       // Setting a line and write:
00208                                 // Setting configuration
00209                         $updatedLine = $writeToLocalconf_dat['updatedText'].date('d-m-Y H:i:s');
00210                         array_push($inlines,$updatedLine);
00211                         array_push($inlines,$writeToLocalconf_dat['endLine']);
00212 
00213                         if ($this->setLocalconf)        {
00214                                 $success = FALSE;
00215                                 if (!t3lib_div::writeFile($writeToLocalconf_dat['tmpfile'],implode(chr(10),$inlines)))  {
00216                                         $msg = 'typo3conf/localconf.php'.$tmpExt.' could not be written - maybe a write access problem?';
00217                                 }
00218                                 elseif (strcmp(t3lib_div::getUrl($writeToLocalconf_dat['tmpfile']), implode(chr(10),$inlines))) {
00219                                         @unlink($writeToLocalconf_dat['tmpfile']);
00220                                         $msg = 'typo3conf/localconf.php'.$tmpExt.' was NOT written properly (written content didn\'t match file content) - maybe a disk space problem?';
00221                                 }
00222                                 elseif (!@copy($writeToLocalconf_dat['tmpfile'],$writeToLocalconf_dat['file'])) {
00223                                         $msg = 'typo3conf/localconf.php could not be replaced by typo3conf/localconf.php'.$tmpExt.' - maybe a write access problem?';
00224                                 }
00225                                 else {
00226                                         @unlink($writeToLocalconf_dat['tmpfile']);
00227                                         $success = TRUE;
00228                                         $msg = 'Configuration written to typo3conf/localconf.php';
00229                                 }
00230                                 $this->messages[]= $msg;
00231 
00232                                 if ($success)   {
00233                                         return 'continue';
00234                                 } else {
00235                                         t3lib_div::sysLog($msg, 'Core', 3);
00236                                         return 'nochange';
00237                                 }
00238                         } else {
00239                                 return 'nochange';
00240                         }
00241                 } else {        // Return lines found in localconf.php
00242                         return $lines;
00243                 }
00244         }
00245 
00253         function checkForBadString($string)     {
00254                 return preg_match('/['.chr(10).chr(13).']/',$string) ? FALSE : TRUE;
00255         }
00256 
00264         function slashValueForSingleDashes($value)      {
00265                 $value = str_replace("'.chr(10).'", '###INSTALL_TOOL_LINEBREAK###', $value);
00266                 $value = str_replace("'","\'",str_replace('\\','\\\\',$value));
00267                 $value = str_replace('###INSTALL_TOOL_LINEBREAK###', "'.chr(10).'", $value);
00268 
00269                 return $value;
00270         }
00271 
00272 
00273 
00274 
00275 
00276 
00277 
00278 
00279 
00280 
00281         /*************************************
00282          *
00283          * SQL
00284          *
00285          *************************************/
00286 
00293         function getFieldDefinitions_sqlContent($sqlContent)    {
00294                 $lines = t3lib_div::trimExplode(chr(10), $sqlContent,1);
00295                 $isTable = '';
00296                 $total = Array();
00297 
00298                 foreach($lines as $value)       {
00299                         if ($value[0]!='#')     {
00300                                 if (!$isTable)  {
00301                                         $parts = explode(' ',$value);
00302                                         if ($parts[0]=='CREATE' && $parts[1]=='TABLE')  {
00303                                                 $isTable = str_replace( '`', '', $parts[2]);
00304                                                 if (TYPO3_OS=='WIN') {  // tablenames are always lowercase on windows!
00305                                                         $isTable = strtolower($isTable);
00306                                                 }
00307                                         }
00308                                 } else {
00309                                         if (substr($value,0,1)==')' && substr($value,-1)==';')  {
00310                                                 $ttype = array();
00311                                                 preg_match('/(ENGINE|TYPE)=([a-zA-Z]*)/',$value,$ttype);
00312                                                 $total[$isTable]['extra']['ttype'] = $ttype[2];
00313                                                 $isTable = '';
00314                                         } else {
00315                                                 $lineV = preg_replace('/,$/','',$value);
00316                                                 $lineV = str_replace('UNIQUE KEY', 'UNIQUE', $lineV);
00317                                                 $parts = explode(' ',$lineV,2);
00318 
00319                                                         // Make sure there is no default value when auto_increment is set
00320                                                 if(stristr($parts[1],'auto_increment')) {
00321                                                         $parts[1] = preg_replace('/ default \'0\'/i','',$parts[1]);
00322                                                 }
00323                                                         // "default" is always lower-case
00324                                                 if(strstr($parts[1], ' DEFAULT '))      {
00325                                                         $parts[1] = str_replace(' DEFAULT ', ' default ', $parts[1]);
00326                                                 }
00327 
00328                                                         // Change order of "default" and "null" statements
00329                                                 $parts[1] = preg_replace('/(.*) (default .*) (NOT NULL)/', '$1 $3 $2', $parts[1]);
00330                                                 $parts[1] = preg_replace('/(.*) (default .*) (NULL)/', '$1 $3 $2', $parts[1]);
00331 
00332                                                         // Remove double blanks
00333                                                 $parts[1] = preg_replace('/([^ ]+)[ ]+([^ ]+)/', '$1 $2', $parts[1]);
00334 
00335                                                 if ($parts[0]!='PRIMARY' && $parts[0]!='KEY' && $parts[0]!='UNIQUE')    {
00336                                                         $key = str_replace('`', '', $parts[0]);
00337                                                         $total[$isTable]['fields'][$key] = $parts[1];
00338                                                 } else {
00339                                                         $newParts = explode(' ',$parts[1],2);
00340                                                         $key = str_replace('`', '', ($parts[0]=='PRIMARY'?$parts[0]:$newParts[0]));
00341                                                         $total[$isTable]['keys'][$key] = str_replace('`', '', $lineV);
00342                                                 }
00343                                         }
00344                                 }
00345                         }
00346                 }
00347 
00348                 $this->getFieldDefinitions_sqlContent_parseTypes($total);
00349                 return $total;
00350         }
00351 
00361         function getFieldDefinitions_sqlContent_parseTypes(&$total)     {
00362 
00363                 $mSize = (double)$this->multiplySize;
00364                 if ($mSize > 1) {
00365 
00366                                 // Init SQL parser:
00367                         $sqlParser = t3lib_div::makeInstance('t3lib_sqlparser');
00368                         foreach($total as $table => $cfg)       {
00369                                 if (is_array($cfg['fields'])) {
00370                                         foreach($cfg['fields'] as $fN => $fType)        {
00371                                                 $orig_fType = $fType;
00372                                                 $fInfo = $sqlParser->parseFieldDef($fType);
00373 
00374                                                 switch($fInfo['fieldType'])     {
00375                                                         case 'char':
00376                                                         case 'varchar':
00377                                                                 $newSize = round($fInfo['value']*$mSize);
00378 
00379                                                                 if ($newSize <= 255)    {
00380                                                                         $fInfo['value'] = $newSize;
00381                                                                 } else {
00382                                                                         $fInfo = array(
00383                                                                                 'fieldType' => 'text',
00384                                                                                 'featureIndex' => array(
00385                                                                                         'NOTNULL' => array(
00386                                                                                                 'keyword' => 'NOT NULL'
00387                                                                                         )
00388                                                                                 )
00389                                                                         );
00390                                                                 }
00391                                                         break;
00392                                                         case 'tinytext':
00393                                                                 $fInfo['fieldType'] = 'text';
00394                                                         break;
00395                                                 }
00396 
00397                                                 $total[$table]['fields'][$fN] = $sqlParser->compileFieldCfg($fInfo);
00398                                                 if ($sqlParser->parse_error)    die($sqlParser->parse_error);
00399                                         }
00400                                 }
00401                         }
00402                 }
00403         }
00404 
00410         function getFieldDefinitions_database() {
00411                 $total = array();
00412                 $GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db);
00413                 echo $GLOBALS['TYPO3_DB']->sql_error();
00414 
00415                 $tables = $GLOBALS['TYPO3_DB']->admin_get_tables(TYPO3_db);
00416                 foreach($tables as $tableName)  {
00417 
00418                                 // Fields:
00419                         $fieldInformation = $GLOBALS['TYPO3_DB']->admin_get_fields($tableName);
00420                         foreach($fieldInformation as $fN => $fieldRow)  {
00421                                 $total[$tableName]['fields'][$fN] = $this->assembleFieldDefinition($fieldRow);
00422                         }
00423 
00424                                 // Keys:
00425                         $keyInformation = $GLOBALS['TYPO3_DB']->admin_get_keys($tableName);
00426                         foreach($keyInformation as $kN => $keyRow)      {
00427                                 $tempKeys[$tableName][$keyRow['Key_name']][$keyRow['Seq_in_index']] = $keyRow['Column_name'];
00428                                 $tempKeysPrefix[$tableName][$keyRow['Key_name']]= ($keyRow['Key_name']=='PRIMARY'?'PRIMARY KEY':($keyRow['Non_unique']?'KEY':'UNIQUE').' '.$keyRow['Key_name']);
00429                         }
00430                 }
00431 
00432                         // Compile information:
00433                 if (is_array($tempKeys))        {
00434                         foreach($tempKeys as $table => $keyInf) {
00435                                 foreach($keyInf as $kName => $index) {
00436                                         ksort($index);
00437                                         $total[$table]['keys'][$kName] = $tempKeysPrefix[$table][$kName].' ('.implode(',',$index).')';
00438                                 }
00439                         }
00440                 }
00441 
00442                 return $total;
00443         }
00444 
00455         function getDatabaseExtra($FDsrc, $FDcomp, $onlyTableList='',$ignoreNotNullWhenComparing=true)  {
00456                 $extraArr = array();
00457                 $diffArr = array();
00458 
00459                 if (is_array($FDsrc))   {
00460                         foreach($FDsrc as $table => $info) {
00461                                 if (!strlen($onlyTableList) || t3lib_div::inList($onlyTableList, $table))       {
00462                                         if (!isset($FDcomp[$table]))    {
00463                                                 $extraArr[$table] = $info;              // If the table was not in the FDcomp-array, the result array is loaded with that table.
00464                                                 $extraArr[$table]['whole_table']=1;
00465                                         } else {
00466                                                 $keyTypes = explode(',','fields,keys');
00467                                                 foreach($keyTypes as $theKey)   {
00468                                                         if (is_array($info[$theKey]))   {
00469                                                                 foreach($info[$theKey] as $fieldN => $fieldC)   {
00470                                                                         $fieldN = str_replace('`','',$fieldN);
00471                                                                         if (!isset($FDcomp[$table][$theKey][$fieldN]))  {
00472                                                                                 $extraArr[$table][$theKey][$fieldN] = $fieldC;
00473                                                                         } elseif (strcmp($FDcomp[$table][$theKey][$fieldN], $ignoreNotNullWhenComparing?str_replace(' NOT NULL', '', $fieldC):$fieldC)) {
00474                                                                                 $diffArr[$table][$theKey][$fieldN] = $fieldC;
00475                                                                                 $diffArr_cur[$table][$theKey][$fieldN] = $FDcomp[$table][$theKey][$fieldN];
00476                                                                         }
00477                                                                 }
00478                                                         }
00479                                                 }
00480                                         }
00481                                 }
00482                         }
00483                 }
00484 
00485                 $output = array(
00486                         'extra' => $extraArr,
00487                         'diff' => $diffArr,
00488                         'diff_currentValues' => $diffArr_cur
00489                 );
00490 
00491                 return $output;
00492         }
00493 
00501         function getUpdateSuggestions($diffArr,$keyList='extra,diff')   {
00502                 $statements = array();
00503                 $deletedPrefixKey = $this->deletedPrefixKey;
00504                 $remove = 0;
00505                 if ($keyList == 'remove')       {
00506                         $remove = 1;
00507                         $keyList = 'extra';
00508                 }
00509                 $keyList = explode(',',$keyList);
00510                 foreach($keyList as $theKey)    {
00511                         if (is_array($diffArr[$theKey]))        {
00512                                 foreach($diffArr[$theKey] as $table => $info) {
00513                                         $whole_table = array();
00514                                         if (is_array($info['fields']))  {
00515                                                 foreach($info['fields'] as $fN => $fV) {
00516                                                         if ($info['whole_table'])       {
00517                                                                 $whole_table[]=$fN.' '.$fV;
00518                                                         } else {
00519                                                                 if ($theKey=='extra')   {
00520                                                                         if ($remove)    {
00521                                                                                 if (substr($fN,0,strlen($deletedPrefixKey))!=$deletedPrefixKey) {
00522                                                                                         $statement = 'ALTER TABLE '.$table.' CHANGE '.$fN.' '.$deletedPrefixKey.$fN.' '.$fV.';';
00523                                                                                         $statements['change'][md5($statement)] = $statement;
00524                                                                                 } else {
00525                                                                                         $statement = 'ALTER TABLE '.$table.' DROP '.$fN.';';
00526                                                                                         $statements['drop'][md5($statement)] = $statement;
00527                                                                                 }
00528                                                                         } else {
00529                                                                                 $statement = 'ALTER TABLE '.$table.' ADD '.$fN.' '.$fV.';';
00530                                                                                 $statements['add'][md5($statement)] = $statement;
00531                                                                         }
00532                                                                 } elseif ($theKey=='diff')      {
00533                                                                         $statement = 'ALTER TABLE '.$table.' CHANGE '.$fN.' '.$fN.' '.$fV.';';
00534                                                                         $statements['change'][md5($statement)] = $statement;
00535                                                                         $statements['change_currentValue'][md5($statement)] = $diffArr['diff_currentValues'][$table]['fields'][$fN];
00536                                                                 }
00537                                                         }
00538                                                 }
00539                                         }
00540                                         if (is_array($info['keys']))    {
00541                                                 foreach($info['keys'] as $fN => $fV) {
00542                                                         if ($info['whole_table'])       {
00543                                                                 $whole_table[] = $fV;
00544                                                         } else {
00545                                                                 if ($theKey=='extra')   {
00546                                                                         if ($remove)    {
00547                                                                                 $statement = 'ALTER TABLE '.$table.($fN=='PRIMARY' ? ' DROP PRIMARY KEY' : ' DROP KEY '.$fN).';';
00548                                                                                 $statements['drop'][md5($statement)] = $statement;
00549                                                                         } else {
00550                                                                                 $statement = 'ALTER TABLE '.$table.' ADD '.$fV.';';
00551                                                                                 $statements['add'][md5($statement)] = $statement;
00552                                                                         }
00553                                                                 } elseif ($theKey=='diff') {
00554                                                                         $statement = 'ALTER TABLE '.$table.($fN=='PRIMARY' ? ' DROP PRIMARY KEY' : ' DROP KEY '.$fN).';';
00555                                                                         $statements['change'][md5($statement)] = $statement;
00556                                                                         $statement = 'ALTER TABLE '.$table.' ADD '.$fV.';';
00557                                                                         $statements['change'][md5($statement)] = $statement;
00558                                                                 }
00559                                                         }
00560                                                 }
00561                                         }
00562                                         if ($info['whole_table'])       {
00563                                                 if ($remove)    {
00564                                                         if (substr($table,0,strlen($deletedPrefixKey))!=$deletedPrefixKey)      {
00565                                                                 $statement = 'ALTER TABLE '.$table.' RENAME '.$deletedPrefixKey.$table.';';
00566                                                                 $statements['change_table'][md5($statement)]=$statement;
00567                                                         } else {
00568                                                                 $statement = 'DROP TABLE '.$table.';';
00569                                                                 $statements['drop_table'][md5($statement)]=$statement;
00570                                                         }
00571                                                         // count:
00572                                                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', $table, '');
00573                                                         list($count) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00574                                                         $statements['tables_count'][md5($statement)] = $count?'Records in table: '.$count:'';
00575                                                 } else {
00576                                                         $statement = 'CREATE TABLE '.$table." (\n".implode(",\n",$whole_table)."\n)";
00577                                                         $statement .= ($info['extra']['ttype']) ? ' TYPE='.$info['extra']['ttype'].';' : ';';
00578                                                         $statements['create_table'][md5($statement)]=$statement;
00579                                                 }
00580                                         }
00581                                 }
00582                         }
00583                 }
00584 
00585                 return $statements;
00586         }
00587 
00594         function assembleFieldDefinition($row)  {
00595                 $field[] = $row['Type'];
00596                 // if (!$row['Null'])   { $field[] = 'NOT NULL'; }
00597                 if (!strstr($row['Type'],'blob') && !strstr($row['Type'],'text'))       {
00598                                 // Add a default value if the field is not auto-incremented (these fields never have a default definition).
00599                         if (!stristr($row['Extra'],'auto_increment'))   {
00600                                 $field[] = 'default '."'".(addslashes($row['Default']))."'";
00601                         }
00602                 }
00603                 if ($row['Extra'])      { $field[] = $row['Extra']; }
00604 
00605                 return implode(' ',$field);
00606         }
00607 
00616         function getStatementArray($sqlcode,$removeNonSQL=0,$query_regex='')    {
00617                 $sqlcodeArr = explode(chr(10),$sqlcode);
00618 
00619                 // Based on the assumption that the sql-dump has
00620                 $statementArray = array();
00621                 $statementArrayPointer = 0;
00622 
00623                 foreach($sqlcodeArr as $line => $linecontent)   {
00624                         $is_set = 0;
00625                         if(stristr($linecontent,'auto_increment')) {
00626                                 $linecontent = eregi_replace(' default \'0\'','',$linecontent);
00627                         }
00628 
00629                         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
00630                                 $statementArray[$statementArrayPointer].= $linecontent;
00631                                 $is_set = 1;
00632                         }
00633                         if (substr(trim($linecontent),-1)==';') {
00634                                 if (isset($statementArray[$statementArrayPointer]))     {
00635                                         if (!trim($statementArray[$statementArrayPointer]) || ($query_regex && !eregi($query_regex,trim($statementArray[$statementArrayPointer]))))     {
00636                                                 unset($statementArray[$statementArrayPointer]);
00637                                         }
00638                                 }
00639                                 $statementArrayPointer++;
00640                         } elseif ($is_set) {
00641                                 $statementArray[$statementArrayPointer].=chr(10);
00642                         }
00643                 }
00644                 return $statementArray;
00645         }
00646 
00654         function getCreateTables($statements, $insertCountFlag=0)       {
00655                 $crTables = array();
00656                 $insertCount = array();
00657                 foreach($statements as $line => $linecontent)   {
00658                         $reg = array();
00659                         if (eregi('^create[[:space:]]*table[[:space:]]*[`]?([[:alnum:]_]*)[`]?',substr($linecontent,0,100),$reg))       {
00660                                 $table = trim($reg[1]);
00661                                 if ($table)     {
00662                                         if (TYPO3_OS=='WIN')    { $table=strtolower($table); }  // table names are always lowercase on Windows!
00663                                         $sqlLines = explode(chr(10), $linecontent);
00664                                         foreach($sqlLines as $k=>$v)    {
00665                                                 if(stristr($v,'auto_increment')) {
00666                                                         $sqlLines[$k] = eregi_replace(' default \'0\'','',$v);
00667                                                 }
00668                                         }
00669                                         $linecontent = implode(chr(10), $sqlLines);
00670                                         $crTables[$table] = $linecontent;
00671                                 }
00672                         } elseif ($insertCountFlag && eregi('^insert[[:space:]]*into[[:space:]]*[`]?([[:alnum:]_]*)[`]?',substr($linecontent,0,100),$reg))      {
00673                                 $nTable = trim($reg[1]);
00674                                 $insertCount[$nTable]++;
00675                         }
00676                 }
00677 
00678                 return array($crTables,$insertCount);
00679         }
00680 
00688         function getTableInsertStatements($statements, $table)  {
00689                 $outStatements=array();
00690                 foreach($statements as $line => $linecontent)   {
00691                         $reg = array();
00692                         if (preg_match('/^insert[[:space:]]*into[[:space:]]*[`]?([[:alnum:]_]*)[`]?/i',substr($linecontent,0,100),$reg))        {
00693                                 $nTable = trim($reg[1]);
00694                                 if ($nTable && !strcmp($table,$nTable)) {
00695                                         $outStatements[]=$linecontent;
00696                                 }
00697                         }
00698                 }
00699                 return $outStatements;
00700         }
00701 
00709         function performUpdateQueries($arr,$keyArr)     {
00710                 if (is_array($arr))     {
00711                         foreach($arr as $key => $string)        {
00712                                 if (isset($keyArr[$key]) && $keyArr[$key])      {
00713                                         $GLOBALS['TYPO3_DB']->admin_query($string);
00714                                 }
00715                         }
00716                 }
00717         }
00718 
00725         function getListOfTables()      {
00726                 $whichTables = $GLOBALS['TYPO3_DB']->admin_get_tables(TYPO3_db);
00727                 return $whichTables;
00728         }
00729 
00741         function generateUpdateDatabaseForm_checkboxes($arr,$label,$checked=1,$iconDis=0,$currentValue=array(),$cVfullMsg=0)    {
00742                 $out = array();
00743                 if (is_array($arr))     {
00744                         foreach($arr as $key => $string)        {
00745                                 $ico = '';
00746                                 if ($iconDis)   {
00747                                         if (stristr($string,' user_'))  {
00748                                                 $ico.= '<img src="'.$this->backPath.'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(USER) </strong>';
00749                                         }
00750                                         if (stristr($string,' app_'))   {
00751                                                 $ico.= '<img src="'.$this->backPath.'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(APP) </strong>';
00752                                         }
00753                                         if (stristr($string,' ttx_') || stristr($string,' tx_'))        {
00754                                                 $ico.= '<img src="'.$this->backPath.'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(EXT) </strong>';
00755                                         }
00756                                 }
00757                                 $out[]='
00758                                         <tr>
00759                                                 <td valign="top"><input type="checkbox" id="db-'.$key.'" name="'.$this->dbUpdateCheckboxPrefix.'['.$key.']" value="1"'.($checked?' checked="checked"':'').' /></td>
00760                                                 <td nowrap="nowrap"><label for="db-'.$key.'">'.nl2br($ico.htmlspecialchars($string)).'</label></td>
00761                                         </tr>';
00762                                 if (isset($currentValue[$key])) {
00763                                         $out[]='
00764                                         <tr>
00765                                                 <td valign="top"></td>
00766                                                 <td nowrap="nowrap" style="color : #666666;">'.nl2br((!$cVfullMsg?"Current value: ":"").'<em>'.$currentValue[$key].'</em>').'</td>
00767                                         </tr>';
00768                                 }
00769                         }
00770 
00771                         // Compile rows:
00772                         $content = '
00773                                 <!-- Update database fields / tables -->
00774                                 <h3>'.$label.'</h3>
00775                                 <table border="0" cellpadding="2" cellspacing="2" class="update-db-fields">'.implode('',$out).'
00776                                 </table>';
00777                 }
00778 
00779                 return $content;
00780         }
00781 }
00782 
00783 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_install.php'])   {
00784         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_install.php']);
00785 }
00786 ?>