Index: t3lib/class.t3lib_install.php =================================================================== --- t3lib/class.t3lib_install.php (revision 9380) +++ t3lib/class.t3lib_install.php (revision ) @@ -1,29 +1,29 @@ admin_get_charsets() + var $character_sets = array(); // Caching output of $GLOBALS['TYPO3_DB']->admin_get_charsets() // Internal, dynamic: - var $setLocalconf = 0; // Used to indicate that a value is change in the line-array of localconf and that it should be written. + var $setLocalconf = 0; // Used to indicate that a value is change in the line-array of localconf and that it should be written. - var $messages = array(); // Used to set (error)messages from the executing functions like mail-sending, writing Localconf and such + var $messages = array(); // Used to set (error)messages from the executing functions like mail-sending, writing Localconf and such - var $touchedLine = 0; // updated with line in localconf.php file that was changed. + var $touchedLine = 0; // updated with line in localconf.php file that was changed. /** @@ -105,14 +98,13 @@ * * @return void */ - function t3lib_install() { + function t3lib_install() { - if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['multiplyDBfieldSize']>= 1 && $GLOBALS['TYPO3_CONF_VARS']['SYS']['multiplyDBfieldSize']<=5) { + if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['multiplyDBfieldSize'] >= 1 && $GLOBALS['TYPO3_CONF_VARS']['SYS']['multiplyDBfieldSize'] <= 5) { - $this->multiplySize = (double)$GLOBALS['TYPO3_CONF_VARS']['SYS']['multiplyDBfieldSize']; + $this->multiplySize = (double) $GLOBALS['TYPO3_CONF_VARS']['SYS']['multiplyDBfieldSize']; } } - /************************************** * * Writing to localconf.php @@ -131,35 +123,39 @@ * @see writeToLocalconf_control() */ public function setValueInLocalconfFile(&$line_array, $variable, $value, $quoteValue = TRUE) { - if (!$this->checkForBadString($value)) return 0; + if (!$this->checkForBadString($value)) { + return 0; + } // Initialize: $found = 0; $this->touchedLine = ''; $commentKey = '## '; - $inArray = in_array($commentKey.$this->localconf_editPointToken,$line_array); + $inArray = in_array($commentKey . $this->localconf_editPointToken, $line_array); - $tokenSet = ($this->localconf_editPointToken && !$inArray); // Flag is set if the token should be set but is not yet... + $tokenSet = ($this->localconf_editPointToken && !$inArray); // Flag is set if the token should be set but is not yet... $stopAtToken = ($this->localconf_editPointToken && $inArray); - $comment = ' Modified or inserted by '.$this->updateIdentity.'.'; + $comment = ' Modified or inserted by ' . $this->updateIdentity . '.'; $replace = array('["', '"]'); $search = array('[\'', '\']'); $varDoubleQuotes = str_replace($search, $replace, $variable); // Search for variable name: - if (!$this->localconf_addLinesOnly && !$tokenSet) { + if (!$this->localconf_addLinesOnly && !$tokenSet) { $line_array = array_reverse($line_array); - foreach($line_array as $k => $v) { + foreach ($line_array as $k => $v) { $v2 = trim($v); - if ($stopAtToken && !strcmp($v2,$commentKey.$this->localconf_editPointToken)) break; // If stopAtToken and token found, break out of the loop.. + if ($stopAtToken && !strcmp($v2, $commentKey . $this->localconf_editPointToken)) { + break; + } // If stopAtToken and token found, break out of the loop.. - if (!strcmp(substr($v2,0,strlen($variable.' ')),$variable.' ')) { + if (!strcmp(substr($v2, 0, strlen($variable . ' ')), $variable . ' ')) { - $mainparts = explode($variable,$v,2); + $mainparts = explode($variable, $v, 2); - if (count($mainparts)==2) { // should ALWAYS be.... + if (count($mainparts) == 2) { // should ALWAYS be.... - $subparts = explode('//',$mainparts[1],2); + $subparts = explode('//', $mainparts[1], 2); if ($quoteValue) { $value = '\'' . $this->slashValueForSingleDashes($value) . '\''; } $line_array[$k] = $mainparts[0] . $variable . " = " . $value . "; " . ('//' . $comment . str_replace($comment, '', $subparts[1])); - $this->touchedLine = count($line_array)-$k-1; + $this->touchedLine = count($line_array) - $k - 1; $found = 1; break; } @@ -179,14 +175,14 @@ $this->touchedLine = count($line_array) - $k - 1; $found = 1; break; - } - } + } + } } $line_array = array_reverse($line_array); } - if (!$found) { + if (!$found) { - if ($tokenSet) { + if ($tokenSet) { - $line_array[] = $commentKey.$this->localconf_editPointToken; + $line_array[] = $commentKey . $this->localconf_editPointToken; $line_array[] = ''; } if ($quoteValue) { @@ -215,7 +211,7 @@ public function setArrayValueInLocalconfFile(array &$lines, $variable, array $value) { $commentKey = '## '; $inArray = in_array($commentKey . $this->localconf_editPointToken, $lines); - $tokenSet = $this->localconf_editPointToken && !$inArray; // Flag is set if the token should be set but is not yet + $tokenSet = $this->localconf_editPointToken && !$inArray; // Flag is set if the token should be set but is not yet $stopAtToken = $this->localconf_editPointToken && $inArray; $comment = 'Modified or inserted by ' . $this->updateIdentity . '.'; $format = "%s = %s;\t// " . $comment; @@ -302,11 +298,11 @@ * @return mixed If $inlines is not an array it will return an array with the lines from localconf.php. Otherwise it will return a status string, either "continue" (updated) or "nochange" (not updated) * @see setValueInLocalconfFile() */ - function writeToLocalconf_control($inlines='',$absFullPath='') { + function writeToLocalconf_control($inlines = '', $absFullPath = '') { $tmpExt = '.TMP.php'; $writeToLocalconf_dat = array(); - $writeToLocalconf_dat['file'] = $absFullPath ? $absFullPath : PATH_typo3conf.'localconf.php'; + $writeToLocalconf_dat['file'] = $absFullPath ? $absFullPath : PATH_typo3conf . 'localconf.php'; - $writeToLocalconf_dat['tmpfile'] = $writeToLocalconf_dat['file'].$tmpExt; + $writeToLocalconf_dat['tmpfile'] = $writeToLocalconf_dat['file'] . $tmpExt; // Checking write state of localconf.php: if (!$this->allowUpdateLocalConf) { @@ -315,35 +311,35 @@ 1270853915 ); } - if (!@is_writable($writeToLocalconf_dat['file'])) { + if (!@is_writable($writeToLocalconf_dat['file'])) { throw new RuntimeException( 'TYPO3 Fatal Error: ' . $writeToLocalconf_dat['file'] . ' is not writable!', 1270853916 ); } - // Splitting localconf.php file into lines: + // Splitting localconf.php file into lines: - $lines = explode(LF,str_replace(CR,'',trim(t3lib_div::getUrl($writeToLocalconf_dat['file'])))); + $lines = explode(LF, str_replace(CR, '', trim(t3lib_div::getUrl($writeToLocalconf_dat['file'])))); - $writeToLocalconf_dat['endLine'] = array_pop($lines); // Getting "? >" ending. + $writeToLocalconf_dat['endLine'] = array_pop($lines); // Getting "? >" ending. // Checking if "updated" line was set by this tool - if so remove old line. $updatedLine = array_pop($lines); - $writeToLocalconf_dat['updatedText'] = '// Updated by '.$this->updateIdentity.' '; + $writeToLocalconf_dat['updatedText'] = '// Updated by ' . $this->updateIdentity . ' '; - if (!strstr($updatedLine, $writeToLocalconf_dat['updatedText'])) { + if (!strstr($updatedLine, $writeToLocalconf_dat['updatedText'])) { - array_push($lines,$updatedLine); + array_push($lines, $updatedLine); } - if (is_array($inlines)) { // Setting a line and write: + if (is_array($inlines)) { // Setting a line and write: // Setting configuration - $updatedLine = $writeToLocalconf_dat['updatedText'].date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'].' H:i:s'); + $updatedLine = $writeToLocalconf_dat['updatedText'] . date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' H:i:s'); - array_push($inlines,$updatedLine); + array_push($inlines, $updatedLine); - array_push($inlines,$writeToLocalconf_dat['endLine']); + array_push($inlines, $writeToLocalconf_dat['endLine']); - if ($this->setLocalconf) { + if ($this->setLocalconf) { $success = $this->writeToLocalconf($inlines, $absFullPath); - if ($success) { + if ($success) { return 'continue'; } else { return 'nochange'; @@ -351,7 +347,7 @@ } else { return 'nochange'; } - } else { // Return lines found in localconf.php + } else { // Return lines found in localconf.php return $lines; } } @@ -383,14 +379,14 @@ ); } - $writeToLocalconf_dat['endLine'] = array_pop($lines); // Getting "? >" ending. + $writeToLocalconf_dat['endLine'] = array_pop($lines); // Getting "? >" ending. if (!strstr('?' . '>', $writeToLocalconf_dat['endLine'])) { $lines[] = $writeToLocalconf_dat['endLine']; $writeToLocalconf_dat['endLine'] = '?' . '>'; } // Checking if "updated" line was set by this tool - if so remove old line. $updatedLine = array_pop($lines); - $writeToLocalconf_dat['updatedText'] = '// Updated by '. $this->updateIdentity . ' '; + $writeToLocalconf_dat['updatedText'] = '// Updated by ' . $this->updateIdentity . ' '; if (!strstr($updatedLine, $writeToLocalconf_dat['updatedText'])) { $lines[] = $updatedLine; @@ -432,8 +428,8 @@ * @return boolean Returns TRUE if string is OK * @see setValueInLocalconfFile() */ - function checkForBadString($string) { + function checkForBadString($string) { - return preg_match('/['.LF.CR.']/',$string) ? FALSE : TRUE; + return preg_match('/[' . LF . CR . ']/', $string) ? FALSE : TRUE; } /** @@ -443,23 +439,15 @@ * @return string Output value * @see setValueInLocalconfFile() */ - function slashValueForSingleDashes($value) { + function slashValueForSingleDashes($value) { $value = str_replace("'.LF.'", '###INSTALL_TOOL_LINEBREAK###', $value); - $value = str_replace("'","\'",str_replace('\\','\\\\',$value)); + $value = str_replace("'", "\'", str_replace('\\', '\\\\', $value)); $value = str_replace('###INSTALL_TOOL_LINEBREAK###', "'.LF.'", $value); return $value; } - - - - - - - - /************************************* * * SQL @@ -472,28 +460,28 @@ * @param string Should be a string read from an SQL-file made with 'mysqldump [database_name] -d' * @return array Array with information about table. */ - function getFieldDefinitions_fileContent($fileContent) { + function getFieldDefinitions_fileContent($fileContent) { $lines = t3lib_div::trimExplode(LF, $fileContent, 1); $table = ''; $total = array(); foreach ($lines as $value) { - if (substr($value,0,1)=='#') { + if (substr($value, 0, 1) == '#') { - continue; // Ignore comments + continue; // Ignore comments } if (!strlen($table)) { $parts = t3lib_div::trimExplode(' ', $value, TRUE); if (strtoupper($parts[0]) === 'CREATE' && strtoupper($parts[1]) === 'TABLE') { - $table = str_replace( '`', '', $parts[2]); + $table = str_replace('`', '', $parts[2]); - if (TYPO3_OS=='WIN') { // tablenames are always lowercase on windows! + if (TYPO3_OS == 'WIN') { // tablenames are always lowercase on windows! $table = strtolower($table); } } } else { - if (substr($value,0,1)==')' && substr($value,-1)==';') { + if (substr($value, 0, 1) == ')' && substr($value, -1) == ';') { $ttype = array(); - if (preg_match('/(ENGINE|TYPE)[ ]*=[ ]*([a-zA-Z]*)/',$value,$ttype)) { + if (preg_match('/(ENGINE|TYPE)[ ]*=[ ]*([a-zA-Z]*)/', $value, $ttype)) { $total[$table]['extra']['ENGINE'] = $ttype[2]; } // Otherwise, just do nothing: If table engine is not defined, just accept the system default. @@ -502,29 +490,29 @@ $total[$table]['extra']['COLLATE'] = $tcollation[2]; } else { // Otherwise, get the CHARACTER SET and try to find the default collation for it as returned by "SHOW CHARACTER SET" query (for details, see http://dev.mysql.com/doc/refman/5.1/en/charset-table.html) - if (preg_match('/(CHARSET|CHARACTER SET)[ ]*=[ ]*([a-zA-z0-9_-]+)/', $value, $tcharset)) { // Note: Keywords "DEFAULT CHARSET" and "CHARSET" are the same, so "DEFAULT" can just be ignored + if (preg_match('/(CHARSET|CHARACTER SET)[ ]*=[ ]*([a-zA-z0-9_-]+)/', $value, $tcharset)) { // Note: Keywords "DEFAULT CHARSET" and "CHARSET" are the same, so "DEFAULT" can just be ignored $charset = $tcharset[2]; } else { - $charset = $GLOBALS['TYPO3_DB']->default_charset; // Fallback to default charset + $charset = $GLOBALS['TYPO3_DB']->default_charset; // Fallback to default charset } $total[$table]['extra']['COLLATE'] = $this->getCollationForCharset($charset); } - $table = ''; // Remove table marker and start looking for the next "CREATE TABLE" statement + $table = ''; // Remove table marker and start looking for the next "CREATE TABLE" statement } else { - $lineV = preg_replace('/,$/','',$value); // Strip trailing commas + $lineV = preg_replace('/,$/', '', $value); // Strip trailing commas $lineV = str_replace('`', '', $lineV); - $lineV = str_replace(' ', ' ', $lineV); // Remove double blanks + $lineV = str_replace(' ', ' ', $lineV); // Remove double blanks $parts = explode(' ', $lineV, 2); - if (!preg_match('/(PRIMARY|UNIQUE|FULLTEXT|INDEX|KEY)/',$parts[0])) { // Field definition + if (!preg_match('/(PRIMARY|UNIQUE|FULLTEXT|INDEX|KEY)/', $parts[0])) { // Field definition // Make sure there is no default value when auto_increment is set - if (stristr($parts[1],'auto_increment')) { + if (stristr($parts[1], 'auto_increment')) { - $parts[1] = preg_replace('/ default \'0\'/i','',$parts[1]); + $parts[1] = preg_replace('/ default \'0\'/i', '', $parts[1]); } // "default" is always lower-case - if (stristr($parts[1], ' DEFAULT ')) { + if (stristr($parts[1], ' DEFAULT ')) { $parts[1] = str_ireplace(' DEFAULT ', ' default ', $parts[1]); } @@ -535,7 +523,7 @@ $key = $parts[0]; $total[$table]['fields'][$key] = $parts[1]; - } else { // Key definition + } else { // Key definition $search = array('/UNIQUE (INDEX|KEY)/', '/FULLTEXT (INDEX|KEY)/', '/INDEX/'); $replace = array('UNIQUE', 'FULLTEXT', 'KEY'); $lineV = preg_replace($search, $replace, $lineV); @@ -544,13 +532,13 @@ $parts[1] = preg_replace('/^(KEY|INDEX) /', '', $parts[1]); } - $newParts = explode(' ',$parts[1],2); + $newParts = explode(' ', $parts[1], 2); - $key = $parts[0]=='PRIMARY' ? $parts[0] : $newParts[0]; + $key = $parts[0] == 'PRIMARY' ? $parts[0] : $newParts[0]; $total[$table]['keys'][$key] = $lineV; // This is a protection against doing something stupid: Only allow clearing of cache_* and index_* tables. - if (preg_match('/^(cache|index)_/',$table)) { + if (preg_match('/^(cache|index)_/', $table)) { // Suggest to truncate (clear) this table $total[$table]['extra']['CLEAR'] = 1; } @@ -572,25 +560,25 @@ * @access private * @see getFieldDefinitions_fileContent() */ - function getFieldDefinitions_sqlContent_parseTypes(&$total) { + function getFieldDefinitions_sqlContent_parseTypes(&$total) { - $mSize = (double)$this->multiplySize; + $mSize = (double) $this->multiplySize; - if ($mSize > 1) { + if ($mSize > 1) { // Init SQL parser: $sqlParser = t3lib_div::makeInstance('t3lib_sqlparser'); - foreach($total as $table => $cfg) { + foreach ($total as $table => $cfg) { if (is_array($cfg['fields'])) { - foreach($cfg['fields'] as $fN => $fType) { + foreach ($cfg['fields'] as $fN => $fType) { $orig_fType = $fType; $fInfo = $sqlParser->parseFieldDef($fType); - switch($fInfo['fieldType']) { + switch ($fInfo['fieldType']) { case 'char': case 'varchar': - $newSize = round($fInfo['value']*$mSize); + $newSize = round($fInfo['value'] * $mSize); - if ($newSize <= 255) { + if ($newSize <= 255) { $fInfo['value'] = $newSize; } else { $fInfo = array( @@ -607,13 +595,13 @@ $match = array(); preg_match('/^([^(]*)\(([^)]+)\)(.*)/', $kType, $match); $keys = array(); - foreach (t3lib_div::trimExplode(',',$match[2]) as $kfN) { + foreach (t3lib_div::trimExplode(',', $match[2]) as $kfN) { - if ($fN == $kfN) { + if ($fN == $kfN) { - $kfN .= '('.$newSize.')'; + $kfN .= '(' . $newSize . ')'; } $keys[] = $kfN; } - $total[$table]['keys'][$kN] = $match[1].'('.implode(',',$keys).')'.$match[3]; + $total[$table]['keys'][$kN] = $match[1] . '(' . implode(',', $keys) . ')' . $match[3]; } } } @@ -642,13 +630,13 @@ * @param string Character set * @return string Corresponding default collation */ - function getCollationForCharset($charset) { + function getCollationForCharset($charset) { // Load character sets, if not cached already if (!count($this->character_sets)) { - if (method_exists($GLOBALS['TYPO3_DB'],'admin_get_charsets')) { + if (method_exists($GLOBALS['TYPO3_DB'], 'admin_get_charsets')) { $this->character_sets = $GLOBALS['TYPO3_DB']->admin_get_charsets(); } else { - $this->character_sets[$charset] = array(); // Add empty element to avoid that the check will be repeated + $this->character_sets[$charset] = array(); // Add empty element to avoid that the check will be repeated } } @@ -665,7 +653,7 @@ * * @return array Array with information about table. */ - function getFieldDefinitions_database() { + function getFieldDefinitions_database() { $total = array(); $tempKeys = array(); $tempKeysPrefix = array(); @@ -689,20 +677,20 @@ $keyName = $keyRow['Key_name']; $colName = $keyRow['Column_name']; if ($keyRow['Sub_part']) { - $colName.= '('.$keyRow['Sub_part'].')'; + $colName .= '(' . $keyRow['Sub_part'] . ')'; } $tempKeys[$tableName][$keyName][$keyRow['Seq_in_index']] = $colName; - if ($keyName=='PRIMARY') { + if ($keyName == 'PRIMARY') { $prefix = 'PRIMARY KEY'; } else { - if ($keyRow['Index_type']=='FULLTEXT') { + if ($keyRow['Index_type'] == 'FULLTEXT') { $prefix = 'FULLTEXT'; } elseif ($keyRow['Non_unique']) { $prefix = 'KEY'; } else { $prefix = 'UNIQUE'; } - $prefix.= ' '.$keyName; + $prefix .= ' ' . $keyName; } $tempKeysPrefix[$tableName][$keyName] = $prefix; } @@ -714,7 +702,7 @@ 'Collation' => 'COLLATE', ); - foreach ($tableExtraFields as $mysqlKey=>$internalKey) { + foreach ($tableExtraFields as $mysqlKey => $internalKey) { if (isset($tableStatus[$mysqlKey])) { $total[$tableName]['extra'][$internalKey] = $tableStatus[$mysqlKey]; } @@ -727,7 +715,7 @@ foreach ($tempKeys as $table => $keyInf) { foreach ($keyInf as $kName => $index) { ksort($index); - $total[$table]['keys'][$kName] = $tempKeysPrefix[$table][$kName].' ('.implode(',',$index).')'; + $total[$table]['keys'][$kName] = $tempKeysPrefix[$table][$kName] . ' (' . implode(',', $index) . ')'; } } } @@ -745,7 +733,7 @@ * @param boolean If set, this function ignores NOT NULL statements of the SQL file field definition when comparing current field definition from database with field definition from SQL file. This way, NOT NULL statements will be executed when the field is initially created, but the SQL parser will never complain about missing NOT NULL statements afterwards. * @return array Returns an array with 1) all elements from $FDsrc that is not in $FDcomp (in key 'extra') and 2) all elements from $FDsrc that is different from the ones in $FDcomp */ - function getDatabaseExtra($FDsrc, $FDcomp, $onlyTableList='',$ignoreNotNullWhenComparing=true) { + function getDatabaseExtra($FDsrc, $FDcomp, $onlyTableList = '', $ignoreNotNullWhenComparing = TRUE) { $extraArr = array(); $diffArr = array(); @@ -753,16 +741,16 @@ foreach ($FDsrc as $table => $info) { if (!strlen($onlyTableList) || t3lib_div::inList($onlyTableList, $table)) { if (!isset($FDcomp[$table])) { - $extraArr[$table] = $info; // If the table was not in the FDcomp-array, the result array is loaded with that table. + $extraArr[$table] = $info; // If the table was not in the FDcomp-array, the result array is loaded with that table. - $extraArr[$table]['whole_table']=1; + $extraArr[$table]['whole_table'] = 1; } else { - $keyTypes = explode(',','extra,fields,keys'); + $keyTypes = explode(',', 'extra,fields,keys'); foreach ($keyTypes as $theKey) { if (is_array($info[$theKey])) { foreach ($info[$theKey] as $fieldN => $fieldC) { - $fieldN = str_replace('`','',$fieldN); + $fieldN = str_replace('`', '', $fieldN); - if ($fieldN=='COLLATE') { + if ($fieldN == 'COLLATE') { - continue; // TODO: collation support is currently disabled (needs more testing) + continue; // TODO: collation support is currently disabled (needs more testing) } if (!isset($FDcomp[$table][$theKey][$fieldN])) { @@ -802,15 +790,15 @@ * @param string List of fields in diff array to take notice of. * @return array Array of SQL statements (organized in keys depending on type) */ - function getUpdateSuggestions($diffArr,$keyList='extra,diff') { + function getUpdateSuggestions($diffArr, $keyList = 'extra,diff') { $statements = array(); $deletedPrefixKey = $this->deletedPrefixKey; $remove = 0; - if ($keyList == 'remove') { + if ($keyList == 'remove') { $remove = 1; $keyList = 'extra'; } - $keyList = explode(',',$keyList); + $keyList = explode(',', $keyList); foreach ($keyList as $theKey) { if (is_array($diffArr[$theKey])) { foreach ($diffArr[$theKey] as $table => $info) { @@ -818,7 +806,7 @@ if (is_array($info['fields'])) { foreach ($info['fields'] as $fN => $fV) { if ($info['whole_table']) { - $whole_table[]=$fN.' '.$fV; + $whole_table[] = $fN . ' ' . $fV; } else { // Special case to work around MySQL problems when adding auto_increment fields: if (stristr($fV, 'auto_increment')) { @@ -832,21 +820,21 @@ $info['extra']['CLEAR'] = 2; } } - if ($theKey=='extra') { + if ($theKey == 'extra') { if ($remove) { - if (substr($fN,0,strlen($deletedPrefixKey))!=$deletedPrefixKey) { + if (substr($fN, 0, strlen($deletedPrefixKey)) != $deletedPrefixKey) { - $statement = 'ALTER TABLE '.$table.' CHANGE '.$fN.' '.$deletedPrefixKey.$fN.' '.$fV.';'; + $statement = 'ALTER TABLE ' . $table . ' CHANGE ' . $fN . ' ' . $deletedPrefixKey . $fN . ' ' . $fV . ';'; $statements['change'][md5($statement)] = $statement; } else { - $statement = 'ALTER TABLE '.$table.' DROP '.$fN.';'; + $statement = 'ALTER TABLE ' . $table . ' DROP ' . $fN . ';'; $statements['drop'][md5($statement)] = $statement; } } else { - $statement = 'ALTER TABLE '.$table.' ADD '.$fN.' '.$fV.';'; + $statement = 'ALTER TABLE ' . $table . ' ADD ' . $fN . ' ' . $fV . ';'; $statements['add'][md5($statement)] = $statement; } - } elseif ($theKey=='diff') { + } elseif ($theKey == 'diff') { - $statement = 'ALTER TABLE '.$table.' CHANGE '.$fN.' '.$fN.' '.$fV.';'; + $statement = 'ALTER TABLE ' . $table . ' CHANGE ' . $fN . ' ' . $fN . ' ' . $fV . ';'; $statements['change'][md5($statement)] = $statement; $statements['change_currentValue'][md5($statement)] = $diffArr['diff_currentValues'][$table]['fields'][$fN]; } @@ -858,18 +846,18 @@ if ($info['whole_table']) { $whole_table[] = $fV; } else { - if ($theKey=='extra') { + if ($theKey == 'extra') { if ($remove) { - $statement = 'ALTER TABLE '.$table.($fN=='PRIMARY' ? ' DROP PRIMARY KEY' : ' DROP KEY '.$fN).';'; + $statement = 'ALTER TABLE ' . $table . ($fN == 'PRIMARY' ? ' DROP PRIMARY KEY' : ' DROP KEY ' . $fN) . ';'; $statements['drop'][md5($statement)] = $statement; } else { - $statement = 'ALTER TABLE '.$table.' ADD '.$fV.';'; + $statement = 'ALTER TABLE ' . $table . ' ADD ' . $fV . ';'; $statements['add'][md5($statement)] = $statement; } - } elseif ($theKey=='diff') { + } elseif ($theKey == 'diff') { - $statement = 'ALTER TABLE '.$table.($fN=='PRIMARY' ? ' DROP PRIMARY KEY' : ' DROP KEY '.$fN).';'; + $statement = 'ALTER TABLE ' . $table . ($fN == 'PRIMARY' ? ' DROP PRIMARY KEY' : ' DROP KEY ' . $fN) . ';'; $statements['change'][md5($statement)] = $statement; - $statement = 'ALTER TABLE '.$table.' ADD '.$fV.';'; + $statement = 'ALTER TABLE ' . $table . ' ADD ' . $fV . ';'; $statements['change'][md5($statement)] = $statement; } } @@ -878,60 +866,60 @@ if (is_array($info['extra'])) { $extras = array(); $extras_currentValue = array(); - $clear_table = false; + $clear_table = FALSE; foreach ($info['extra'] as $fN => $fV) { // Only consider statements which are missing in the database but don't remove existing properties if (!$remove) { - if (!$info['whole_table']) { // If the whole table is created at once, we take care of this later by imploding all elements of $info['extra'] + if (!$info['whole_table']) { // If the whole table is created at once, we take care of this later by imploding all elements of $info['extra'] - if ($fN=='CLEAR') { + if ($fN == 'CLEAR') { // Truncate table must happen later, not now // Valid values for CLEAR: 1=only clear if keys are missing, 2=clear anyway (force) - if (count($info['keys']) || $fV==2) { + if (count($info['keys']) || $fV == 2) { - $clear_table = true; + $clear_table = TRUE; } continue; } else { - $extras[] = $fN.'='.$fV; + $extras[] = $fN . '=' . $fV; - $extras_currentValue[] = $fN.'='.$diffArr['diff_currentValues'][$table]['extra'][$fN]; + $extras_currentValue[] = $fN . '=' . $diffArr['diff_currentValues'][$table]['extra'][$fN]; } } } } if ($clear_table) { - $statement = 'TRUNCATE TABLE '.$table.';'; + $statement = 'TRUNCATE TABLE ' . $table . ';'; $statements['clear_table'][md5($statement)] = $statement; } if (count($extras)) { - $statement = 'ALTER TABLE '.$table.' '.implode(' ',$extras).';'; + $statement = 'ALTER TABLE ' . $table . ' ' . implode(' ', $extras) . ';'; $statements['change'][md5($statement)] = $statement; - $statements['change_currentValue'][md5($statement)] = implode(' ',$extras_currentValue); + $statements['change_currentValue'][md5($statement)] = implode(' ', $extras_currentValue); } } if ($info['whole_table']) { if ($remove) { - if (substr($table,0,strlen($deletedPrefixKey))!=$deletedPrefixKey) { + if (substr($table, 0, strlen($deletedPrefixKey)) != $deletedPrefixKey) { - $statement = 'ALTER TABLE '.$table.' RENAME '.$deletedPrefixKey.$table.';'; + $statement = 'ALTER TABLE ' . $table . ' RENAME ' . $deletedPrefixKey . $table . ';'; $statements['change_table'][md5($statement)] = $statement; } else { - $statement = 'DROP TABLE '.$table.';'; + $statement = 'DROP TABLE ' . $table . ';'; $statements['drop_table'][md5($statement)] = $statement; } // count: $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', $table); - $statements['tables_count'][md5($statement)] = $count?'Records in table: '.$count:''; + $statements['tables_count'][md5($statement)] = $count ? 'Records in table: ' . $count : ''; } else { - $statement = 'CREATE TABLE '.$table." (\n".implode(",\n",$whole_table)."\n)"; + $statement = 'CREATE TABLE ' . $table . " (\n" . implode(",\n", $whole_table) . "\n)"; if ($info['extra']) { - foreach ($info['extra'] as $k=>$v) { + foreach ($info['extra'] as $k => $v) { - if ($k=='COLLATE' || $k=='CLEAR') { + if ($k == 'COLLATE' || $k == 'CLEAR') { - continue; // Skip these special statements. TODO: collation support is currently disabled (needs more testing) + continue; // Skip these special statements. TODO: collation support is currently disabled (needs more testing) } - $statement.= ' '.$k.'='.$v; // Add extra attributes like ENGINE, CHARSET, etc. + $statement .= ' ' . $k . '=' . $v; // Add extra attributes like ENGINE, CHARSET, etc. } } - $statement.= ';'; + $statement .= ';'; $statements['create_table'][md5($statement)] = $statement; } } @@ -948,23 +936,23 @@ * @param array MySQL result row * @return string Field definition */ - function assembleFieldDefinition($row) { + function assembleFieldDefinition($row) { $field = array($row['Type']); - if ($row['Null']=='NO') { + if ($row['Null'] == 'NO') { $field[] = 'NOT NULL'; } - if (!strstr($row['Type'],'blob') && !strstr($row['Type'],'text')) { + if (!strstr($row['Type'], 'blob') && !strstr($row['Type'], 'text')) { // Add a default value if the field is not auto-incremented (these fields never have a default definition) - if (!stristr($row['Extra'],'auto_increment')) { + if (!stristr($row['Extra'], 'auto_increment')) { - $field[] = 'default \''.addslashes($row['Default']).'\''; + $field[] = 'default \'' . addslashes($row['Default']) . '\''; } } if ($row['Extra']) { $field[] = $row['Extra']; } - return implode(' ',$field); + return implode(' ', $field); } /** @@ -975,7 +963,7 @@ * @param string Regex to filter SQL lines to include * @return array Array of SQL statements */ - function getStatementArray($sqlcode,$removeNonSQL=0,$query_regex='') { + function getStatementArray($sqlcode, $removeNonSQL = 0, $query_regex = '') { $sqlcodeArr = explode(LF, $sqlcode); // Based on the assumption that the sql-dump has @@ -986,24 +974,24 @@ $is_set = 0; // auto_increment fields cannot have a default value! - if (stristr($lineContent,'auto_increment')) { + if (stristr($lineContent, 'auto_increment')) { $lineContent = preg_replace('/ default \'0\'/i', '', $lineContent); } - 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 + 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 - $statementArray[$statementArrayPointer].= $lineContent; + $statementArray[$statementArrayPointer] .= $lineContent; $is_set = 1; } - if (substr(trim($lineContent),-1)==';') { + if (substr(trim($lineContent), -1) == ';') { if (isset($statementArray[$statementArrayPointer])) { - if (!trim($statementArray[$statementArrayPointer]) || ($query_regex && !preg_match('/'.$query_regex.'/i',trim($statementArray[$statementArrayPointer])))) { + if (!trim($statementArray[$statementArrayPointer]) || ($query_regex && !preg_match('/' . $query_regex . '/i', trim($statementArray[$statementArrayPointer])))) { unset($statementArray[$statementArrayPointer]); } } $statementArrayPointer++; } elseif ($is_set) { - $statementArray[$statementArrayPointer].= LF; + $statementArray[$statementArrayPointer] .= LF; } } @@ -1017,34 +1005,34 @@ * @param boolean If set, will count number of INSERT INTO statements following that table definition * @return array Array with table definitions in index 0 and count in index 1 */ - function getCreateTables($statements, $insertCountFlag=0) { + function getCreateTables($statements, $insertCountFlag = 0) { $crTables = array(); $insertCount = array(); foreach ($statements as $line => $lineContent) { $reg = array(); - if (preg_match('/^create[[:space:]]*table[[:space:]]*[`]?([[:alnum:]_]*)[`]?/i',substr($lineContent,0,100),$reg)) { + if (preg_match('/^create[[:space:]]*table[[:space:]]*[`]?([[:alnum:]_]*)[`]?/i', substr($lineContent, 0, 100), $reg)) { $table = trim($reg[1]); - if ($table) { + if ($table) { // table names are always lowercase on Windows! if (TYPO3_OS == 'WIN') { $table = strtolower($table); } $sqlLines = explode(LF, $lineContent); - foreach ($sqlLines as $k=>$v) { + foreach ($sqlLines as $k => $v) { - if (stristr($v,'auto_increment')) { + if (stristr($v, 'auto_increment')) { $sqlLines[$k] = preg_replace('/ default \'0\'/i', '', $v); } } $lineContent = implode(LF, $sqlLines); $crTables[$table] = $lineContent; } - } elseif ($insertCountFlag && preg_match('/^insert[[:space:]]*into[[:space:]]*[`]?([[:alnum:]_]*)[`]?/i',substr($lineContent,0,100),$reg)) { + } elseif ($insertCountFlag && preg_match('/^insert[[:space:]]*into[[:space:]]*[`]?([[:alnum:]_]*)[`]?/i', substr($lineContent, 0, 100), $reg)) { $nTable = trim($reg[1]); $insertCount[$nTable]++; } } - return array($crTables,$insertCount); + return array($crTables, $insertCount); } /** @@ -1054,13 +1042,13 @@ * @param string Table name * @return array Array of INSERT INTO statements where table match $table */ - function getTableInsertStatements($statements, $table) { + function getTableInsertStatements($statements, $table) { - $outStatements=array(); + $outStatements = array(); - foreach($statements as $line => $lineContent) { + foreach ($statements as $line => $lineContent) { $reg = array(); - if (preg_match('/^insert[[:space:]]*into[[:space:]]*[`]?([[:alnum:]_]*)[`]?/i',substr($lineContent,0,100),$reg)) { + if (preg_match('/^insert[[:space:]]*into[[:space:]]*[`]?([[:alnum:]_]*)[`]?/i', substr($lineContent, 0, 100), $reg)) { $nTable = trim($reg[1]); - if ($nTable && !strcmp($table,$nTable)) { + if ($nTable && !strcmp($table, $nTable)) { $outStatements[] = $lineContent; } } @@ -1075,13 +1063,13 @@ * @param array Array with keys that must match keys in $arr. Only where a key in this array is set and true will the query be executed (meant to be passed from a form checkbox) * @return mixed Array with error message from database if any occured. Otherwise true if everything was executed successfully. */ - function performUpdateQueries($arr,$keyArr) { + function performUpdateQueries($arr, $keyArr) { $result = array(); - if (is_array($arr)) { + if (is_array($arr)) { - foreach($arr as $key => $string) { + foreach ($arr as $key => $string) { - if (isset($keyArr[$key]) && $keyArr[$key]) { + if (isset($keyArr[$key]) && $keyArr[$key]) { $res = $GLOBALS['TYPO3_DB']->admin_query($string); - if ($res === false) { + if ($res === FALSE) { $result[$key] = $GLOBALS['TYPO3_DB']->sql_error(); } elseif (is_resource($res)) { $GLOBALS['TYPO3_DB']->sql_free_result($res); @@ -1089,10 +1077,10 @@ } } } - if (count($result) > 0) { + if (count($result) > 0) { return $result; } else { - return true; + return TRUE; } } @@ -1102,9 +1090,9 @@ * @return array List of tables. * @see t3lib_db::admin_get_tables() */ - function getListOfTables() { + function getListOfTables() { $whichTables = $GLOBALS['TYPO3_DB']->admin_get_tables(TYPO3_db); - foreach ($whichTables as $key=>&$value) { + foreach ($whichTables as $key => &$value) { $value = $key; } return $whichTables; @@ -1121,9 +1109,9 @@ * @param boolean If set, will show the prefix "Current value" if $currentValue is given. * @return string HTML table with checkboxes for update. Must be wrapped in a form. */ - function generateUpdateDatabaseForm_checkboxes($arr,$label,$checked=1,$iconDis=0,$currentValue=array(),$cVfullMsg=0) { + function generateUpdateDatabaseForm_checkboxes($arr, $label, $checked = 1, $iconDis = 0, $currentValue = array(), $cVfullMsg = 0) { $out = array(); - if (is_array($arr)) { + if (is_array($arr)) { $tableId = uniqid('table'); if (count($arr) > 1) { $out[] = ' @@ -1135,32 +1123,32 @@ '; } - foreach($arr as $key => $string) { + foreach ($arr as $key => $string) { $ico = ''; $warnings = array(); - if ($iconDis) { + if ($iconDis) { - if (preg_match('/^TRUNCATE/i',$string)) { + if (preg_match('/^TRUNCATE/i', $string)) { - $ico.= ' '; + $ico .= ' '; $warnings['clear_table_info'] = 'Clearing the table is sometimes neccessary when adding new keys. In case of cache_* tables this should not hurt at all. However, use it with care.'; - } elseif (stristr($string,' user_')) { + } elseif (stristr($string, ' user_')) { - $ico.= '(USER) '; + $ico .= '(USER) '; - } elseif (stristr($string,' app_')) { + } elseif (stristr($string, ' app_')) { - $ico.= '(APP) '; + $ico .= '(APP) '; - } elseif (stristr($string,' ttx_') || stristr($string,' tx_')) { + } elseif (stristr($string, ' ttx_') || stristr($string, ' tx_')) { - $ico.= '(EXT) '; + $ico .= '(EXT) '; } } - $out[]=' + $out[] = ' - + - + '; - if (isset($currentValue[$key])) { + if (isset($currentValue[$key])) { - $out[]=' + $out[] = ' - '.nl2br((!$cVfullMsg?"Current value: ":"").''.$currentValue[$key].'').' + ' . nl2br((!$cVfullMsg ? "Current value: " : "") . '' . $currentValue[$key] . '') . ' '; } } @@ -1168,14 +1156,14 @@ $out[] = ' - ' . implode('
',$warnings) . '
+ ' . implode('
', $warnings) . '
'; } - // Compile rows: + // Compile rows: $content = ' -

'.$label.'

+

' . $label . '

' . implode('', $out) . '
'; } @@ -1190,14 +1178,14 @@ * @return array Array with information about table. * @deprecated since TYPO3 4.2, this function will be removed in TYPO3 4.6, use ->getFieldDefinitions_fileContent() instead! */ - function getFieldDefinitions_sqlContent($fileContent) { + function getFieldDefinitions_sqlContent($fileContent) { t3lib_div::logDeprecatedFunction(); return $this->getFieldDefinitions_fileContent($fileContent); } } -if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_install.php']) { +if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_install.php']) { include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_install.php']); }