Fix calculating of neutral reactions for objects after revert a reaction
authorJoshua Rüsweg <ruesweg@woltlab.com>
Fri, 5 Jul 2019 11:55:26 +0000 (13:55 +0200)
committerJoshua Rüsweg <ruesweg@woltlab.com>
Fri, 5 Jul 2019 11:56:01 +0000 (13:56 +0200)
wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php

index f9a20fcb5b7ba80282c439909510465466bc4021..986b38b09a604404d208ca969af7ed1e05b2a7a7 100644 (file)
@@ -617,6 +617,7 @@ class ReactionHandler extends SingletonFactory {
                // update existing object
                $likes = $likeObject->likes;
                $dislikes = $likeObject->dislikes;
+               $neutralReactions = $likeObject->neutralReactions;
                $cumulativeLikes = $likeObject->cumulativeLikes;
                $cachedReactions = @unserialize($likeObject->cachedReactions);
                if (!is_array($cachedReactions)) {
@@ -632,6 +633,12 @@ class ReactionHandler extends SingletonFactory {
                                $dislikes--;
                                $cumulativeLikes++;
                        }
+                       else if ($like->getReactionType()->isNeutral()) {
+                               $neutralReactions--;
+                       }
+                       else {
+                               throw new \LogicException('Unreachable');
+                       }
                        
                        if (isset($cachedReactions[$like->getReactionType()->reactionTypeID])) {
                                if (--$cachedReactions[$like->getReactionType()->reactionTypeID] == 0) {
@@ -643,6 +650,7 @@ class ReactionHandler extends SingletonFactory {
                        $updateData = [
                                'likes' => $likes,
                                'dislikes' => $dislikes,
+                               'neutralReactions' => $neutralReactions,
                                'cumulativeLikes' => $cumulativeLikes,
                                'cachedReactions' => serialize($cachedReactions)
                        ];