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 
00204                 if (!strstr($updatedLine, $writeToLocalconf_dat['updatedText']))        {
00205                         array_push($lines,$updatedLine);
00206                 }
00207 
00208                 if (is_array($inlines)) {       // Setting a line and write:
00209                                 // Setting configuration
00210                         $updatedLine = $writeToLocalconf_dat['updatedText'].date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'].' H:i:s');
00211                         array_push($inlines,$updatedLine);
00212                         array_push($inlines,$writeToLocalconf_dat['endLine']);
00213 
00214                         if ($this->setLocalconf)        {
00215                                 $success = FALSE;
00216                                 if (!t3lib_div::writeFile($writeToLocalconf_dat['tmpfile'],implode(chr(10),$inlines)))  {
00217                                         $msg = 'typo3conf/localconf.php'.$tmpExt.' could not be written - maybe a write access problem?';
00218                                 }
00219                                 elseif (strcmp(t3lib_div::getUrl($writeToLocalconf_dat['tmpfile']), implode(chr(10),$inlines))) {
00220                                         @unlink($writeToLocalconf_dat['tmpfile']);
00221                                         $msg = 'typo3conf/localconf.php'.$tmpExt.' was NOT written properly (written content didn\'t match file content) - maybe a disk space problem?';
00222                                 }
00223                                 elseif (!@copy($writeToLocalconf_dat['tmpfile'],$writeToLocalconf_dat['file'])) {
00224                                         $msg = 'typo3conf/localconf.php could not be replaced by typo3conf/localconf.php'.$tmpExt.' - maybe a write access problem?';
00225                                 }
00226                                 else {
00227                                         @unlink($writeToLocalconf_dat['tmpfile']);
00228                                         $success = TRUE;
00229                                         $msg = 'Configuration written to typo3conf/localconf.php';
00230                                 }
00231                                 $this->messages[] = $msg;
00232 
00233                                 if ($success)   {
00234                                         return 'continue';
00235                                 } else {
00236                                         t3lib_div::sysLog($msg, 'Core', 3);
00237                                         return 'nochange';
00238                                 }
00239                         } else {
00240                                 return 'nochange';
00241                         }
00242                 } else {        // Return lines found in localconf.php
00243                         return $lines;
00244                 }
00245         }
00246 
00254         function checkForBadString($string)     {
00255                 return preg_match('/['.chr(10).chr(13).']/',$string) ? FALSE : TRUE;
00256         }
00257 
00265         function slashValueForSingleDashes($value)      {
00266                 $value = str_replace("'.chr(10).'", '###INSTALL_TOOL_LINEBREAK###', $value);
00267                 $value = str_replace("'","\'",str_replace('\\','\\\\',$value));
00268                 $value = str_replace('###INSTALL_TOOL_LINEBREAK###', "'.chr(10).'", $value);
00269 
00270                 return $value;
00271         }
00272 
00273 
00274 
00275 
00276 
00277 
00278 
00279 
00280 
00281 
00282         /*************************************
00283          *
00284          * SQL
00285          *
00286          *************************************/
00287 
00294         function getFieldDefinitions_sqlContent($sqlContent)    {
00295                 $lines = t3lib_div::trimExplode(chr(10), $sqlContent,1);
00296                 $isTable = '';
00297                 $total = Array();
00298 
00299                 foreach($lines as $value)       {
00300                         if ($value[0]!='#')     {
00301                                 if (!$isTable)  {
00302                                         $parts = explode(' ',$value);
00303                                         if ($parts[0]=='CREATE' && $parts[1]=='TABLE')  {
00304                                                 $isTable = str_replace( '`', '', $parts[2]);
00305                                                 if (TYPO3_OS=='WIN') {  // tablenames are always lowercase on windows!
00306                                                         $isTable = strtolower($isTable);
00307                                                 }
00308                                         }
00309                                 } else {
00310                                         if (substr($value,0,1)==')' && substr($value,-1)==';')  {
00311                                                 $ttype = array();
00312                                                 preg_match('/(ENGINE|TYPE)=([a-zA-Z]*)/',$value,$ttype);
00313                                                 $total[$isTable]['extra']['ttype'] = $ttype[2];
00314                                                 $isTable = '';
00315                                         } else {
00316                                                 $lineV = preg_replace('/,$/','',$value);
00317                                                 $lineV = str_replace('UNIQUE KEY', 'UNIQUE', $lineV);
00318                                                 $parts = explode(' ',$lineV,2);
00319 
00320                                                         // Make sure there is no default value when auto_increment is set
00321                                                 if(stristr($parts[1],'auto_increment')) {
00322                                                         $parts[1] = preg_replace('/ default \'0\'/i','',$parts[1]);
00323                                                 }
00324                                                         // "default" is always lower-case
00325                                                 if(strstr($parts[1], ' DEFAULT '))      {
00326                                                         $parts[1] = str_replace(' DEFAULT ', ' default ', $parts[1]);
00327                                                 }
00328 
00329                                                         // Change order of "default" and "null" statements
00330                                                 $parts[1] = preg_replace('/(.*) (default .*) (NOT NULL)/', '$1 $3 $2', $parts[1]);
00331                                                 $parts[1] = preg_replace('/(.*) (default .*) (NULL)/', '$1 $3 $2', $parts[1]);
00332 
00333                                                         // Remove double blanks
00334                                                 $parts[1] = preg_replace('/([^ ]+)[ ]+([^ ]+)/', '$1 $2', $parts[1]);
00335 
00336                                                 if ($parts[0]!='PRIMARY' && $parts[0]!='KEY' && $parts[0]!='UNIQUE')    {
00337                                                         $key = str_replace('`', '', $parts[0]);
00338                                                         $total[$isTable]['fields'][$key] = $parts[1];
00339                                                 } else {        // Process keys
00340                                                         $newParts = explode(' ',$parts[1],2);
00341                                                         $key = str_replace('`', '', ($parts[0]=='PRIMARY'?$parts[0]:$newParts[0]));
00342                                                         $lineV = str_replace('`', '', $lineV);
00343                                                         $total[$isTable]['keys'][$key] = $lineV;
00344                                                 }
00345                                         }
00346                                 }
00347                         }
00348                 }
00349 
00350                 $this->getFieldDefinitions_sqlContent_parseTypes($total);
00351                 return $total;
00352         }
00353 
00363         function getFieldDefinitions_sqlContent_parseTypes(&$total)     {
00364 
00365                 $mSize = (double)$this->multiplySize;
00366                 if ($mSize > 1) {
00367 
00368                                 // Init SQL parser:
00369                         $sqlParser = t3lib_div::makeInstance('t3lib_sqlparser');
00370                         foreach($total as $table => $cfg)       {
00371                                 if (is_array($cfg['fields'])) {
00372                                         foreach($cfg['fields'] as $fN => $fType)        {
00373                                                 $orig_fType = $fType;
00374                                                 $fInfo = $sqlParser->parseFieldDef($fType);
00375 
00376                                                 switch($fInfo['fieldType'])     {
00377                                                         case 'char':
00378                                                         case 'varchar':
00379                                                                 $newSize = round($fInfo['value']*$mSize);
00380 
00381                                                                 if ($newSize <= 255)    {
00382                                                                         $fInfo['value'] = $newSize;
00383                                                                 } else {
00384                                                                         $fInfo = array(
00385                                                                                 'fieldType' => 'text',
00386                                                                                 'featureIndex' => array(
00387                                                                                         'NOTNULL' => array(
00388                                                                                                 'keyword' => 'NOT NULL'
00389                                                                                         )
00390                                                                                 )
00391                                                                         );
00392                                                                                 // Change key definition if necessary (must use "prefix" on TEXT columns)
00393                                                                         foreach ($cfg['keys'] as $kN => $kType) {
00394                                                                                 $match = array();
00395                                                                                 preg_match('/^([^(]*)\(([^)]+)\)(.*)/', $kType, $match);
00396                                                                                 $keys = array();
00397                                                                                 foreach (t3lib_div::trimExplode(',',$match[2]) as $kfN) {
00398                                                                                         if ($fN == $kfN)        {
00399                                                                                                 $kfN .= '('.$newSize.')';
00400                                                                                         }
00401                                                                                         $keys[] = $kfN;
00402                                                                                 }
00403                                                                                 $total[$table]['keys'][$kN] = $match[1].'('.join(',',$keys).')'.$match[3];
00404                                                                         }
00405                                                                 }
00406                                                         break;
00407                                                         case 'tinytext':
00408                                                                 $fInfo['fieldType'] = 'text';
00409                                                         break;
00410                                                 }
00411 
00412                                                 $total[$table]['fields'][$fN] = $sqlParser->compileFieldCfg($fInfo);
00413                                                 if ($sqlParser->parse_error)    die($sqlParser->parse_error);
00414                                         }
00415                                 }
00416                         }
00417                 }
00418         }
00419 
00425         function getFieldDefinitions_database() {
00426                 $total = array();
00427                 $GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db);
00428                 echo $GLOBALS['TYPO3_DB']->sql_error();
00429 
00430                 $tables = $GLOBALS['TYPO3_DB']->admin_get_tables(TYPO3_db);
00431                 foreach($tables as $tableName)  {
00432 
00433                                 // Fields:
00434                         $fieldInformation = $GLOBALS['TYPO3_DB']->admin_get_fields($tableName);
00435                         foreach($fieldInformation as $fN => $fieldRow)  {
00436                                 $total[$tableName]['fields'][$fN] = $this->assembleFieldDefinition($fieldRow);
00437                         }
00438 
00439                                 // Keys:
00440                         $keyInformation = $GLOBALS['TYPO3_DB']->admin_get_keys($tableName);
00441                         foreach($keyInformation as $kN => $keyRow)      {
00442                                 $tempKeys[$tableName][$keyRow['Key_name']][$keyRow['Seq_in_index']] = $keyRow['Column_name'];
00443                                 if ($keyRow['Sub_part'])        {
00444                                         $tempKeys[$tableName][$keyRow['Key_name']][$keyRow['Seq_in_index']].= '('.$keyRow['Sub_part'].')';
00445                                 }
00446                                 if ($keyRow['Key_name']=='PRIMARY')     {
00447                                         $tempKeysPrefix[$tableName][$keyRow['Key_name']] = 'PRIMARY KEY';
00448                                 } else {
00449                                         if ($keyRow['Non_unique'])      {
00450                                                 $tempKeysPrefix[$tableName][$keyRow['Key_name']] = 'KEY';
00451                                         } else {
00452                                                 $tempKeysPrefix[$tableName][$keyRow['Key_name']] = 'UNIQUE';
00453                                         }
00454                                         $tempKeysPrefix[$tableName][$keyRow['Key_name']].= ' '.$keyRow['Key_name'];
00455                                 }
00456                         }
00457                 }
00458 
00459                         // Compile information:
00460                 if (is_array($tempKeys))        {
00461                         foreach($tempKeys as $table => $keyInf) {
00462                                 foreach($keyInf as $kName => $index) {
00463                                         ksort($index);
00464                                         $total[$table]['keys'][$kName] = $tempKeysPrefix[$table][$kName].' ('.implode(',',$index).')';
00465                                 }
00466                         }
00467                 }
00468 
00469                 return $total;
00470         }
00471 
00482         function getDatabaseExtra($FDsrc, $FDcomp, $onlyTableList='',$ignoreNotNullWhenComparing=true)  {
00483                 $extraArr = array();
00484                 $diffArr = array();
00485 
00486                 if (is_array($FDsrc))   {
00487                         foreach($FDsrc as $table => $info) {
00488                                 if (!strlen($onlyTableList) || t3lib_div::inList($onlyTableList, $table))       {
00489                                         if (!isset($FDcomp[$table]))    {
00490                                                 $extraArr[$table] = $info;              // If the table was not in the FDcomp-array, the result array is loaded with that table.
00491                                                 $extraArr[$table]['whole_table']=1;
00492                                         } else {
00493                                                 $keyTypes = explode(',','fields,keys');
00494                                                 foreach($keyTypes as $theKey)   {
00495                                                         if (is_array($info[$theKey]))   {
00496                                                                 foreach($info[$theKey] as $fieldN => $fieldC)   {
00497                                                                         $fieldN = str_replace('`','',$fieldN);
00498                                                                         if (!isset($FDcomp[$table][$theKey][$fieldN]))  {
00499                                                                                 $extraArr[$table][$theKey][$fieldN] = $fieldC;
00500                                                                         } elseif (strcmp($FDcomp[$table][$theKey][$fieldN], $ignoreNotNullWhenComparing?str_replace(' NOT NULL', '', $fieldC):$fieldC)) {
00501                                                                                 $diffArr[$table][$theKey][$fieldN] = $fieldC;
00502                                                                                 $diffArr_cur[$table][$theKey][$fieldN] = $FDcomp[$table][$theKey][$fieldN];
00503                                                                         }
00504                                                                 }
00505                                                         }
00506                                                 }
00507                                         }
00508                                 }
00509                         }
00510                 }
00511 
00512                 $output = array(
00513                         'extra' => $extraArr,
00514                         'diff' => $diffArr,
00515                         'diff_currentValues' => $diffArr_cur
00516                 );
00517 
00518                 return $output;
00519         }
00520 
00528         function getUpdateSuggestions($diffArr,$keyList='extra,diff')   {
00529                 $statements = array();
00530                 $deletedPrefixKey = $this->deletedPrefixKey;
00531                 $remove = 0;
00532                 if ($keyList == 'remove')       {
00533                         $remove = 1;
00534                         $keyList = 'extra';
00535                 }
00536                 $keyList = explode(',',$keyList);
00537                 foreach($keyList as $theKey)    {
00538                         if (is_array($diffArr[$theKey]))        {
00539                                 foreach($diffArr[$theKey] as $table => $info) {
00540                                         $whole_table = array();
00541                                         if (is_array($info['fields']))  {
00542                                                 foreach($info['fields'] as $fN => $fV) {
00543                                                         if ($info['whole_table'])       {
00544                                                                 $whole_table[]=$fN.' '.$fV;
00545                                                         } else {
00546                                                                 if ($theKey=='extra')   {
00547                                                                         if ($remove)    {
00548                                                                                 if (substr($fN,0,strlen($deletedPrefixKey))!=$deletedPrefixKey) {
00549                                                                                         $statement = 'ALTER TABLE '.$table.' CHANGE '.$fN.' '.$deletedPrefixKey.$fN.' '.$fV.';';
00550                                                                                         $statements['change'][md5($statement)] = $statement;
00551                                                                                 } else {
00552                                                                                         $statement = 'ALTER TABLE '.$table.' DROP '.$fN.';';
00553                                                                                         $statements['drop'][md5($statement)] = $statement;
00554                                                                                 }
00555                                                                         } else {
00556                                                                                 $statement = 'ALTER TABLE '.$table.' ADD '.$fN.' '.$fV.';';
00557                                                                                 $statements['add'][md5($statement)] = $statement;
00558                                                                         }
00559                                                                 } elseif ($theKey=='diff')      {
00560                                                                         $statement = 'ALTER TABLE '.$table.' CHANGE '.$fN.' '.$fN.' '.$fV.';';
00561                                                                         $statements['change'][md5($statement)] = $statement;
00562                                                                         $statements['change_currentValue'][md5($statement)] = $diffArr['diff_currentValues'][$table]['fields'][$fN];
00563                                                                 }
00564                                                         }
00565                                                 }
00566                                         }
00567                                         if (is_array($info['keys']))    {
00568                                                 foreach($info['keys'] as $fN => $fV) {
00569                                                         if ($info['whole_table'])       {
00570                                                                 $whole_table[] = $fV;
00571                                                         } else {
00572                                                                 if ($theKey=='extra')   {
00573                                                                         if ($remove)    {
00574                                                                                 $statement = 'ALTER TABLE '.$table.($fN=='PRIMARY' ? ' DROP PRIMARY KEY' : ' DROP KEY '.$fN).';';
00575                                                                                 $statements['drop'][md5($statement)] = $statement;
00576                                                                         } else {
00577                                                                                 $statement = 'ALTER TABLE '.$table.' ADD '.$fV.';';
00578                                                                                 $statements['add'][md5($statement)] = $statement;
00579                                                                         }
00580                                                                 } elseif ($theKey=='diff') {
00581                                                                         $statement = 'ALTER TABLE '.$table.($fN=='PRIMARY' ? ' DROP PRIMARY KEY' : ' DROP KEY '.$fN).';';
00582                                                                         $statements['change'][md5($statement)] = $statement;
00583                                                                         $statement = 'ALTER TABLE '.$table.' ADD '.$fV.';';
00584                                                                         $statements['change'][md5($statement)] = $statement;
00585                                                                 }
00586                                                         }
00587                                                 }
00588                                         }
00589                                         if ($info['whole_table'])       {
00590                                                 if ($remove)    {
00591                                                         if (substr($table,0,strlen($deletedPrefixKey))!=$deletedPrefixKey)      {
00592                                                                 $statement = 'ALTER TABLE '.$table.' RENAME '.$deletedPrefixKey.$table.';';
00593                                                                 $statements['change_table'][md5($statement)]=$statement;
00594                                                         } else {
00595                                                                 $statement = 'DROP TABLE '.$table.';';
00596                                                                 $statements['drop_table'][md5($statement)]=$statement;
00597                                                         }
00598                                                         // count:
00599                                                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', $table, '');
00600                                                         list($count) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00601                                                         $statements['tables_count'][md5($statement)] = $count?'Records in table: '.$count:'';
00602                                                 } else {
00603                                                         $statement = 'CREATE TABLE '.$table." (\n".implode(",\n",$whole_table)."\n)";
00604                                                         $statement .= ($info['extra']['ttype']) ? ' TYPE='.$info['extra']['ttype'].';' : ';';
00605                                                         $statements['create_table'][md5($statement)]=$statement;
00606                                                 }
00607                                         }
00608                                 }
00609                         }
00610                 }
00611 
00612                 return $statements;
00613         }
00614 
00621         function assembleFieldDefinition($row)  {
00622                 $field[] = $row['Type'];
00623                 // if (!$row['Null'])   { $field[] = 'NOT NULL'; }
00624                 if (!strstr($row['Type'],'blob') && !strstr($row['Type'],'text'))       {
00625                                 // Add a default value if the field is not auto-incremented (these fields never have a default definition).
00626                         if (!stristr($row['Extra'],'auto_increment'))   {
00627                                 $field[] = 'default '."'".(addslashes($row['Default']))."'";
00628                         }
00629                 }
00630                 if ($row['Extra'])      { $field[] = $row['Extra']; }
00631 
00632                 return implode(' ',$field);
00633         }
00634 
00643         function getStatementArray($sqlcode,$removeNonSQL=0,$query_regex='')    {
00644                 $sqlcodeArr = explode(chr(10),$sqlcode);
00645 
00646                 // Based on the assumption that the sql-dump has
00647                 $statementArray = array();
00648                 $statementArrayPointer = 0;
00649 
00650                 foreach($sqlcodeArr as $line => $linecontent)   {
00651                         $is_set = 0;
00652                         if(stristr($linecontent,'auto_increment')) {
00653                                 $linecontent = eregi_replace(' default \'0\'','',$linecontent);
00654                         }
00655 
00656                         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
00657                                 $statementArray[$statementArrayPointer].= $linecontent;
00658                                 $is_set = 1;
00659                         }
00660                         if (substr(trim($linecontent),-1)==';') {
00661                                 if (isset($statementArray[$statementArrayPointer]))     {
00662                                         if (!trim($statementArray[$statementArrayPointer]) || ($query_regex && !eregi($query_regex,trim($statementArray[$statementArrayPointer]))))     {
00663                                                 unset($statementArray[$statementArrayPointer]);
00664                                         }
00665                                 }
00666                                 $statementArrayPointer++;
00667                         } elseif ($is_set) {
00668                                 $statementArray[$statementArrayPointer].=chr(10);
00669                         }
00670                 }
00671                 return $statementArray;
00672         }
00673 
00681         function getCreateTables($statements, $insertCountFlag=0)       {
00682                 $crTables = array();
00683                 $insertCount = array();
00684                 foreach($statements as $line => $linecontent)   {
00685                         $reg = array();
00686                         if (eregi('^create[[:space:]]*table[[:space:]]*[`]?([[:alnum:]_]*)[`]?',substr($linecontent,0,100),$reg))       {
00687                                 $table = trim($reg[1]);
00688                                 if ($table)     {
00689                                         if (TYPO3_OS=='WIN')    { $table=strtolower($table); }  // table names are always lowercase on Windows!
00690                                         $sqlLines = explode(chr(10), $linecontent);
00691                                         foreach($sqlLines as $k=>$v)    {
00692                                                 if(stristr($v,'auto_increment')) {
00693                                                         $sqlLines[$k] = eregi_replace(' default \'0\'','',$v);
00694                                                 }
00695                                         }
00696                                         $linecontent = implode(chr(10), $sqlLines);
00697                                         $crTables[$table] = $linecontent;
00698                                 }
00699                         } elseif ($insertCountFlag && eregi('^insert[[:space:]]*into[[:space:]]*[`]?([[:alnum:]_]*)[`]?',substr($linecontent,0,100),$reg))      {
00700                                 $nTable = trim($reg[1]);
00701                                 $insertCount[$nTable]++;
00702                         }
00703                 }
00704 
00705                 return array($crTables,$insertCount);
00706         }
00707 
00715         function getTableInsertStatements($statements, $table)  {
00716                 $outStatements=array();
00717                 foreach($statements as $line => $linecontent)   {
00718                         $reg = array();
00719                         if (preg_match('/^insert[[:space:]]*into[[:space:]]*[`]?([[:alnum:]_]*)[`]?/i',substr($linecontent,0,100),$reg))        {
00720                                 $nTable = trim($reg[1]);
00721                                 if ($nTable && !strcmp($table,$nTable)) {
00722                                         $outStatements[]=$linecontent;
00723                                 }
00724                         }
00725                 }
00726                 return $outStatements;
00727         }
00728 
00736         function performUpdateQueries($arr,$keyArr)     {
00737                 if (is_array($arr))     {
00738                         foreach($arr as $key => $string)        {
00739                                 if (isset($keyArr[$key]) && $keyArr[$key])      {
00740                                         $GLOBALS['TYPO3_DB']->admin_query($string);
00741                                 }
00742                         }
00743                 }
00744         }
00745 
00752         function getListOfTables()      {
00753                 $whichTables = $GLOBALS['TYPO3_DB']->admin_get_tables(TYPO3_db);
00754                 return $whichTables;
00755         }
00756 
00768         function generateUpdateDatabaseForm_checkboxes($arr,$label,$checked=1,$iconDis=0,$currentValue=array(),$cVfullMsg=0)    {
00769                 $out = array();
00770                 if (is_array($arr))     {
00771                         foreach($arr as $key => $string)        {
00772                                 $ico = '';
00773                                 if ($iconDis)   {
00774                                         if (stristr($string,' user_'))  {
00775                                                 $ico.= '<img src="'.$this->backPath.'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(USER) </strong>';
00776                                         }
00777                                         if (stristr($string,' app_'))   {
00778                                                 $ico.= '<img src="'.$this->backPath.'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(APP) </strong>';
00779                                         }
00780                                         if (stristr($string,' ttx_') || stristr($string,' tx_'))        {
00781                                                 $ico.= '<img src="'.$this->backPath.'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(EXT) </strong>';
00782                                         }
00783                                 }
00784                                 $out[]='
00785                                         <tr>
00786                                                 <td valign="top"><input type="checkbox" id="db-'.$key.'" name="'.$this->dbUpdateCheckboxPrefix.'['.$key.']" value="1"'.($checked?' checked="checked"':'').' /></td>
00787                                                 <td nowrap="nowrap"><label for="db-'.$key.'">'.nl2br($ico.htmlspecialchars($string)).'</label></td>
00788                                         </tr>';
00789                                 if (isset($currentValue[$key])) {
00790                                         $out[]='
00791                                         <tr>
00792                                                 <td valign="top"></td>
00793                                                 <td nowrap="nowrap" style="color : #666666;">'.nl2br((!$cVfullMsg?"Current value: ":"").'<em>'.$currentValue[$key].'</em>').'</td>
00794                                         </tr>';
00795                                 }
00796                         }
00797 
00798                         // Compile rows:
00799                         $content = '
00800                                 <!-- Update database fields / tables -->
00801                                 <h3>'.$label.'</h3>
00802                                 <table border="0" cellpadding="2" cellspacing="2" class="update-db-fields">'.implode('',$out).'
00803                                 </table>';
00804                 }
00805 
00806                 return $content;
00807         }
00808 }
00809 
00810 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_install.php'])   {
00811         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_install.php']);
00812 }
00813 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6