UpdateDatabase/MysqlEngineCharset.php
[Pman.Core] / UpdateDatabase / MysqlEngineCharset.php
index 5354207..403a6d0 100644 (file)
@@ -7,15 +7,19 @@
 class Pman_Core_UpdateDatabase_MysqlEngineCharset {
     
     var $dburl;
-    var $schema;
-    var $links;
+    var $schema = array();
+    var $links = array();
     
     function __construct()
     {
           
         $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();
         
         
     }
@@ -32,6 +36,9 @@ class Pman_Core_UpdateDatabase_MysqlEngineCharset {
         
         
         $iniCache = $ff->DB_DataObject[$dbini];
+        if (!file_exists($iniCache)) {
+            return;
+        }
         
         $this->schema = parse_ini_file($iniCache, true);
         $this->links = parse_ini_file(preg_replace('/\.ini$/', '.links.ini', $iniCache), true);
@@ -42,12 +49,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("
@@ -65,7 +80,9 @@ class Pman_Core_UpdateDatabase_MysqlEngineCharset {
                         T.table_name = '{$tbl}' -- COLLATE utf8_general_ci
             ");
                      
-            $ce->fetch();
+            if (!$ce->fetch()) {
+                continue;
+            }
             
             if($ce->csname == 'utf8' && $ce->collatename == 'utf8_general_ci'){
                 echo "utf8: SKIP $tbl\n";
@@ -84,17 +101,50 @@ 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 $tbl\n";