Use `TDatabaseObjectToggle` more often (#2846)
authorFabii547 <Fabii547@users.noreply.github.com>
Sat, 9 Feb 2019 10:19:21 +0000 (11:19 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 9 Feb 2019 10:19:21 +0000 (11:19 +0100)
wcfsetup/install/files/lib/data/ad/AdAction.class.php
wcfsetup/install/files/lib/data/category/CategoryAction.class.php
wcfsetup/install/files/lib/data/contact/recipient/ContactRecipientAction.class.php
wcfsetup/install/files/lib/data/menu/item/MenuItemAction.class.php
wcfsetup/install/files/lib/data/notice/NoticeAction.class.php
wcfsetup/install/files/lib/data/page/PageAction.class.php
wcfsetup/install/files/lib/data/trophy/TrophyAction.class.php

index c23294b505d76c824e4a50b02dac60a968722d1b..49bdbeb31356b08ee22157a864c2ede5eb6bc013 100644 (file)
@@ -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
         */
index 3a673c5dd00bed3587af7afd652db24b6be21a6d..5581a2eb44047152af38f36b056c65034739ba57 100644 (file)
@@ -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
         */
index 49951ba53e9efe9083c43c6e5a027839bbe2a1a7..55fdba35e8f14b45efc4c668ee11af3bc28c23c2 100644 (file)
@@ -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
         */
index 7c3c06da3f9d6951ecaf9a65782c4656928238b3..353f82b7eec64963c6a58623806d61440d885ecc 100644 (file)
@@ -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
         */
index fedd64d5d5c5baf98f3c45d88e851bfb6df6f11f..7ee218b1504ae626ef3108a4152ae7cd17e20b18 100644 (file)
@@ -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
         */
index 1b57f0ad6ee267730abfe52e684b4f296cd3bd57..bcdcb586bd782121451c5a0a59a36817c46fa2d8 100644 (file)
@@ -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
         */
index 9921ade6544f9b1d195bc416372a78132349a88a..121d07aa1473cf2eaaf8e442f4d3c5cf4b3fa4fe 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\data\trophy;
+use wcf\data\TDatabaseObjectToggle;
 use wcf\data\user\trophy\UserTrophyAction;
 use wcf\data\user\trophy\UserTrophyList;
 use wcf\data\user\UserAction;
@@ -29,6 +30,8 @@ use wcf\system\WCF;
  * @method     TrophyEditor            getSingleObject()
  */
 class TrophyAction extends AbstractDatabaseObjectAction implements IToggleAction, IUploadAction, ISortableAction {
+       use TDatabaseObjectToggle;
+       
        /**
         * @inheritDoc
         */
@@ -123,7 +126,6 @@ class TrophyAction extends AbstractDatabaseObjectAction implements IToggleAction
                        $trophy->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
         */