Fix update of trophy points when editing a trophy
authorJoshua Rüsweg <josh@bastelstu.be>
Wed, 22 Nov 2017 14:18:30 +0000 (15:18 +0100)
committerJoshua Rüsweg <josh@bastelstu.be>
Wed, 22 Nov 2017 14:19:14 +0000 (15:19 +0100)
wcfsetup/install/files/lib/acp/form/TrophyEditForm.class.php

index 62a1bcfb8281022d9afdfac393e78a1911d409ad..903f61389ade17fbe789edb754232ef6f66067e4 100644 (file)
@@ -197,23 +197,25 @@ class TrophyEditForm extends TrophyAddForm {
                        UserStorageHandler::getInstance()->resetAll('specialTrophies');
                }
                
-               // update trophy points
-               $conditionBuilder = new PreparedStatementConditionBuilder();
-               $conditionBuilder->add('trophyID = ?', [$this->trophyID]);
-               $sql = "SELECT          COUNT(*) as count, userID
+               if ($this->isDisabled != $this->trophy->isDisabled) {
+                       // update trophy points
+                       $conditionBuilder = new PreparedStatementConditionBuilder();
+                       $conditionBuilder->add('trophyID = ?', [$this->trophyID]);
+                       $sql = "SELECT          COUNT(*) as count, userID
                        FROM            wcf".WCF_N."_user_trophy
                        ".$conditionBuilder."
                        GROUP BY        userID";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute($conditionBuilder->getParameters());
-               
-               while ($row = $statement->fetchArray()) {
-                       $userAction = new UserAction([$row['userID']], 'update', [
-                               'counters' => [
-                                       'trophyPoints' => $row['count'] * ($this->isDisabled) ? -1 : 1
-                               ]
-                       ]);
-                       $userAction->executeAction();
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute($conditionBuilder->getParameters());
+                       
+                       while ($row = $statement->fetchArray()) {
+                               $userAction = new UserAction([$row['userID']], 'update', [
+                                       'counters' => [
+                                               'trophyPoints' => $row['count'] * ($this->isDisabled) ? -1 : 1
+                                       ]
+                               ]);
+                               $userAction->executeAction();
+                       }
                }
                
                $this->saved();