UpdateDatabase/MysqlLinks.php
[Pman.Core] / UpdateDatabase / MysqlLinks.php
index 9ebbf98..e8ab14d 100644 (file)
@@ -38,6 +38,9 @@ class Pman_Core_UpdateDatabase_MysqlLinks {
           
         $this->loadIniFiles();
         $this->updateTableComments();
+        
+        $this->updateCharacterSet();
+        
         $ff = HTML_FlexyFramework::get();
         if (!empty($ff->Pman['enable_trigger_tests'])) {
             
@@ -169,7 +172,7 @@ class Pman_Core_UpdateDatabase_MysqlLinks {
             
             if (!isset($this->schema[$target_table])) {
                 echo "Skip $target_table  = table does not exist in schema\n";
-                continue;;
+                continue;
             }
         
             
@@ -195,11 +198,11 @@ class Pman_Core_UpdateDatabase_MysqlLinks {
                 $err = substr("Failed Delete {$target_table} refs {$source_table}:{$source_col}", 0, 64);
                 $trigger .="
                     SET mid = 0;
-                    SELECT count(*) into mid FROM {$source_table} WHERE {$source_col} = OLD.{$target_col} LIMIT 1;
-                    IF mid > 0 THEN
-                       
-                       UPDATE `$err` SET x = 1;
-                       
+                    IF OLD.{$target_col} > 0 THEN 
+                        SELECT count(*) into mid FROM {$source_table} WHERE {$source_col} = OLD.{$target_col} LIMIT 1;
+                        IF mid > 0 THEN   
+                           UPDATE `$err` SET x = 1;
+                        END IF;
                     END IF;
                 ";
             }
@@ -260,6 +263,13 @@ class Pman_Core_UpdateDatabase_MysqlLinks {
                 
                 $source_tbl = $tbl;
                 list($target_table , $target_col) = explode(':', $target);
+                
+                if (!isset($this->schema[$target_table])) {
+                    // skip... target table does not exist
+                    continue;
+                }
+                
+                
                 $err = substr("Fail: INSERT referenced {$tbl}:{$source_col}", 0, 64);
                 $trigger .="
                     SET mid = 0;
@@ -334,6 +344,12 @@ class Pman_Core_UpdateDatabase_MysqlLinks {
                 
                 $source_tbl = $tbl;
                 list($target_table , $target_col) = explode(':', $target);
+                
+                if (!isset($this->schema[$target_table])) {
+                    // skip... target table does not exist
+                    continue;
+                }
+                
                 $err = substr("Fail: UPDATE referenced {$tbl}:$source_col", 0, 64);
                 $trigger .="
                     SET mid = 0;
@@ -419,6 +435,13 @@ class Pman_Core_UpdateDatabase_MysqlLinks {
         return $ret;
     }
         
+    function updateCharacterSet()
+    {
+        foreach ($this->schema as $tbl => $map){
+            echo "CALL mysql_change_charset('{$tbl}') \n";
+            DB_DataObject::factory('core_enum')->query("CALL mysql_change_charset('{$tbl}')");
+        }
+    }
     
 }