From 6449f3a4ccc4e376a1bc70b8ea4962bcb1dba058 Mon Sep 17 00:00:00 2001 From: kevin_fourie Date: Fri, 14 Dec 2007 15:12:55 +0000 Subject: [PATCH] Merged in from DEV trunk... --- lib/database/schema.inc.php | 18 ++++++++++++------ sql/mysql/install/data.sql | 11 +++++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/database/schema.inc.php b/lib/database/schema.inc.php index 16c460c..a781ed8 100644 --- a/lib/database/schema.inc.php +++ b/lib/database/schema.inc.php @@ -65,12 +65,6 @@ class KTSchemaUtil $this->definePrimaryKeys(); $this->defineForeignKeys(); $this->defineOtherIndexes(); - $this->_exec('SET FOREIGN_KEY_CHECKS = 0'); - } - - public function __destruct() - { - $this->_exec('SET FOREIGN_KEY_CHECKS = 1'); } private function createFixUser() @@ -759,6 +753,13 @@ class KTSchemaUtil private function fixForeignKey($table, $field, $otherTable, $otherField) { + if ($table == $otherTable) + { + $this->_exec("create temporary table tmp_{$table}(id int);"); + $this->_exec("insert into tmp_{$table} select distinct id FROM {$table};"); + $this->_exec("insert into tmp_{$table} select distinct id FROM {$table};"); + $otherTable = "tmp_{$table}"; + } if ($otherTable == 'users' && $otherField == 'id') { $this->createFixUser(); @@ -769,6 +770,11 @@ class KTSchemaUtil $sql = "DELETE FROM $table WHERE $field is not null and $field not in (select distinct $otherField FROM $otherTable)"; $this->_exec($sql); + + if ($table == $otherTable) + { + $this->_exec("drop table tmp_{$table};"); + } } /** diff --git a/sql/mysql/install/data.sql b/sql/mysql/install/data.sql index 74fa571..47c614d 100644 --- a/sql/mysql/install/data.sql +++ b/sql/mysql/install/data.sql @@ -957,7 +957,14 @@ INSERT INTO `upgrades` VALUES (1,'sql*2.0.6*0*2.0.6/create_upgrade_table.sql','D (159,'sql*3.5.2*0*3.5.2/metadata_length.sql','Updates metadata length. Changes chars to varchars.','2007-11-21 00:00:00',1,'upgrade*3.5.2*99*upgrade3.5.2'), (160,'sql*3.5.2*0*3.5.2/scheduler_tasks.sql','Initialise some scheduler tasks.','2007-11-21 00:00:00',1,'upgrade*3.5.2*99*upgrade3.5.2'), (161,'sql*3.5.2*0*3.5.2/csv_mime.sql','Update mime types for CSV files.','2007-11-21 00:00:00',1,'upgrade*3.5.2*99*upgrade3.5.2'), -(162,'upgrade*3.5.2*99*upgrade3.5.2','Upgrade from version 3.5.1 to 3.5.2','2007-11-21 00:00:00',1,'upgrade*3.5.2*99*upgrade3.5.2'); +(162,'upgrade*3.5.2*99*upgrade3.5.2','Upgrade from version 3.5.1 to 3.5.2','2007-11-21 00:00:00',1,'upgrade*3.5.2*99*upgrade3.5.2'), +(163,'func*3.5.2*1*dropForeignKeys','Recreate db integrity: Drop foreign keys on the database','2007-11-21 00:00:00',1,'upgrade*3.5.2*99*upgrade3.5.2'), +(164,'func*3.5.2*2*dropPrimaryKeys','Recreate db integrity:Drop primary keys on the database','2007-11-21 00:00:00',1,'upgrade*3.5.2*99*upgrade3.5.2'), +(165,'func*3.5.2*3*dropIndexes','Recreate db integrity:Drop indexes on the database','2007-11-21 00:00:00',1,'upgrade*3.5.2*99*upgrade3.5.2'), +(166,'func*3.5.2*4*createPrimaryKeys','Recreate db integrity:Create primary keys on the database','2007-11-21 00:00:00',1,'upgrade*3.5.2*99*upgrade3.5.2'), +(167,'func*3.5.2*5*createForeignKeys','Recreate db integrity:Create foreign keys on the database','2007-11-21 00:00:00',1,'upgrade*3.5.2*99*upgrade3.5.2'), +(168,'func*3.5.2*6*createIndexes','Recreate db integrity:Create indexes on the database','2007-11-21 00:00:00',1,'upgrade*3.5.2*99*upgrade3.5.2'), +(169,'sql*3.5.2*0*3.5.2/plugins_orderby.sql','Database upgrade to version 3.5.2: Plugins orderby','2007-11-21 00:00:00',1,'upgrade*3.5.2*99*upgrade3.5.2'); /*!40000 ALTER TABLE `upgrades` ENABLE KEYS */; UNLOCK TABLES; @@ -1814,7 +1821,7 @@ UNLOCK TABLES; LOCK TABLES `zseq_upgrades` WRITE; /*!40000 ALTER TABLE `zseq_upgrades` DISABLE KEYS */; -INSERT INTO `zseq_upgrades` VALUES (162); +INSERT INTO `zseq_upgrades` VALUES (169); /*!40000 ALTER TABLE `zseq_upgrades` ENABLE KEYS */; UNLOCK TABLES; -- libgit2 0.21.4