Documentation TYPO3 par Ameos

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 
00297                 foreach($lines as $value)       {
00298                         if ($value[0]!='#')     {
00299                                 if (!$isTable)  {
00300                                         $parts = explode(' ',$value);
00301                                         if ($parts[0]=='CREATE' && $parts[1]=='TABLE')  {
00302                                                 $isTable = str_replace( '`', '', $parts[2]);
00303                                                 if (TYPO3_OS=='WIN') {  // tablenames are always lowercase on windows!
00304                                                         $isTable = strtolower($isTable);
00305                                                 }
00306                                         }
00307                                 } else {
00308                                         if (substr($value,0,1)==')' && substr($value,-1)==';')  {
00309                                                 $ttype = array();
00310                                                 preg_match('/(ENGINE|TYPE)=([a-zA-Z]*)/',$value,$ttype);
00311                                                 $total[$isTable]['extra']['ttype'] = $ttype[2];
00312                                                 $isTable = '';
00313                                         } else {
00314                                                 $lineV = preg_replace('/,$/','',$value);
00315                                                 $lineV = str_replace('UNIQUE KEY', 'UNIQUE', $lineV);
00316                                                 $parts = explode(' ',$lineV,2);
00317 
00318                                                         // Make sure there is no default value when auto_increment is set
00319                                                 if(stristr($parts[1],'auto_increment')) {
00320                                                         $parts[1] = preg_replace('/ default \'0\'/i','',$parts[1]);
00321                                                 }
00322                                                         // "default" is always lower-case
00323                                                 if(strstr($parts[1], ' DEFAULT '))      {
00324                                                         $parts[1] = str_replace(' DEFAULT ', ' default ', $parts[1]);
00325                                                 }
00326 
00327                                                         // Change order of "default" and "null" statements
00328                                                 $parts[1] = preg_replace('/(.*) (default .*) (NOT NULL)/', '$1 $3 $2', $parts[1]);
00329                                                 $parts[1] = preg_replace('/(.*) (default .*) (NULL)/', '$1 $3 $2', $parts[1]);
00330 
00331                                                         // Remove double blanks
00332                                                 $parts[1] = preg_replace('/([^ ]+)[ ]+([^ ]+)/', '$1 $2', $parts[1]);
00333 
00334                                                 if ($parts[0]!='PRIMARY' && $parts[0]!='KEY' && $parts[0]!='UNIQUE')    {
00335                                                         $key = str_replace('`', '', $parts[0]);
00336                                                         $total[$isTable]['fields'][$key] = $parts[1];
00337                                                 } else {
00338                                                         $newParts = explode(' ',$parts[1],2);
00339                                                         $key = str_replace('`', '', ($parts[0]=='PRIMARY'?$parts[0]:$newParts[0]));
00340                                                         $total[$isTable]['keys'][$key] = str_replace('`', '', $lineV);
00341                                                 }
00342                                         }
00343                                 }
00344                         }
00345                 }
00346 
00347                 $this->getFieldDefinitions_sqlContent_parseTypes($total);
00348                 return $total;
00349         }
00350 
00360         function getFieldDefinitions_sqlContent_parseTypes(&$total)     {
00361 
00362                 $mSize = (double)$this->multiplySize;
00363                 if ($mSize > 1) {
00364 
00365                                 // Init SQL parser:
00366                         $sqlParser = t3lib_div::makeInstance('t3lib_sqlparser');
00367                         foreach($total as $table => $cfg)       {
00368                                 foreach($cfg['fields'] as $fN => $fType)        {
00369                                         $orig_fType = $fType;
00370                                         $fInfo = $sqlParser->parseFieldDef($fType);
00371 
00372                                         switch($fInfo['fieldType'])     {
00373                                                 case 'char':
00374                                                 case 'varchar':
00375                                                         $newSize = round($fInfo['value']*$mSize);
00376 
00377                                                         if ($newSize <= 255)    {
00378                                                                 $fInfo['value'] = $newSize;
00379                                                         } else {
00380                                                                 $fInfo = array(
00381                                                                         'fieldType' => 'text',
00382                                                                         'featureIndex' => array(
00383                                                                                 'NOTNULL' => array(
00384                                                                                         'keyword' => 'NOT NULL'
00385                                                                                 )
00386                                                                         )
00387                                                                 );
00388                                                         }
00389                                                 break;
00390                                                 case 'tinytext':
00391                                                         $fInfo['fieldType'] = 'text';
00392                                                 break;
00393                                         }
00394 
00395                                         $total[$table]['fields'][$fN] = $sqlParser->compileFieldCfg($fInfo);
00396                                         if ($sqlParser->parse_error)    die($sqlParser->parse_error);
00397                                 }
00398                         }
00399                 }
00400         }
00401 
00407         function getFieldDefinitions_database() {
00408                 $total = array();
00409                 $GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db);
00410                 echo $GLOBALS['TYPO3_DB']->sql_error();
00411 
00412                 $tables = $GLOBALS['TYPO3_DB']->admin_get_tables(TYPO3_db);
00413                 foreach($tables as $tableName)  {
00414 
00415                                 // Fields:
00416                         $fieldInformation = $GLOBALS['TYPO3_DB']->admin_get_fields($tableName);
00417                         foreach($fieldInformation as $fN => $fieldRow)  {
00418                                 $total[$tableName]['fields'][$fN] = $this->assembleFieldDefinition($fieldRow);
00419                         }
00420 
00421                                 // Keys:
00422                         $keyInformation = $GLOBALS['TYPO3_DB']->admin_get_keys($tableName);
00423                         foreach($keyInformation as $kN => $keyRow)      {
00424                                 $tempKeys[$tableName][$keyRow['Key_name']][$keyRow['Seq_in_index']] = $keyRow['Column_name'];
00425                                 $tempKeysPrefix[$tableName][$keyRow['Key_name']]= ($keyRow['Key_name']=='PRIMARY'?'PRIMARY KEY':($keyRow['Non_unique']?'KEY':'UNIQUE').' '.$keyRow['Key_name']);
00426                         }
00427                 }
00428 
00429                         // Compile information:
00430                 if (is_array($tempKeys))        {
00431                         foreach($tempKeys as $table => $keyInf) {
00432                                 foreach($keyInf as $kName => $index) {
00433                                         ksort($index);
00434                                         $total[$table]['keys'][$kName] = $tempKeysPrefix[$table][$kName].' ('.implode(',',$index).')';
00435                                 }
00436                         }
00437                 }
00438 
00439                 return $total;
00440         }
00441 
00452         function getDatabaseExtra($FDsrc, $FDcomp, $onlyTableList='',$ignoreNotNullWhenComparing=true)  {
00453                 $extraArr = array();
00454                 $diffArr = array();
00455 
00456                 if (is_array($FDsrc))   {
00457                         foreach($FDsrc as $table => $info) {
00458                                 if (!strlen($onlyTableList) || t3lib_div::inList($onlyTableList, $table))       {
00459                                         if (!isset($FDcomp[$table]))    {
00460                                                 $extraArr[$table] = $info;              // If the table was not in the FDcomp-array, the result array is loaded with that table.
00461                                                 $extraArr[$table]['whole_table']=1;
00462                                         } else {
00463                                                 $keyTypes = explode(',','fields,keys');
00464                                                 foreach($keyTypes as $theKey)   {
00465                                                         if (is_array($info[$theKey]))   {
00466                                                                 foreach($info[$theKey] as $fieldN => $fieldC)   {
00467                                                                         $fieldN = str_replace('`','',$fieldN);
00468                                                                         if (!isset($FDcomp[$table][$theKey][$fieldN]))  {
00469                                                                                 $extraArr[$table][$theKey][$fieldN] = $fieldC;
00470                                                                         } elseif (strcmp($FDcomp[$table][$theKey][$fieldN], $ignoreNotNullWhenComparing?str_replace(' NOT NULL', '', $fieldC):$fieldC)) {
00471                                                                                 $diffArr[$table][$theKey][$fieldN] = $fieldC;
00472                                                                                 $diffArr_cur[$table][$theKey][$fieldN] = $FDcomp[$table][$theKey][$fieldN];
00473                                                                         }
00474                                                                 }
00475                                                         }
00476                                                 }
00477                                         }
00478                                 }
00479                         }
00480                 }
00481 
00482                 $output = array(
00483                         'extra' => $extraArr,
00484                         'diff' => $diffArr,
00485                         'diff_currentValues' => $diffArr_cur
00486                 );
00487 
00488                 return $output;
00489         }
00490 
00498         function getUpdateSuggestions($diffArr,$keyList='extra,diff')   {
00499                 $statements = array();
00500                 $deletedPrefixKey = $this->deletedPrefixKey;
00501                 $remove = 0;
00502                 if ($keyList == 'remove')       {
00503                         $remove = 1;
00504                         $keyList = 'extra';
00505                 }
00506                 $keyList = explode(',',$keyList);
00507                 foreach($keyList as $theKey)    {
00508                         if (is_array($diffArr[$theKey]))        {
00509                                 foreach($diffArr[$theKey] as $table => $info) {
00510                                         $whole_table = array();
00511                                         if (is_array($info['fields']))  {
00512                                                 foreach($info['fields'] as $fN => $fV) {
00513                                                         if ($info['whole_table'])       {
00514                                                                 $whole_table[]=$fN.' '.$fV;
00515                                                         } else {
00516                                                                 if ($theKey=='extra')   {
00517                                                                         if ($remove)    {
00518                                                                                 if (substr($fN,0,strlen($deletedPrefixKey))!=$deletedPrefixKey) {
00519                                                                                         $statement = 'ALTER TABLE '.$table.' CHANGE '.$fN.' '.$deletedPrefixKey.$fN.' '.$fV.';';
00520                                                                                         $statements['change'][md5($statement)] = $statement;
00521                                                                                 } else {
00522                                                                                         $statement = 'ALTER TABLE '.$table.' DROP '.$fN.';';
00523                                                                                         $statements['drop'][md5($statement)] = $statement;
00524                                                                                 }
00525                                                                         } else {
00526                                                                                 $statement = 'ALTER TABLE '.$table.' ADD '.$fN.' '.$fV.';';
00527                                                                                 $statements['add'][md5($statement)] = $statement;
00528                                                                         }
00529                                                                 } elseif ($theKey=='diff')      {
00530                                                                         $statement = 'ALTER TABLE '.$table.' CHANGE '.$fN.' '.$fN.' '.$fV.';';
00531                                                                         $statements['change'][md5($statement)] = $statement;
00532                                                                         $statements['change_currentValue'][md5($statement)] = $diffArr['diff_currentValues'][$table]['fields'][$fN];
00533                                                                 }
00534                                                         }
00535                                                 }
00536                                         }
00537                                         if (is_array($info['keys']))    {
00538                                                 foreach($info['keys'] as $fN => $fV) {
00539                                                         if ($info['whole_table'])       {
00540                                                                 $whole_table[] = $fV;
00541                                                         } else {
00542                                                                 if ($theKey=='extra')   {
00543                                                                         if ($remove)    {
00544                                                                                 $statement = 'ALTER TABLE '.$table.($fN=='PRIMARY' ? ' DROP PRIMARY KEY' : ' DROP KEY '.$fN).';';
00545                                                                                 $statements['drop'][md5($statement)] = $statement;
00546                                                                         } else {
00547                                                                                 $statement = 'ALTER TABLE '.$table.' ADD '.$fV.';';
00548                                                                                 $statements['add'][md5($statement)] = $statement;
00549                                                                         }
00550                                                                 } elseif ($theKey=='diff') {
00551                                                                         $statement = 'ALTER TABLE '.$table.($fN=='PRIMARY' ? ' DROP PRIMARY KEY' : ' DROP KEY '.$fN).';';
00552                                                                         $statements['change'][md5($statement)] = $statement;
00553                                                                         $statement = 'ALTER TABLE '.$table.' ADD '.$fV.';';
00554                                                                         $statements['change'][md5($statement)] = $statement;
00555                                                                 }
00556                                                         }
00557                                                 }
00558                                         }
00559                                         if ($info['whole_table'])       {
00560                                                 if ($remove)    {
00561                                                         if (substr($table,0,strlen($deletedPrefixKey))!=$deletedPrefixKey)      {
00562                                                                 $statement = 'ALTER TABLE '.$table.' RENAME '.$deletedPrefixKey.$table.';';
00563                                                                 $statements['change_table'][md5($statement)]=$statement;
00564                                                         } else {
00565                                                                 $statement = 'DROP TABLE '.$table.';';
00566                                                                 $statements['drop_table'][md5($statement)]=$statement;
00567                                                         }
00568                                                         // count:
00569                                                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', $table, '');
00570                                                         list($count) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00571                                                         $statements['tables_count'][md5($statement)] = $count?'Records in table: '.$count:'';
00572                                                 } else {
00573                                                         $statement = 'CREATE TABLE '.$table." (\n".implode(",\n",$whole_table)."\n)";
00574                                                         $statement .= ($info['extra']['ttype']) ? ' TYPE='.$info['extra']['ttype'].';' : ';';
00575                                                         $statements['create_table'][md5($statement)]=$statement;
00576                                                 }
00577                                         }
00578                                 }
00579                         }
00580                 }
00581 
00582                 return $statements;
00583         }
00584 
00591         function assembleFieldDefinition($row)  {
00592                 $field[] = $row['Type'];
00593                 // if (!$row['Null'])   { $field[] = 'NOT NULL'; }
00594                 if (!strstr($row['Type'],'blob') && !strstr($row['Type'],'text'))       {
00595                                 // Add a default value if the field is not auto-incremented (these fields never have a default definition).
00596                         if (!stristr($row['Extra'],'auto_increment'))   {
00597                                 $field[] = 'default '."'".(addslashes($row['Default']))."'";
00598                         }
00599                 }
00600                 if ($row['Extra'])      { $field[] = $row['Extra']; }
00601 
00602                 return implode(' ',$field);
00603         }
00604 
00613         function getStatementArray($sqlcode,$removeNonSQL=0,$query_regex='')    {
00614                 $sqlcodeArr = explode(chr(10),$sqlcode);
00615 
00616                 // Based on the assumption that the sql-dump has
00617                 $statementArray = array();
00618                 $statementArrayPointer = 0;
00619 
00620                 foreach($sqlcodeArr as $line => $linecontent)   {
00621                         $is_set = 0;
00622                         if(stristr($linecontent,'auto_increment')) {
00623                                 $linecontent = eregi_replace(' default \'0\'','',$linecontent);
00624                         }
00625 
00626                         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
00627                                 $statementArray[$statementArrayPointer].= $linecontent;
00628                                 $is_set = 1;
00629                         }
00630                         if (substr(trim($linecontent),-1)==';') {
00631                                 if (isset($statementArray[$statementArrayPointer]))     {
00632                                         if (!trim($statementArray[$statementArrayPointer]) || ($query_regex && !eregi($query_regex,trim($statementArray[$statementArrayPointer]))))     {
00633                                                 unset($statementArray[$statementArrayPointer]);
00634                                         }
00635                                 }
00636                                 $statementArrayPointer++;
00637                         } elseif ($is_set) {
00638                                 $statementArray[$statementArrayPointer].=chr(10);
00639                         }
00640                 }
00641                 return $statementArray;
00642         }
00643 
00651         function getCreateTables($statements, $insertCountFlag=0)       {
00652                 $crTables = array();
00653                 $insertCount = array();
00654                 foreach($statements as $line => $linecontent)   {
00655                         $reg = array();
00656                         if (eregi('^create[[:space:]]*table[[:space:]]*[`]?([[:alnum:]_]*)[`]?',substr($linecontent,0,100),$reg))       {
00657                                 $table = trim($reg[1]);
00658                                 if ($table)     {
00659                                         if (TYPO3_OS=='WIN')    { $table=strtolower($table); }  // table names are always lowercase on Windows!
00660                                         $sqlLines = explode(chr(10), $linecontent);
00661                                         foreach($sqlLines as $k=>$v)    {
00662                                                 if(stristr($v,'auto_increment')) {
00663                                                         $sqlLines[$k] = eregi_replace(' default \'0\'','',$v);
00664                                                 }
00665                                         }
00666                                         $linecontent = implode(chr(10), $sqlLines);
00667                                         $crTables[$table] = $linecontent;
00668                                 }
00669                         } elseif ($insertCountFlag && eregi('^insert[[:space:]]*into[[:space:]]*[`]?([[:alnum:]_]*)[`]?',substr($linecontent,0,100),$reg))      {
00670                                 $nTable = trim($reg[1]);
00671                                 $insertCount[$nTable]++;
00672                         }
00673                 }
00674 
00675                 return array($crTables,$insertCount);
00676         }
00677 
00685         function getTableInsertStatements($statements, $table)  {
00686                 $outStatements=array();
00687                 foreach($statements as $line => $linecontent)   {
00688                         $reg = array();
00689                         if (eregi('^insert[[:space:]]*into[[:space:]]*[`]?([[:alnum:]_]*)[`]?',substr($linecontent,0,100),$reg))        {
00690                                 $nTable = trim($reg[1]);
00691                                 if ($nTable && !strcmp($table,$nTable)) {
00692                                         $outStatements[]=$linecontent;
00693                                 }
00694                         }
00695                 }
00696                 return $outStatements;
00697         }
00698 
00706         function performUpdateQueries($arr,$keyArr)     {
00707                 if (is_array($arr))     {
00708                         foreach($arr as $key => $string)        {
00709                                 if (isset($keyArr[$key]) && $keyArr[$key])      {
00710                                         $GLOBALS['TYPO3_DB']->admin_query($string);
00711                                 }
00712                         }
00713                 }
00714         }
00715 
00722         function getListOfTables()      {
00723                 $whichTables = $GLOBALS['TYPO3_DB']->admin_get_tables(TYPO3_db);
00724                 return $whichTables;
00725         }
00726 
00738         function generateUpdateDatabaseForm_checkboxes($arr,$label,$checked=1,$iconDis=0,$currentValue=array(),$cVfullMsg=0)    {
00739                 $out = array();
00740                 if (is_array($arr))     {
00741                         foreach($arr as $key => $string)        {
00742                                 $ico = '';
00743                                 if ($iconDis)   {
00744                                         if (stristr($string,' user_'))  {
00745                                                 $ico.= '<img src="'.$this->backPath.'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(USER) </strong>';
00746                                         }
00747                                         if (stristr($string,' app_'))   {
00748                                                 $ico.= '<img src="'.$this->backPath.'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(APP) </strong>';
00749                                         }
00750                                         if (stristr($string,' ttx_') || stristr($string,' tx_'))        {
00751                                                 $ico.= '<img src="'.$this->backPath.'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(EXT) </strong>';
00752                                         }
00753                                 }
00754                                 $out[]='
00755                                         <tr>
00756                                                 <td valign="top"><input type="checkbox" id="db-'.$key.'" name="'.$this->dbUpdateCheckboxPrefix.'['.$key.']" value="1"'.($checked?' checked="checked"':'').' /></td>
00757                                                 <td nowrap="nowrap"><label for="db-'.$key.'">'.nl2br($ico.htmlspecialchars($string)).'</label></td>
00758                                         </tr>';
00759                                 if (isset($currentValue[$key])) {
00760                                         $out[]='
00761                                         <tr>
00762                                                 <td valign="top"></td>
00763                                                 <td nowrap="nowrap" style="color : #666666;">'.nl2br((!$cVfullMsg?"Current value: ":"").'<em>'.$currentValue[$key].'</em>').'</td>
00764                                         </tr>';
00765                                 }
00766                         }
00767 
00768                         // Compile rows:
00769                         $content = '
00770                                 <!-- Update database fields / tables -->
00771                                 <h3>'.$label.'</h3>
00772                                 <table border="0" cellpadding="2" cellspacing="2" class="update-db-fields">'.implode('',$out).'
00773                                 </table>';
00774                 }
00775 
00776                 return $content;
00777         }
00778 }
00779 
00780 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_install.php'])   {
00781         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_install.php']);
00782 }
00783 ?>


Généré par Les experts TYPO3 avec  doxygen 1.4.6