Added support for 'DROP FOREIGN KEY'
authorAlexander Ebert <ebert@woltlab.com>
Sun, 21 Sep 2014 14:50:12 +0000 (16:50 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 21 Sep 2014 14:50:12 +0000 (16:50 +0200)
wcfsetup/install/files/lib/system/database/util/SQLParser.class.php

index 439ef7b2a93d53d71c25cacf8188728ab6c86afe..433f364eb2c7ecdd1570f1b41ca1633faca0a7c9 100644 (file)
@@ -157,6 +157,10 @@ class SQLParser {
                                else if (preg_match('~^ALTER\s+TABLE\s+(\w+)\s+DROP\s+(?:INDEX|KEY)\s+(\w+)~is', $query, $match)) {
                                        $this->executeDropIndexStatement($match[1], $match[2]);
                                }
+                               // drop foreign key
+                               else if (preg_match('~^ALTER\s+TABLE\s+(\w+)\s+DROP\s+FOREIGN KEY\s+(\w+)~is', $query, $match)) {
+                                       $this->executeDropForeignKeyStatement($match[1], self::getGenericIndexName($match[1], $match[2], 'fk'));
+                               }
                                // drop column
                                else if (preg_match('~^ALTER\s+TABLE\s+(\w+)\s+DROP\s+(?:COLUMN\s+)?(\w+)~is', $query, $match)) {
                                        $this->executeDropColumnStatement($match[1], $match[2]);
@@ -278,6 +282,16 @@ class SQLParser {
                WCF::getDB()->getEditor()->dropIndex($tableName, $indexName);
        }
        
+       /**
+        * Executes a 'DROP FOREIGN KEY' statement.
+        * 
+        * @param       string          $tableName
+        * @param       string          $indexName
+        */
+       protected function executeDropForeignKeyStatement($tableName, $indexName) {
+               WCF::getDB()->getEditor()->dropForeignKey($tableName, $indexName);
+       }
+       
        /**
         * Executes a 'DROP TABLE' statement.
         *