Filter out special trophies that no longer exist
authorAlexander Ebert <ebert@woltlab.com>
Tue, 19 Sep 2023 13:35:43 +0000 (15:35 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 19 Sep 2023 13:35:43 +0000 (15:35 +0200)
See https://www.woltlab.com/community/thread/301663-attempt-to-read-property-showorder-on-null/

wcfsetup/install/files/lib/data/user/UserProfile.class.php

index 3d3e0c9be1c1e569334b9b4e6216520d0f317583..02097beb41d54c031ba9eb4ea1d899f78f4d2f8b 100644 (file)
@@ -533,6 +533,16 @@ class UserProfile extends DatabaseObjectDecorator implements ITitledLinkObject
             UserStorageHandler::getInstance()->update($this->userID, 'specialTrophies', \serialize($specialTrophies));
         }
         $trophies = TrophyCache::getInstance()->getTrophiesByID($specialTrophies);
+
+        $filteredTrophies = $trophies = \array_filter($trophies);
+        if ($filteredTrophies !== $trophies) {
+            // One or more trophies no longer exists, remove them from the return
+            // value and force a cache reset.
+            $trophies = $filteredTrophies;
+
+            UserStorageHandler::getInstance()->reset([$this->userID], 'specialTrophies');
+        }
+
         Trophy::sort($trophies, 'showOrder');
 
         return $trophies;