Prevent duplicates in special trophy assignment
authorJoshua Rüsweg <ruesweg@woltlab.com>
Thu, 9 Jan 2020 22:12:36 +0000 (23:12 +0100)
committerJoshua Rüsweg <ruesweg@woltlab.com>
Thu, 9 Jan 2020 22:12:42 +0000 (23:12 +0100)
If a trophy is taken away and added again shortly afterwards, the error may occur that the trophy can be marked twice as "Special". In this case, this leads to an error. We prevent this by making the whole thing clear.

wcfsetup/install/files/lib/data/user/trophy/UserTrophyAction.class.php

index eff4a7a9ad342ceabdae16b29f5a46941247646a..dea4a5502b6aaf6de859236378c0235c6f125dbb 100644 (file)
@@ -69,9 +69,9 @@ class UserTrophyAction extends AbstractDatabaseObjectAction {
                                
                                if (!$hasTrophy) {
                                        $userProfileAction = new UserProfileAction([$userTrophy->getUserProfile()->getDecoratedObject()], 'updateSpecialTrophies', [
-                                               'trophyIDs' => array_merge(array_map(function($trophy) {
+                                               'trophyIDs' => array_unique(array_merge(array_map(function($trophy) {
                                                        return $trophy->trophyID;
-                                               }, $userTrophy->getUserProfile()->getSpecialTrophies()), [$userTrophy->trophyID])
+                                               }, $userTrophy->getUserProfile()->getSpecialTrophies()), [$userTrophy->trophyID]))
                                        ]);
                                        $userProfileAction->executeAction();
                                }