* Improvements to Install Tool:
authorMichael Stucki <michael.stucki@typo3.org>
Mon, 3 Mar 2008 16:18:06 +0000 (16:18 +0000)
committerMichael Stucki <michael.stucki@typo3.org>
Mon, 3 Mar 2008 16:18:06 +0000 (16:18 +0000)
  - Detect differences in table engine and table character set during DB compare

git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@3365 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_db.php
t3lib/class.t3lib_install.php

index fb7ddbf..e38dcbb 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,6 +15,7 @@
        * Improvements to Install Tool:
                - Cleanup in t3lib_install
                - Fixed bug #7589: FULLTEXT keys are not processed correctly
+               - Detect differences in table engine and table character set during DB compare
        * Fix DB field types for static_tsconfig_help
 
 2008-03-03  Ingo Renner  <ingo@typo3.org>
index 2eb8992..65dea28 100755 (executable)
@@ -976,16 +976,18 @@ class t3lib_DB {
         * In a DBAL this method should 1) look up all tables from the DBMS  of the _DEFAULT handler and then 2) add all tables *configured* to be managed by other handlers
         * Usage count/core: 2
         *
-        * @return      array           Tables in an array (tablename is in both key and value)
+        * @return      array           Tables in an array with tablename as key and an array with status information as value
         */
        function admin_get_tables()     {
                $whichTables = array();
-               $tables_result = mysql_list_tables(TYPO3_db, $this->link);
+
+               $tables_result = mysql_query('SHOW TABLE STATUS FROM '.TYPO3_db, $this->link);
                if (!mysql_error())     {
                        while ($theTable = mysql_fetch_assoc($tables_result)) {
-                               $whichTables[current($theTable)] = current($theTable);
+                               $whichTables[$theTable['Name']] = $theTable;
                        }
                }
+
                return $whichTables;
        }
 
index 578d261..b45f1f3 100755 (executable)
@@ -443,7 +443,7 @@ class t3lib_install {
                echo $GLOBALS['TYPO3_DB']->sql_error();
 
                $tables = $GLOBALS['TYPO3_DB']->admin_get_tables(TYPO3_db);
-               foreach ($tables as $tableName) {
+               foreach ($tables as $tableName => $tableStatus) {
 
                                // Fields:
                        $fieldInformation = $GLOBALS['TYPO3_DB']->admin_get_fields($tableName);
@@ -475,6 +475,20 @@ class t3lib_install {
                                }
                                $tempKeysPrefix[$tableName][$keyName] = $prefix;
                        }
+
+                               // Table status (storage engine, collaction, etc.)
+                       if (is_array($tableStatus)) {
+                               $tableExtraFields = array(
+                                       'Engine' => 'ENGINE',
+                                       'Collation' => 'COLLATE',
+                               );
+
+                               foreach ($tableExtraFields as $mysqlKey=>$internalKey) {
+                                       if (isset($tableStatus[$mysqlKey])) {
+                                               $total[$tableName]['extra'][$internalKey] = $tableStatus[$mysqlKey];
+                                       }
+                               }
+                       }
                }
 
                        // Compile key information:
@@ -511,11 +525,15 @@ class t3lib_install {
                                                $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;
                                        } else {
-                                               $keyTypes = explode(',','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);
+                                                                       if ($fieldN=='COLLATE') {
+                                                                               continue;       // TODO: collation support is currently disabled (needs more testing)
+                                                                       }
+
                                                                        if (!isset($FDcomp[$table][$theKey][$fieldN])) {
                                                                                $extraArr[$table][$theKey][$fieldN] = $fieldC;
                                                                        } else {
@@ -614,6 +632,25 @@ class t3lib_install {
                                                        }
                                                }
                                        }
+                                       if (is_array($info['extra'])) {
+                                               $extras = array();
+                                               $extras_currentValue = array();
+                                               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']
+                                                                       $extras[] = $fN.'='.$fV;
+                                                                       $extras_currentValue[] = $fN.'='.$diffArr['diff_currentValues'][$table]['extra'][$fN];
+                                                               }
+                                                       }
+                                               }
+                                               if (count($extras)) {
+                                                       $statement = 'ALTER TABLE '.$table.' '.implode(' ',$extras).';';
+                                                       $statements['change'][md5($statement)] = $statement;
+                                                       $statements['change_currentValue'][md5($statement)] = implode(' ',$extras_currentValue);
+                                               }
+                                       }
                                        if ($info['whole_table']) {
                                                if ($remove) {
                                                        if (substr($table,0,strlen($deletedPrefixKey))!=$deletedPrefixKey) {
@@ -807,7 +844,7 @@ class t3lib_install {
         */
        function getListOfTables()      {
                $whichTables = $GLOBALS['TYPO3_DB']->admin_get_tables(TYPO3_db);
-               return $whichTables;
+               return array_keys($whichTables);
        }
 
        /**