From d996e907cd6d0cb8a5d0967b9b43422be76e6b89 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Wed, 8 Jan 2020 18:53:59 +0100 Subject: [PATCH] Add missing foreign keys logs during table creation via PHP API --- .../DatabaseTableChangeProcessor.class.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php b/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php index 261de6ae47..9f6fc5484d 100644 --- a/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php @@ -576,6 +576,26 @@ class DatabaseTableChangeProcessor { WCF::getDB()->commitTransaction(); } + /** + * Creates a done log entry for the given foreign key. + * + * @param string $tableName + * @param DatabaseTableForeignKey $foreignKey + */ + protected function createForeignKeyLog($tableName, DatabaseTableForeignKey $foreignKey) { + $sql = "INSERT INTO wcf" . WCF_N . "_package_installation_sql_log + (packageID, sqlTable, sqlIndex, isDone) + VALUES (?, ?, ?, ?)"; + $statement = WCF::getDB()->prepareStatement($sql); + + $statement->execute([ + $this->package->packageID, + $tableName, + $foreignKey->getName(), + 1 + ]); + } + /** * Creates the given table. * @@ -612,6 +632,9 @@ class DatabaseTableChangeProcessor { foreach ($table->getForeignKeys() as $foreignKey) { $this->dbEditor->addForeignKey($table->getName(), $foreignKey->getName(), $foreignKey->getData()); + + // foreign keys need to be explicitly logged for proper uninstallation + $this->createForeignKeyLog($table->getName(), $foreignKey); } } -- 2.20.1