From 530a084ab6d5a41e953920f890276da428fa9c03 Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Sat, 6 Feb 2021 12:29:07 +0100 Subject: [PATCH] Use `User::getUserOptionID` instead of internal cache Fixes #3936 --- wcfsetup/install/files/lib/page/TrophyPage.class.php | 10 ++++++---- .../system/box/UserTrophyListBoxController.class.php | 11 ++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/wcfsetup/install/files/lib/page/TrophyPage.class.php b/wcfsetup/install/files/lib/page/TrophyPage.class.php index 521dbc75d0..f45699f1ab 100644 --- a/wcfsetup/install/files/lib/page/TrophyPage.class.php +++ b/wcfsetup/install/files/lib/page/TrophyPage.class.php @@ -7,6 +7,7 @@ use wcf\data\trophy\Trophy; use wcf\data\trophy\TrophyCache; use wcf\data\user\trophy\UserTrophy; use wcf\data\user\trophy\UserTrophyList; +use wcf\data\user\User; use wcf\system\cache\builder\UserOptionCacheBuilder; use wcf\system\cache\runtime\UserProfileRuntimeCache; use wcf\system\database\util\PreparedStatementConditionBuilder; @@ -143,20 +144,21 @@ class TrophyPage extends MultipleLinkPage $this->objectList->getConditionBuilder()->add('user_trophy.trophyID = ?', [$this->trophy->getObjectID()]); $canViewTrophyDefaultValue = UserOptionCacheBuilder::getInstance()->getData()['options']['canViewTrophies']->defaultValue; + $canViewTrophiesOptionID = User::getUserOptionID('canViewTrophies'); if (!WCF::getUser()->userID) { $this->objectList->getConditionBuilder()->add('user_trophy.userID IN ( SELECT userID FROM wcf' . WCF_N . '_user_option_value - WHERE COALESCE(userOption' . UserOptionCacheBuilder::getInstance()->getData()['options']['canViewTrophies']->optionID . ', ' . $canViewTrophyDefaultValue . ') = 0)'); + WHERE COALESCE(userOption' . $canViewTrophiesOptionID . ', ' . $canViewTrophyDefaultValue . ') = 0)'); } elseif (!WCF::getSession()->getPermission('admin.general.canViewPrivateUserOptions')) { $conditionBuilder = new PreparedStatementConditionBuilder(false, 'OR'); $conditionBuilder->add('user_trophy.userID IN ( SELECT userID FROM wcf' . WCF_N . '_user_option_value WHERE ( - COALESCE(userOption' . UserOptionCacheBuilder::getInstance()->getData()['options']['canViewTrophies']->optionID . ', ' . $canViewTrophyDefaultValue . ') = 0 - OR COALESCE(userOption' . UserOptionCacheBuilder::getInstance()->getData()['options']['canViewTrophies']->optionID . ', ' . $canViewTrophyDefaultValue . ') = 1 + COALESCE(userOption' . $canViewTrophiesOptionID . ', ' . $canViewTrophyDefaultValue . ') = 0 + OR COALESCE(userOption' . $canViewTrophiesOptionID . ', ' . $canViewTrophyDefaultValue . ') = 1 ) )'); @@ -164,7 +166,7 @@ class TrophyPage extends MultipleLinkPage $friendshipConditionBuilder->add('user_trophy.userID IN ( SELECT userID FROM wcf' . WCF_N . '_user_option_value - WHERE COALESCE(userOption' . UserOptionCacheBuilder::getInstance()->getData()['options']['canViewTrophies']->optionID . ', ' . $canViewTrophyDefaultValue . ') = 2 + WHERE COALESCE(userOption' . $canViewTrophiesOptionID . ', ' . $canViewTrophyDefaultValue . ') = 2 )'); $friendshipConditionBuilder->add( 'user_trophy.userID IN ( diff --git a/wcfsetup/install/files/lib/system/box/UserTrophyListBoxController.class.php b/wcfsetup/install/files/lib/system/box/UserTrophyListBoxController.class.php index 5e73c64a24..47e31a2633 100644 --- a/wcfsetup/install/files/lib/system/box/UserTrophyListBoxController.class.php +++ b/wcfsetup/install/files/lib/system/box/UserTrophyListBoxController.class.php @@ -3,7 +3,7 @@ namespace wcf\system\box; use wcf\data\user\trophy\UserTrophyList; -use wcf\system\cache\builder\UserOptionCacheBuilder; +use wcf\data\user\User; use wcf\system\cache\runtime\UserProfileRuntimeCache; use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\WCF; @@ -94,11 +94,12 @@ class UserTrophyListBoxController extends AbstractDatabaseObjectListBoxControlle $list->getConditionBuilder()->add('trophy.isDisabled = ?', [0]); $list->getConditionBuilder()->add('category.isDisabled = ?', [0]); + $canViewTrophiesOptionID = User::getUserOptionID('canViewTrophies'); if (!WCF::getUser()->userID) { $list->getConditionBuilder()->add('user_trophy.userID IN ( SELECT userID FROM wcf' . WCF_N . '_user_option_value - WHERE userOption' . UserOptionCacheBuilder::getInstance()->getData()['options']['canViewTrophies']->optionID . ' = 0 + WHERE userOption' . $canViewTrophiesOptionID . ' = 0 )'); } elseif (!WCF::getSession()->getPermission('admin.general.canViewPrivateUserOptions')) { $conditionBuilder = new PreparedStatementConditionBuilder(false, 'OR'); @@ -106,8 +107,8 @@ class UserTrophyListBoxController extends AbstractDatabaseObjectListBoxControlle SELECT userID FROM wcf' . WCF_N . '_user_option_value WHERE ( - userOption' . UserOptionCacheBuilder::getInstance()->getData()['options']['canViewTrophies']->optionID . ' = 0 - OR userOption' . UserOptionCacheBuilder::getInstance()->getData()['options']['canViewTrophies']->optionID . ' = 1 + userOption' . $canViewTrophiesOptionID . ' = 0 + OR userOption' . $canViewTrophiesOptionID . ' = 1 ) )'); @@ -115,7 +116,7 @@ class UserTrophyListBoxController extends AbstractDatabaseObjectListBoxControlle $friendshipConditionBuilder->add('user_trophy.userID IN ( SELECT userID FROM wcf' . WCF_N . '_user_option_value - WHERE userOption' . UserOptionCacheBuilder::getInstance()->getData()['options']['canViewTrophies']->optionID . ' = 2 + WHERE userOption' . $canViewTrophiesOptionID . ' = 2 )'); $friendshipConditionBuilder->add( 'user_trophy.userID IN ( -- 2.20.1