From: Joshua Rüsweg Date: Wed, 1 Aug 2018 11:08:24 +0000 (+0200) Subject: Rebuild reaction stats on user rebuilding X-Git-Tag: 5.2.0_Alpha_1~364^2~101^2~47 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=557115b51c48d5591adc48946893e44e2d48e45e;p=GitHub%2FWoltLab%2FWCF.git Rebuild reaction stats on user rebuilding See #2508 --- diff --git a/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php b/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php index 4c8f58066b..de4c281876 100644 --- a/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php +++ b/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php @@ -1,6 +1,7 @@ getEnabledReactionTypes() as $reactionType) { + switch ($reactionType->type) { + case ReactionType::REACTION_TYPE_POSITIVE: + $positiveReactionTypes[] = $reactionType->reactionTypeID; + break; + + case ReactionType::REACTION_TYPE_NEGATIVE: + $negativeReactionTypes[] = $reactionType->reactionTypeID; + break; + + case ReactionType::REACTION_TYPE_NEUTRAL: + $neutralReactionTypes[] = $reactionType->reactionTypeID; + break; + + default: + throw new \LogicException('Unreachable'); + } + } + + + $sql = "UPDATE wcf".WCF_N."_user user_table SET"; + + if (!empty($positiveReactionTypes)) { + $sql .= " likesReceived = ( SELECT COUNT(*) FROM wcf".WCF_N."_like WHERE objectUserID = user_table.userID - AND likeValue = ".Like::LIKE." - ) - ".$conditionBuilder; + AND reactionTypeID IN (". implode(',', $positiveReactionTypes) .") + ), positiveReactionsReceived = ( + SELECT COUNT(*) + FROM wcf".WCF_N."_like + WHERE objectUserID = user_table.userID + AND reactionTypeID IN (". implode(',', $positiveReactionTypes) ."))"; + } + else { + $sql .= " likesReceived = 0, positiveReactionsReceived = 0"; + } + + if (!empty($negativeReactionTypes)) { + $sql .= ", negativeReactionsReceived = ( + SELECT COUNT(*) + FROM wcf".WCF_N."_like + WHERE objectUserID = user_table.userID + AND reactionTypeID IN (". implode(',', $negativeReactionTypes) ."))"; + } + else { + $sql .= ", negativeReactionsReceived = 0"; + } + + if (!empty($neutralReactionTypes)) { + $sql .= ", neutralReactionsReceived = ( + SELECT COUNT(*) + FROM wcf".WCF_N."_like + WHERE objectUserID = user_table.userID + AND reactionTypeID IN (". implode(',', $neutralReactionTypes) ."))"; + } + else { + $sql .= ", neutralReactionsReceived = 0"; + } + + $sql .= " ".$conditionBuilder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); }