From 167291206e57ffb9bc043308682061e5e499ff45 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 3 Aug 2021 16:13:58 +0200 Subject: [PATCH] Take the array key into account when matching up FOREIGN KEYs in DatabaseTableChangeProcessor MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Previously a FOREIGN KEY within the database that looks like this: […] FOREIGN KEY (someOtherUserID) REFERENCES wcf1_user (userID) […] would match up a FOREIGN KEY definition like the following: […] FOREIGN KEY (userID) REFERENCES wcf1_user (userID) […] Converted into the `getDiffData()` representation of the PHP DDL API these would like: [ 'columns' => 'someOtherUserID' , 'referencedColumns' => 'userID' , 'referencedTable' => 'wcf1_user' ] and [ 'columns' => 'userID' , 'referencedColumns' => 'userID' , 'referencedTable' => 'wcf1_user' ] respectively. Now taking the diff of the second array against the first array (subtracting the first from the second) will remove *both* 'userID' values, resulting in an empty difference, thus believing both FOREIGN KEYs are identical Fix this issue by using `array_diff_assoc` which will also take the key into account. --- .../database/table/DatabaseTableChangeProcessor.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 87fc5051e4..ec604781a6 100644 --- a/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php @@ -427,7 +427,7 @@ class DatabaseTableChangeProcessor { foreach ($table->getForeignKeys() as $foreignKey) { $matchingExistingForeignKey = null; foreach ($existingForeignKeys as $existingForeignKey) { - if (empty(array_diff($foreignKey->getDiffData(), $existingForeignKey->getDiffData()))) { + if (empty(array_diff_assoc($foreignKey->getDiffData(), $existingForeignKey->getDiffData()))) { $matchingExistingForeignKey = $existingForeignKey; break; } -- 2.20.1