From: Alexander Ebert Date: Thu, 1 Aug 2013 22:22:59 +0000 (+0200) Subject: Rebuilding likes now rebuilds like objects X-Git-Tag: 2.0.0_Beta_7~66^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b1b041e27aa2538e6ee89576421e9768160107d6;p=GitHub%2FWoltLab%2FWCF.git Rebuilding likes now rebuilds like objects The cached users are not rebuilt yet, this will be added later. --- diff --git a/com.woltlab.wcf/objectType.xml b/com.woltlab.wcf/objectType.xml index d2ea058343..1bd8aa5f57 100644 --- a/com.woltlab.wcf/objectType.xml +++ b/com.woltlab.wcf/objectType.xml @@ -270,15 +270,16 @@ - com.woltlab.wcf.user + com.woltlab.wcf.like com.woltlab.wcf.rebuildData - - 70 + + -100 - com.woltlab.wcf.like + com.woltlab.wcf.user com.woltlab.wcf.rebuildData - + + 70 com.woltlab.wcf.attachment diff --git a/wcfsetup/install/files/lib/system/worker/LikeRebuildDataWorker.class.php b/wcfsetup/install/files/lib/system/worker/LikeRebuildDataWorker.class.php index 466b541c7f..801aaccf94 100644 --- a/wcfsetup/install/files/lib/system/worker/LikeRebuildDataWorker.class.php +++ b/wcfsetup/install/files/lib/system/worker/LikeRebuildDataWorker.class.php @@ -1,6 +1,8 @@ objectList->sqlOrderBy = 'like_table.likeID'; + $this->objectList->sqlOrderBy = 'like_table.objectID, like_table.likeID'; $this->objectList->getConditionBuilder()->add('like_table.objectUserID IS NOT NULL'); } @@ -42,22 +44,68 @@ class LikeRebuildDataWorker extends AbstractRebuildDataWorker { if (!$this->loopCount) { // reset activity points UserActivityPointHandler::getInstance()->reset('com.woltlab.wcf.like.activityPointEvent.receivedLikes'); + + // reset like object data + $sql = "UPDATE wcf".WCF_N."_like_object + SET likes = 0, + dislikes = 0, + cumulativeLikes = 0"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(); } $itemsToUser = array(); + $likeObjectData = array(); foreach ($this->objectList as $like) { - if (!$like->userID) { - continue; - } - if (!isset($itemsToUser[$like->objectUserID])) { $itemsToUser[$like->objectUserID] = 0; } $itemsToUser[$like->objectUserID]++; + + if (!isset($likeObjectData[$like->objectTypeID])) { + $likeObjectData[$like->objectTypeID] = array(); + } + if (!isset($likeObjectData[$like->objectTypeID][$like->objectID])) { + $likeObjectData[$like->objectTypeID][$like->objectID] = array( + 'likes' => 0, + 'dislikes' => 0, + 'cumulativeLikes' => 0 + ); + } + + if ($like->likeValue == Like::LIKE) { + $likeObjectData[$like->objectTypeID][$like->objectID]['likes']++; + } + else { + $likeObjectData[$like->objectTypeID][$like->objectID]['dislikes']++; + } + $likeObjectData[$like->objectTypeID][$like->objectID]['cumulativeLikes'] += $like->likeValue; } // update activity points UserActivityPointHandler::getInstance()->fireEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', $itemsToUser, false); + + $sql = "UPDATE wcf".WCF_N."_like_object + SET likes = ?, + dislikes = ?, + cumulativeLikes = ? + WHERE objectTypeID = ? + AND objectID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + + WCF::getDB()->beginTransaction(); + foreach ($likeObjectData as $objectTypeID => $objects) { + foreach ($objects as $objectID => $data) { + $statement->execute(array( + $data['likes'], + $data['dislikes'], + $data['cumulativeLikes'], + $objectTypeID, + $objectID + )); + } + } + WCF::getDB()->commitTransaction(); } }