// reset special trophies, if trophy is disabled
if ($this->isDisabled) {
- WCF::getDB()->prepareStatement("DELETE FROM wcf". WCF_N ."_user_special_trophy WHERE trophyID = ?")->execute([$this->trophyID]);
+ $sql = "DELETE FROM wcf". WCF_N ."_user_special_trophy WHERE trophyID = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute([$this->trophyID]);
+
UserStorageHandler::getInstance()->resetAll('specialTrophies');
}
* @inheritDoc
*/
public function toggle() {
+ $sql = "DELETE FROM wcf". WCF_N ."_user_special_trophy WHERE trophyID = ?";
+ $deleteStatement = WCF::getDB()->prepareStatement($sql);
+
foreach ($this->getObjects() as $trophy) {
$trophy->update(['isDisabled' => $trophy->isDisabled ? 0 : 1]);
if (!$trophy->isDisabled) {
- WCF::getDB()->prepareStatement("DELETE FROM wcf". WCF_N ."_user_special_trophy WHERE trophyID = ?")->execute([$trophy->trophyID]);
+ $deleteStatement->execute([$trophy->trophyID]);
}
}
$specialTrophies = UserStorageHandler::getInstance()->getField('specialTrophies', $this->userID);
if ($specialTrophies === null) {
- // load special trophies for the user
- $specialTrophies = [];
-
- $statement = WCF::getDB()->prepareStatement("SELECT trophyID FROM wcf".WCF_N."_user_special_trophy WHERE userID = ?");
- $statement->execute([$this->userID]);
-
- while ($trophyID = $statement->fetchColumn()) {
- $specialTrophies[] = $trophyID;
- }
+ // load special trophies for the user
+ $sql = "SELECT trophyID FROM wcf".WCF_N."_user_special_trophy WHERE userID = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute([$this->userID]);
+ $specialTrophies = $statement->fetchAll(\PDO::FETCH_COLUMN);
UserStorageHandler::getInstance()->update($this->userID, 'specialTrophies', serialize($specialTrophies));
}
$conditionBuilder->add('userID = ?', [$this->userID]);
$conditionBuilder->add('trophyID IN (?)', [$trophyDeleteIDs]);
- // reset some special trophies
- WCF::getDB()->prepareStatement("DELETE FROM wcf".WCF_N."_user_special_trophy ".$conditionBuilder)->execute($conditionBuilder->getParameters());
+ // reset the user special trophies
+ $sql = "DELETE FROM wcf".WCF_N."_user_special_trophy ".$conditionBuilder;
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute($conditionBuilder->getParameters());
UserStorageHandler::getInstance()->update($this->userID, 'specialTrophies', serialize($specialTrophies));
}
$this->readObjects();
}
+ $sql = "DELETE FROM wcf".WCF_N."_user_special_trophy WHERE userID = ?";
+ $deleteStatement = WCF::getDB()->prepareStatement($sql);
+
+ $sql = "INSERT INTO wcf".WCF_N."_user_special_trophy (userID, trophyID) VALUES (?, ?)";
+ $insertStatement = WCF::getDB()->prepareStatement($sql);
+
foreach ($this->getObjects() as $user) {
WCF::getDB()->beginTransaction();
- WCF::getDB()->prepareStatement("DELETE FROM wcf".WCF_N."_user_special_trophy WHERE userID = ?")->execute([$user->userID]);
+ // delete all user special trophies for the user
+ $deleteStatement->execute([$user->userID]);
if (!empty($this->parameters['trophyIDs'])) {
- $statement = WCF::getDB()->prepareStatement("INSERT INTO wcf".WCF_N."_user_special_trophy (userID, trophyID) VALUES (?, ?)");
-
foreach ($this->parameters['trophyIDs'] as $trophyID) {
- $statement->execute([
+ $insertStatement->execute([
$user->userID,
$trophyID
]);
$conditionBuilder = new PreparedStatementConditionBuilder();
$conditionBuilder->add('trophyID NOT IN (?)', [array_unique($userTrophyIDs)]);
$conditionBuilder->add('userID = ?', [$userID]);
- WCF::getDB()->prepareStatement("DELETE FROM wcf". WCF_N ."_user_special_trophy ". $conditionBuilder)->execute($conditionBuilder->getParameters());
+
+ $sql = "DELETE FROM wcf". WCF_N ."_user_special_trophy ". $conditionBuilder;
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute($conditionBuilder->getParameters());
UserStorageHandler::getInstance()->reset([$userID], 'specialTrophies');
}