/src/typo3_src-4.2.0alpha1/t3lib/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                                                                         if (is_array($cfg['keys'])) {
00394                                                                                 foreach ($cfg['keys'] as $kN => $kType) {
00395                                                                                         $match = array();
00396                                                                                         preg_match('/^([^(]*)\(([^)]+)\)(.*)/', $kType, $match);
00397                                                                                         $keys = array();
00398                                                                                         foreach (t3lib_div::trimExplode(',',$match[2]) as $kfN) {
00399                                                                                                 if ($fN == $kfN)        {
00400                                                                                                         $kfN .= '('.$newSize.')';
00401                                                                                                 }
00402                                                                                                 $keys[] = $kfN;
00403                                                                                         }
00404                                                                                         $total[$table]['keys'][$kN] = $match[1].'('.join(',',$keys).')'.$match[3];
00405                                                                                 }
00406                                                                         }
00407                                                                 }
00408                                                         break;
00409                                                         case 'tinytext':
00410                                                                 $fInfo['fieldType'] = 'text';
00411                                                         break;
00412                                                 }
00413 
00414                                                 $total[$table]['fields'][$fN] = $sqlParser->compileFieldCfg($fInfo);
00415                                                 if ($sqlParser->parse_error)    die($sqlParser->parse_error);
00416                                         }
00417                                 }
00418                         }
00419                 }
00420         }
00421 
00427         function getFieldDefinitions_database() {
00428                 $total = array();
00429                 $GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db);
00430                 echo $GLOBALS['TYPO3_DB']->sql_error();
00431 
00432                 $tables = $GLOBALS['TYPO3_DB']->admin_get_tables(TYPO3_db);
00433                 foreach($tables as $tableName)  {
00434 
00435                                 // Fields:
00436                         $fieldInformation = $GLOBALS['TYPO3_DB']->admin_get_fields($tableName);
00437                         foreach($fieldInformation as $fN => $fieldRow)  {
00438                                 $total[$tableName]['fields'][$fN] = $this->assembleFieldDefinition($fieldRow);
00439                         }
00440 
00441                                 // Keys:
00442                         $keyInformation = $GLOBALS['TYPO3_DB']->admin_get_keys($tableName);
00443                         foreach($keyInformation as $kN => $keyRow)      {
00444                                 $tempKeys[$tableName][$keyRow['Key_name']][$keyRow['Seq_in_index']] = $keyRow['Column_name'];
00445                                 if ($keyRow['Sub_part'])        {
00446                                         $tempKeys[$tableName][$keyRow['Key_name']][$keyRow['Seq_in_index']].= '('.$keyRow['Sub_part'].')';
00447                                 }
00448                                 if ($keyRow['Key_name']=='PRIMARY')     {
00449                                         $tempKeysPrefix[$tableName][$keyRow['Key_name']] = 'PRIMARY KEY';
00450                                 } else {
00451                                         if ($keyRow['Non_unique'])      {
00452                                                 $tempKeysPrefix[$tableName][$keyRow['Key_name']] = 'KEY';
00453                                         } else {
00454                                                 $tempKeysPrefix[$tableName][$keyRow['Key_name']] = 'UNIQUE';
00455                                         }
00456                                         $tempKeysPrefix[$tableName][$keyRow['Key_name']].= ' '.$keyRow['Key_name'];
00457                                 }
00458                         }
00459                 }
00460 
00461                         // Compile key information:
00462                 if (is_array($tempKeys))        {
00463                         foreach($tempKeys as $table => $keyInf) {
00464                                 foreach($keyInf as $kName => $index) {
00465                                         ksort($index);
00466                                         $total[$table]['keys'][$kName] = $tempKeysPrefix[$table][$kName].' ('.implode(',',$index).')';
00467                                 }
00468                         }
00469                 }
00470 
00471                 return $total;
00472         }
00473 
00484         function getDatabaseExtra($FDsrc, $FDcomp, $onlyTableList='',$ignoreNotNullWhenComparing=true)  {
00485                 $extraArr = array();
00486                 $diffArr = array();
00487 
00488                 if (is_array($FDsrc))   {
00489                         foreach($FDsrc as $table => $info) {
00490                                 if (!strlen($onlyTableList) || t3lib_div::inList($onlyTableList, $table))       {
00491                                         if (!isset($FDcomp[$table]))    {
00492                                                 $extraArr[$table] = $info;              // If the table was not in the FDcomp-array, the result array is loaded with that table.
00493                                                 $extraArr[$table]['whole_table']=1;
00494                                         } else {
00495                                                 $keyTypes = explode(',','fields,keys');
00496                                                 foreach($keyTypes as $theKey)   {
00497                                                         if (is_array($info[$theKey]))   {
00498                                                                 foreach($info[$theKey] as $fieldN => $fieldC)   {
00499                                                                         $fieldN = str_replace('`','',$fieldN);
00500                                                                         if (!isset($FDcomp[$table][$theKey][$fieldN]))  {
00501                                                                                 $extraArr[$table][$theKey][$fieldN] = $fieldC;
00502                                                                         } elseif (strcmp($FDcomp[$table][$theKey][$fieldN], $ignoreNotNullWhenComparing?str_replace(' NOT NULL', '', $fieldC):$fieldC)) {
00503                                                                                 $diffArr[$table][$theKey][$fieldN] = $fieldC;
00504                                                                                 $diffArr_cur[$table][$theKey][$fieldN] = $FDcomp[$table][$theKey][$fieldN];
00505                                                                         }
00506                                                                 }
00507                                                         }
00508                                                 }
00509                                         }
00510                                 }
00511                         }
00512                 }
00513 
00514                 $output = array(
00515                         'extra' => $extraArr,
00516                         'diff' => $diffArr,
00517                         'diff_currentValues' => $diffArr_cur
00518                 );
00519 
00520                 return $output;
00521         }
00522 
00530         function getUpdateSuggestions($diffArr,$keyList='extra,diff')   {
00531                 $statements = array();
00532                 $deletedPrefixKey = $this->deletedPrefixKey;
00533                 $remove = 0;
00534                 if ($keyList == 'remove')       {
00535                         $remove = 1;
00536                         $keyList = 'extra';
00537                 }
00538                 $keyList = explode(',',$keyList);
00539                 foreach($keyList as $theKey)    {
00540                         if (is_array($diffArr[$theKey]))        {
00541                                 foreach($diffArr[$theKey] as $table => $info) {
00542                                         $whole_table = array();
00543                                         if (is_array($info['fields']))  {
00544                                                 foreach($info['fields'] as $fN => $fV) {
00545                                                         if ($info['whole_table'])       {
00546                                                                 $whole_table[]=$fN.' '.$fV;
00547                                                         } else {
00548                                                                 if ($theKey=='extra')   {
00549                                                                         if ($remove)    {
00550                                                                                 if (substr($fN,0,strlen($deletedPrefixKey))!=$deletedPrefixKey) {
00551                                                                                         $statement = 'ALTER TABLE '.$table.' CHANGE '.$fN.' '.$deletedPrefixKey.$fN.' '.$fV.';';
00552                                                                                         $statements['change'][md5($statement)] = $statement;
00553                                                                                 } else {
00554                                                                                         $statement = 'ALTER TABLE '.$table.' DROP '.$fN.';';
00555                                                                                         $statements['drop'][md5($statement)] = $statement;
00556                                                                                 }
00557                                                                         } else {
00558                                                                                 $statement = 'ALTER TABLE '.$table.' ADD '.$fN.' '.$fV.';';
00559                                                                                 $statements['add'][md5($statement)] = $statement;
00560                                                                         }
00561                                                                 } elseif ($theKey=='diff')      {
00562                                                                         $statement = 'ALTER TABLE '.$table.' CHANGE '.$fN.' '.$fN.' '.$fV.';';
00563                                                                         $statements['change'][md5($statement)] = $statement;
00564                                                                         $statements['change_currentValue'][md5($statement)] = $diffArr['diff_currentValues'][$table]['fields'][$fN];
00565                                                                 }
00566                                                         }
00567                                                 }
00568                                         }
00569                                         if (is_array($info['keys']))    {
00570                                                 foreach($info['keys'] as $fN => $fV) {
00571                                                         if ($info['whole_table'])       {
00572                                                                 $whole_table[] = $fV;
00573                                                         } else {
00574                                                                 if ($theKey=='extra')   {
00575                                                                         if ($remove)    {
00576                                                                                 $statement = 'ALTER TABLE '.$table.($fN=='PRIMARY' ? ' DROP PRIMARY KEY' : ' DROP KEY '.$fN).';';
00577                                                                                 $statements['drop'][md5($statement)] = $statement;
00578                                                                         } else {
00579                                                                                 $statement = 'ALTER TABLE '.$table.' ADD '.$fV.';';
00580                                                                                 $statements['add'][md5($statement)] = $statement;
00581                                                                         }
00582                                                                 } elseif ($theKey=='diff') {
00583                                                                         $statement = 'ALTER TABLE '.$table.($fN=='PRIMARY' ? ' DROP PRIMARY KEY' : ' DROP KEY '.$fN).';';
00584                                                                         $statements['change'][md5($statement)] = $statement;
00585                                                                         $statement = 'ALTER TABLE '.$table.' ADD '.$fV.';';
00586                                                                         $statements['change'][md5($statement)] = $statement;
00587                                                                 }
00588                                                         }
00589                                                 }
00590                                         }
00591                                         if ($info['whole_table'])       {
00592                                                 if ($remove)    {
00593                                                         if (substr($table,0,strlen($deletedPrefixKey))!=$deletedPrefixKey)      {
00594                                                                 $statement = 'ALTER TABLE '.$table.' RENAME '.$deletedPrefixKey.$table.';';
00595                                                                 $statements['change_table'][md5($statement)]=$statement;
00596                                                         } else {
00597                                                                 $statement = 'DROP TABLE '.$table.';';
00598                                                                 $statements['drop_table'][md5($statement)]=$statement;
00599                                                         }
00600                                                         // count:
00601                                                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', $table, '');
00602                                                         list($count) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00603                                                         $statements['tables_count'][md5($statement)] = $count?'Records in table: '.$count:'';
00604                                                 } else {
00605                                                         $statement = 'CREATE TABLE '.$table." (\n".implode(",\n",$whole_table)."\n)";
00606                                                         $statement .= ($info['extra']['ttype']) ? ' TYPE='.$info['extra']['ttype'].';' : ';';
00607                                                         $statements['create_table'][md5($statement)]=$statement;
00608                                                 }
00609                                         }
00610                                 }
00611                         }
00612                 }
00613 
00614                 return $statements;
00615         }
00616 
00623         function assembleFieldDefinition($row)  {
00624                 $field[] = $row['Type'];
00625                 // if (!$row['Null'])   { $field[] = 'NOT NULL'; }
00626                 if (!strstr($row['Type'],'blob') && !strstr($row['Type'],'text'))       {
00627                                 // Add a default value if the field is not auto-incremented (these fields never have a default definition).
00628                         if (!stristr($row['Extra'],'auto_increment'))   {
00629                                 $field[] = 'default '."'".(addslashes($row['Default']))."'";
00630                         }
00631                 }
00632                 if ($row['Extra'])      { $field[] = $row['Extra']; }
00633 
00634                 return implode(' ',$field);
00635         }
00636 
00645         function getStatementArray($sqlcode,$removeNonSQL=0,$query_regex='')    {
00646                 $sqlcodeArr = explode(chr(10),$sqlcode);
00647 
00648                 // Based on the assumption that the sql-dump has
00649                 $statementArray = array();
00650                 $statementArrayPointer = 0;
00651 
00652                 foreach($sqlcodeArr as $line => $linecontent)   {
00653                         $is_set = 0;
00654                         if(stristr($linecontent,'auto_increment')) {
00655                                 $linecontent = eregi_replace(' default \'0\'','',$linecontent);
00656                         }
00657 
00658                         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
00659                                 $statementArray[$statementArrayPointer].= $linecontent;
00660                                 $is_set = 1;
00661                         }
00662                         if (substr(trim($linecontent),-1)==';') {
00663                                 if (isset($statementArray[$statementArrayPointer]))     {
00664                                         if (!trim($statementArray[$statementArrayPointer]) || ($query_regex && !eregi($query_regex,trim($statementArray[$statementArrayPointer]))))     {
00665                                                 unset($statementArray[$statementArrayPointer]);
00666                                         }
00667                                 }
00668                                 $statementArrayPointer++;
00669                         } elseif ($is_set) {
00670                                 $statementArray[$statementArrayPointer].=chr(10);
00671                         }
00672                 }
00673                 return $statementArray;
00674         }
00675 
00683         function getCreateTables($statements, $insertCountFlag=0)       {
00684                 $crTables = array();
00685                 $insertCount = array();
00686                 foreach($statements as $line => $linecontent)   {
00687                         $reg = array();
00688                         if (eregi('^create[[:space:]]*table[[:space:]]*[`]?([[:alnum:]_]*)[`]?',substr($linecontent,0,100),$reg))       {
00689                                 $table = trim($reg[1]);
00690                                 if ($table)     {
00691                                         if (TYPO3_OS=='WIN')    { $table=strtolower($table); }  // table names are always lowercase on Windows!
00692                                         $sqlLines = explode(chr(10), $linecontent);
00693                                         foreach($sqlLines as $k=>$v)    {
00694                                                 if(stristr($v,'auto_increment')) {
00695                                                         $sqlLines[$k] = eregi_replace(' default \'0\'','',$v);
00696                                                 }
00697                                         }
00698                                         $linecontent = implode(chr(10), $sqlLines);
00699                                         $crTables[$table] = $linecontent;
00700                                 }
00701                         } elseif ($insertCountFlag && eregi('^insert[[:space:]]*into[[:space:]]*[`]?([[:alnum:]_]*)[`]?',substr($linecontent,0,100),$reg))      {
00702                                 $nTable = trim($reg[1]);
00703                                 $insertCount[$nTable]++;
00704                         }
00705                 }
00706 
00707                 return array($crTables,$insertCount);
00708         }
00709 
00717         function getTableInsertStatements($statements, $table)  {
00718                 $outStatements=array();
00719                 foreach($statements as $line => $linecontent)   {
00720                         $reg = array();
00721                         if (preg_match('/^insert[[:space:]]*into[[:space:]]*[`]?([[:alnum:]_]*)[`]?/i',substr($linecontent,0,100),$reg))        {
00722                                 $nTable = trim($reg[1]);
00723                                 if ($nTable && !strcmp($table,$nTable)) {
00724                                         $outStatements[]=$linecontent;
00725                                 }
00726                         }
00727                 }
00728                 return $outStatements;
00729         }
00730 
00738         function performUpdateQueries($arr,$keyArr)     {
00739                 if (is_array($arr))     {
00740                         foreach($arr as $key => $string)        {
00741                                 if (isset($keyArr[$key]) && $keyArr[$key])      {
00742                                         $GLOBALS['TYPO3_DB']->admin_query($string);
00743                                 }
00744                         }
00745                 }
00746         }
00747 
00754         function getListOfTables()      {
00755                 $whichTables = $GLOBALS['TYPO3_DB']->admin_get_tables(TYPO3_db);
00756                 return $whichTables;
00757         }
00758 
00770         function generateUpdateDatabaseForm_checkboxes($arr,$label,$checked=1,$iconDis=0,$currentValue=array(),$cVfullMsg=0)    {
00771                 $out = array();
00772                 if (is_array($arr))     {
00773                         foreach($arr as $key => $string)        {
00774                                 $ico = '';
00775                                 if ($iconDis)   {
00776                                         if (stristr($string,' user_'))  {
00777                                                 $ico.= '<img src="'.$this->backPath.'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(USER) </strong>';
00778                                         }
00779                                         if (stristr($string,' app_'))   {
00780                                                 $ico.= '<img src="'.$this->backPath.'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(APP) </strong>';
00781                                         }
00782                                         if (stristr($string,' ttx_') || stristr($string,' tx_'))        {
00783                                                 $ico.= '<img src="'.$this->backPath.'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(EXT) </strong>';
00784                                         }
00785                                 }
00786                                 $out[]='
00787                                         <tr>
00788                                                 <td valign="top"><input type="checkbox" id="db-'.$key.'" name="'.$this->dbUpdateCheckboxPrefix.'['.$key.']" value="1"'.($checked?' checked="checked"':'').' /></td>
00789                                                 <td nowrap="nowrap"><label for="db-'.$key.'">'.nl2br($ico.htmlspecialchars($string)).'</label></td>
00790                                         </tr>';
00791                                 if (isset($currentValue[$key])) {
00792                                         $out[]='
00793                                         <tr>
00794                                                 <td valign="top"></td>
00795                                                 <td nowrap="nowrap" style="color : #666666;">'.nl2br((!$cVfullMsg?"Current value: ":"").'<em>'.$currentValue[$key].'</em>').'</td>
00796                                         </tr>';
00797                                 }
00798                         }
00799 
00800                         // Compile rows:
00801                         $content = '
00802                                 <!-- Update database fields / tables -->
00803                                 <h3>'.$label.'</h3>
00804                                 <table border="0" cellpadding="2" cellspacing="2" class="update-db-fields">'.implode('',$out).'
00805                                 </table>';
00806                 }
00807 
00808                 return $content;
00809         }
00810 }
00811 
00812 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_install.php'])   {
00813         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_install.php']);
00814 }
00815 ?>

This documentation has been generated automatically from TYPO3 source code using Doxygen and is provided as is by Cast Iron Coding as a courtesy to other TYPO3 developers and users. Please consider Cast Iron Coding — a full-service web development agency in Portland, Oregon specializing in TYPO3 extension development — for all of your TYPO3 development and consulting needs!