From: Joshua Rüsweg Date: Thu, 3 May 2018 13:21:23 +0000 (+0200) Subject: Load reactions with initialization of the object X-Git-Tag: 5.2.0_Alpha_1~364^2~101^2~121 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=dc70504d586837966b1a05889cc9307f1abf491a;p=GitHub%2FWoltLab%2FWCF.git Load reactions with initialization of the object See #2508 --- diff --git a/wcfsetup/install/files/lib/data/like/object/LikeObject.class.php b/wcfsetup/install/files/lib/data/like/object/LikeObject.class.php index f1067e0996..1eef13a34d 100644 --- a/wcfsetup/install/files/lib/data/like/object/LikeObject.class.php +++ b/wcfsetup/install/files/lib/data/like/object/LikeObject.class.php @@ -2,9 +2,11 @@ declare(strict_types=1); namespace wcf\data\like\object; use wcf\data\object\type\ObjectTypeCache; +use wcf\data\reaction\type\ReactionTypeCache; use wcf\data\user\User; use wcf\data\DatabaseObject; use wcf\system\WCF; +use wcf\util\JSON; /** * Represents a liked object. @@ -71,7 +73,20 @@ class LikeObject extends DatabaseObject { $cachedReactions = @unserialize($data['cachedReactions']); if (is_array($cachedReactions)) { - $this->reactions = $cachedReactions; + foreach ($cachedReactions as $reactionTypeID => $reactionCount) { + $reaction = ReactionTypeCache::getInstance()->getReactionTypeByID($reactionTypeID); + + // prevent outdated reactions + if ($reaction !== null) { + $this->reactions[$reactionTypeID] = [ + 'reactionCount' => $reactionCount, + 'renderedReactionIcon' => $reaction->renderIcon(), + 'renderedReactionIconEncoded' => JSON::encode($reaction->renderIcon()), + 'reactionTitle' => $reaction->getTitle(), + 'reactionType' => $reaction->type + ]; + } + } } } }