UpdateDatabase/MysqlEngineCharset.php
[Pman.Core] / UpdateDatabase / MysqlEngineCharset.php
index 0cf64ae..55fd0f2 100644 (file)
@@ -14,8 +14,12 @@ class Pman_Core_UpdateDatabase_MysqlEngineCharset {
     {
           
         $this->loadIniFiles(); //?? shared???
+        
+        // update the engine first - get's around 1000 character limit on indexes..cd
+        // however - Innodb does not support fulltext indexes, so this may fail...
+        $this->updateEngine(); 
+        
         $this->updateCharacterSet();
-        $this->updateEngine();
         
         
     }
@@ -42,12 +46,20 @@ class Pman_Core_UpdateDatabase_MysqlEngineCharset {
    
     function updateCharacterSet()
     {
+        $db = DB_DataObject::factory('core_enum')->getDatabaseConnection();
+        $views = $db->getListOf(  'views');
+        
+        
         foreach (array_keys($this->schema) as $tbl){
             
             if(strpos($tbl, '__keys') !== false ){
                 continue;
             }
             
+            if(in_array($tbl , $views)) {
+                continue;
+            }
+            
             $ce = DB_DataObject::factory('core_enum');
             
             $ce->query("
@@ -75,6 +87,8 @@ class Pman_Core_UpdateDatabase_MysqlEngineCharset {
             //as the default collation for stored procedure parameters is utf8_general_ci and you can't mix collations.
             
             $ce = DB_DataObject::factory('core_enum');
+            // not sure why, but convert to does not actually change the 'charset=' bit..
+            $ce->query("ALTER TABLE $tbl CHARSET=utf8");
             $ce->query("ALTER TABLE {$tbl} CONVERT TO CHARACTER SET  utf8 COLLATE utf8_general_ci");
             echo "utf8: FIXED {$tbl}\n";
             
@@ -82,20 +96,53 @@ class Pman_Core_UpdateDatabase_MysqlEngineCharset {
     }
     function updateEngine()
     {
+        $db = DB_DataObject::factory('core_enum');
+        $db->query("show variables like 'innodb_file_per_table'");
+        $db->fetch();
+        if ($db->Value == 'OFF') {
+            die("Error: set innodb_file_per_table = 1 in my.cnf\n\n");
+        }
+        
+        // get a list of table views...
+        // innodb in single files is far more efficient that MYD or one big innodb file.
+        // first check if database is using this format.
+        
+        
+        
+        $db = DB_DataObject::factory('core_enum')->getDatabaseConnection();
+        $views = $db->getListOf(  'views');
+        
+        
+        
+        
         foreach (array_keys($this->schema) as $tbl){
             
             if(strpos($tbl, '__keys') !== false ){
                 continue;
             }
+            if(in_array($tbl , $views)) {
+                continue;
+            }
             
             $ce = DB_DataObject::factory('core_enum');
             
-            $ce->query("select engine from information_schema.tables where table_schema='hydra' and table_name = 'core_enum'");
+            $ce->query("
+                select
+                    engine
+                from
+                    information_schema.tables
+                where
+                    table_schema='{$ce->database()}'
+                    and
+                    table_name = '{$tbl}'
+            ");
 
-            $ce->fetch();
+            if (!$ce->fetch()) {
+                continue;
+            }
             
             if($ce->engine == 'InnoDB' ){
-                echo "InnoDB: SKIP $tbln";
+                echo "InnoDB: SKIP $tbl\n";
                 continue;
             }
             // this used to be utf8_unicode_ci