From: Fabii547 Date: Sat, 9 Feb 2019 10:19:21 +0000 (+0100) Subject: Use `TDatabaseObjectToggle` more often (#2846) X-Git-Tag: 5.2.0_Alpha_1~300 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=03ba10fa64a4cb0cb4640a91a718260470a3cdc4;p=GitHub%2FWoltLab%2FWCF.git Use `TDatabaseObjectToggle` more often (#2846) --- diff --git a/wcfsetup/install/files/lib/data/ad/AdAction.class.php b/wcfsetup/install/files/lib/data/ad/AdAction.class.php index c23294b505..49bdbeb313 100644 --- a/wcfsetup/install/files/lib/data/ad/AdAction.class.php +++ b/wcfsetup/install/files/lib/data/ad/AdAction.class.php @@ -3,6 +3,7 @@ namespace wcf\data\ad; use wcf\data\AbstractDatabaseObjectAction; use wcf\data\ISortableAction; use wcf\data\IToggleAction; +use wcf\data\TDatabaseObjectToggle; use wcf\system\condition\ConditionHandler; use wcf\system\exception\UserInputException; use wcf\system\WCF; @@ -19,6 +20,8 @@ use wcf\system\WCF; * @method AdEditor getSingleObject() */ class AdAction extends AbstractDatabaseObjectAction implements ISortableAction, IToggleAction { + use TDatabaseObjectToggle; + /** * @inheritDoc */ @@ -62,24 +65,6 @@ class AdAction extends AbstractDatabaseObjectAction implements ISortableAction, return parent::delete(); } - /** - * @inheritDoc - */ - public function toggle() { - foreach ($this->getObjects() as $ad) { - $ad->update([ - 'isDisabled' => $ad->isDisabled ? 0 : 1 - ]); - } - } - - /** - * @inheritDoc - */ - public function validateToggle() { - parent::validateUpdate(); - } - /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/data/category/CategoryAction.class.php b/wcfsetup/install/files/lib/data/category/CategoryAction.class.php index 3a673c5dd0..5581a2eb44 100644 --- a/wcfsetup/install/files/lib/data/category/CategoryAction.class.php +++ b/wcfsetup/install/files/lib/data/category/CategoryAction.class.php @@ -5,6 +5,7 @@ use wcf\data\AbstractDatabaseObjectAction; use wcf\data\ISortableAction; use wcf\data\IToggleAction; use wcf\data\IToggleContainerAction; +use wcf\data\TDatabaseObjectToggle; use wcf\system\category\CategoryHandler; use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\exception\PermissionDeniedException; @@ -26,6 +27,8 @@ use wcf\system\WCF; * @method CategoryEditor getSingleObject() */ class CategoryAction extends AbstractDatabaseObjectAction implements ISortableAction, IToggleAction, IToggleContainerAction { + use TDatabaseObjectToggle; + /** * categorized object type * @var \wcf\data\object\type\ObjectType @@ -86,17 +89,6 @@ class CategoryAction extends AbstractDatabaseObjectAction implements ISortableAc return $returnValue; } - /** - * @inheritDoc - */ - public function toggle() { - foreach ($this->getObjects() as $categoryEditor) { - $categoryEditor->update([ - 'isDisabled' => 1 - $categoryEditor->isDisabled - ]); - } - } - /** * @inheritDoc */ @@ -226,13 +218,6 @@ class CategoryAction extends AbstractDatabaseObjectAction implements ISortableAc } } - /** - * @inheritDoc - */ - public function validateToggle() { - $this->validateUpdate(); - } - /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/data/contact/recipient/ContactRecipientAction.class.php b/wcfsetup/install/files/lib/data/contact/recipient/ContactRecipientAction.class.php index 49951ba53e..55fdba35e8 100644 --- a/wcfsetup/install/files/lib/data/contact/recipient/ContactRecipientAction.class.php +++ b/wcfsetup/install/files/lib/data/contact/recipient/ContactRecipientAction.class.php @@ -3,6 +3,7 @@ namespace wcf\data\contact\recipient; use wcf\data\AbstractDatabaseObjectAction; use wcf\data\ISortableAction; use wcf\data\IToggleAction; +use wcf\data\TDatabaseObjectToggle; use wcf\system\exception\PermissionDeniedException; use wcf\system\exception\UserInputException; use wcf\system\WCF; @@ -20,6 +21,8 @@ use wcf\system\WCF; * @method ContactRecipientEditor getSingleObject() */ class ContactRecipientAction extends AbstractDatabaseObjectAction implements ISortableAction, IToggleAction { + use TDatabaseObjectToggle; + /** * @inheritDoc */ @@ -71,17 +74,6 @@ class ContactRecipientAction extends AbstractDatabaseObjectAction implements ISo } } - /** - * @inheritDoc - */ - public function toggle() { - foreach ($this->getObjects() as $object) { - $object->update([ - 'isDisabled' => $object->isDisabled ? 0 : 1 - ]); - } - } - /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/data/menu/item/MenuItemAction.class.php b/wcfsetup/install/files/lib/data/menu/item/MenuItemAction.class.php index 7c3c06da3f..353f82b7ee 100644 --- a/wcfsetup/install/files/lib/data/menu/item/MenuItemAction.class.php +++ b/wcfsetup/install/files/lib/data/menu/item/MenuItemAction.class.php @@ -4,6 +4,7 @@ use wcf\data\menu\Menu; use wcf\data\AbstractDatabaseObjectAction; use wcf\data\ISortableAction; use wcf\data\IToggleAction; +use wcf\data\TDatabaseObjectToggle; use wcf\system\exception\PermissionDeniedException; use wcf\system\exception\UserInputException; use wcf\system\WCF; @@ -22,6 +23,8 @@ use wcf\system\WCF; * @method MenuItemEditor getSingleObject() */ class MenuItemAction extends AbstractDatabaseObjectAction implements ISortableAction, IToggleAction { + use TDatabaseObjectToggle; + /** * @inheritDoc */ @@ -60,15 +63,6 @@ class MenuItemAction extends AbstractDatabaseObjectAction implements ISortableAc } } - /** - * @inheritDoc - */ - public function toggle() { - foreach ($this->getObjects() as $object) { - $object->update(['isDisabled' => $object->isDisabled ? 0 : 1]); - } - } - /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/data/notice/NoticeAction.class.php b/wcfsetup/install/files/lib/data/notice/NoticeAction.class.php index fedd64d5d5..7ee218b150 100644 --- a/wcfsetup/install/files/lib/data/notice/NoticeAction.class.php +++ b/wcfsetup/install/files/lib/data/notice/NoticeAction.class.php @@ -3,6 +3,7 @@ namespace wcf\data\notice; use wcf\data\AbstractDatabaseObjectAction; use wcf\data\ISortableAction; use wcf\data\IToggleAction; +use wcf\data\TDatabaseObjectToggle; use wcf\system\condition\ConditionHandler; use wcf\system\exception\UserInputException; use wcf\system\user\storage\UserStorageHandler; @@ -20,6 +21,8 @@ use wcf\system\WCF; * @method NoticeEditor getSingleObject() */ class NoticeAction extends AbstractDatabaseObjectAction implements ISortableAction, IToggleAction { + use TDatabaseObjectToggle; + /** * @inheritDoc */ @@ -106,17 +109,6 @@ class NoticeAction extends AbstractDatabaseObjectAction implements ISortableActi ]; } - /** - * @inheritDoc - */ - public function toggle() { - foreach ($this->getObjects() as $notice) { - $notice->update([ - 'isDisabled' => $notice->isDisabled ? 0 : 1 - ]); - } - } - /** * Validates the 'dismiss' action. */ @@ -124,13 +116,6 @@ class NoticeAction extends AbstractDatabaseObjectAction implements ISortableActi $this->getSingleObject(); } - /** - * @inheritDoc - */ - public function validateToggle() { - parent::validateUpdate(); - } - /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/data/page/PageAction.class.php b/wcfsetup/install/files/lib/data/page/PageAction.class.php index 1b57f0ad6e..bcdcb586bd 100644 --- a/wcfsetup/install/files/lib/data/page/PageAction.class.php +++ b/wcfsetup/install/files/lib/data/page/PageAction.class.php @@ -7,6 +7,7 @@ use wcf\data\AbstractDatabaseObjectAction; use wcf\data\ISearchAction; use wcf\data\ISortableAction; use wcf\data\IToggleAction; +use wcf\data\TDatabaseObjectToggle; use wcf\system\comment\CommentHandler; use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\exception\PermissionDeniedException; @@ -31,6 +32,8 @@ use wcf\system\WCF; * @method PageEditor getSingleObject() */ class PageAction extends AbstractDatabaseObjectAction implements ISearchAction, ISortableAction, IToggleAction { + use TDatabaseObjectToggle; + /** * @inheritDoc */ @@ -299,15 +302,6 @@ class PageAction extends AbstractDatabaseObjectAction implements ISearchAction, } } - /** - * @inheritDoc - */ - public function toggle() { - foreach ($this->getObjects() as $object) { - $object->update(['isDisabled' => $object->isDisabled ? 0 : 1]); - } - } - /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/data/trophy/TrophyAction.class.php b/wcfsetup/install/files/lib/data/trophy/TrophyAction.class.php index 9921ade654..121d07aa14 100644 --- a/wcfsetup/install/files/lib/data/trophy/TrophyAction.class.php +++ b/wcfsetup/install/files/lib/data/trophy/TrophyAction.class.php @@ -1,5 +1,6 @@ update(['isDisabled' => $trophy->isDisabled ? 0 : 1]); if (!$trophy->isDisabled) { - $disabledTrophyIDs[] = $trophy->trophyID; } else { @@ -182,22 +184,6 @@ class TrophyAction extends AbstractDatabaseObjectAction implements IToggleAction UserStorageHandler::getInstance()->resetAll('specialTrophies'); } - /** - * @inheritDoc - */ - public function validateToggle() { - WCF::getSession()->checkPermissions(['admin.trophy.canManageTrophy']); - - // read objects - if (empty($this->objects)) { - $this->readObjects(); - - if (empty($this->objects)) { - throw new UserInputException('objectIDs'); - } - } - } - /** * @inheritDoc */