Commit 6449f3a4ccc4e376a1bc70b8ea4962bcb1dba058

Authored by kevin_fourie
1 parent a29e6ddd

Merged in from DEV trunk...

KTS-2743
"upgrade functionality needs to apply foreign key constrains."
Implemented.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-2743
"upgrade functionality needs to apply foreign key constrains."
Updated. Prevent a clean install having to go through the process of having foreign keys applied again.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@7826 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/database/schema.inc.php
@@ -65,12 +65,6 @@ class KTSchemaUtil @@ -65,12 +65,6 @@ class KTSchemaUtil
65 $this->definePrimaryKeys(); 65 $this->definePrimaryKeys();
66 $this->defineForeignKeys(); 66 $this->defineForeignKeys();
67 $this->defineOtherIndexes(); 67 $this->defineOtherIndexes();
68 - $this->_exec('SET FOREIGN_KEY_CHECKS = 0');  
69 - }  
70 -  
71 - public function __destruct()  
72 - {  
73 - $this->_exec('SET FOREIGN_KEY_CHECKS = 1');  
74 } 68 }
75 69
76 private function createFixUser() 70 private function createFixUser()
@@ -759,6 +753,13 @@ class KTSchemaUtil @@ -759,6 +753,13 @@ class KTSchemaUtil
759 753
760 private function fixForeignKey($table, $field, $otherTable, $otherField) 754 private function fixForeignKey($table, $field, $otherTable, $otherField)
761 { 755 {
  756 + if ($table == $otherTable)
  757 + {
  758 + $this->_exec("create temporary table tmp_{$table}(id int);");
  759 + $this->_exec("insert into tmp_{$table} select distinct id FROM {$table};");
  760 + $this->_exec("insert into tmp_{$table} select distinct id FROM {$table};");
  761 + $otherTable = "tmp_{$table}";
  762 + }
762 if ($otherTable == 'users' && $otherField == 'id') 763 if ($otherTable == 'users' && $otherField == 'id')
763 { 764 {
764 $this->createFixUser(); 765 $this->createFixUser();
@@ -769,6 +770,11 @@ class KTSchemaUtil @@ -769,6 +770,11 @@ class KTSchemaUtil
769 770
770 $sql = "DELETE FROM $table WHERE $field is not null and $field not in (select distinct $otherField FROM $otherTable)"; 771 $sql = "DELETE FROM $table WHERE $field is not null and $field not in (select distinct $otherField FROM $otherTable)";
771 $this->_exec($sql); 772 $this->_exec($sql);
  773 +
  774 + if ($table == $otherTable)
  775 + {
  776 + $this->_exec("drop table tmp_{$table};");
  777 + }
772 } 778 }
773 779
774 /** 780 /**
sql/mysql/install/data.sql
No preview for this file type