add TDatabaseObjectToggle trait
authormutec <webmaster@mysterycode.de>
Sun, 28 Oct 2018 14:17:42 +0000 (15:17 +0100)
committermutec <webmaster@mysterycode.de>
Thu, 1 Nov 2018 09:16:06 +0000 (10:16 +0100)
see #2728

wcfsetup/install/files/lib/data/TDatabaseObjectToggle.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/captcha/question/CaptchaQuestionAction.class.php
wcfsetup/install/files/lib/data/cronjob/CronjobAction.class.php
wcfsetup/install/files/lib/data/custom/option/CustomOptionAction.class.php
wcfsetup/install/files/lib/data/language/LanguageAction.class.php
wcfsetup/install/files/lib/data/package/update/server/PackageUpdateServerAction.class.php
wcfsetup/install/files/lib/data/paid/subscription/PaidSubscriptionAction.class.php
wcfsetup/install/files/lib/data/style/StyleAction.class.php
wcfsetup/install/files/lib/data/user/group/assignment/UserGroupAssignmentAction.class.php
wcfsetup/install/files/lib/data/user/option/UserOptionAction.class.php

diff --git a/wcfsetup/install/files/lib/data/TDatabaseObjectToggle.class.php b/wcfsetup/install/files/lib/data/TDatabaseObjectToggle.class.php
new file mode 100644 (file)
index 0000000..2c2eace
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+namespace wcf\data;
+
+/**
+ * Default implementation of the `IToggleAction` interface.
+ * 
+ * @author     Florian Gail
+ * @copyright  2001-2018 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\Data
+ * @since      3.2
+ *
+ * @mixin      AbstractDatabaseObjectAction
+ */
+trait TDatabaseObjectToggle {
+       /**
+        * Validates the "toggle" action.
+        */
+       public function validateToggle() {
+               $this->validateUpdate();
+       }
+       
+       /**
+        * Toggles the "isDisabled" status of the relevant objects.
+        */
+       public function toggle() {
+               foreach ($this->getObjects() as $object) {
+                       $object->update([
+                               'isDisabled' => $object->isDisabled ? 0 : 1
+                       ]);
+               }
+       }
+}
index 99389fc20b7e02a2be4edaaed30fb02f3fa8e67e..d00afcedf5a4ff4c40bed23c5d0169be5337b8ea 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\data\captcha\question;
 use wcf\data\AbstractDatabaseObjectAction;
 use wcf\data\IToggleAction;
+use wcf\data\TDatabaseObjectToggle;
 
 /**
  * Executes captcha question-related actions.
@@ -16,6 +17,8 @@ use wcf\data\IToggleAction;
  * @method     CaptchaQuestionEditor           getSingleObject()
  */
 class CaptchaQuestionAction extends AbstractDatabaseObjectAction implements IToggleAction {
+       use TDatabaseObjectToggle;
+       
        /**
         * @inheritDoc
         */
@@ -25,22 +28,4 @@ class CaptchaQuestionAction extends AbstractDatabaseObjectAction implements ITog
         * @inheritDoc
         */
        protected $permissionsUpdate = ['admin.captcha.canManageCaptchaQuestion'];
-       
-       /**
-        * @inheritDoc
-        */
-       public function toggle() {
-               foreach ($this->getObjects() as $question) {
-                       $question->update([
-                               'isDisabled' => $question->isDisabled ? 0 : 1
-                       ]);
-               }
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function validateToggle() {
-               parent::validateUpdate();
-       }
 }
index 5c05e42023bd172e40d98e9b08d20ca18661ea68..f84aee04552d8a5bef640f71d231907c28ce3a57 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\data\cronjob;
 use wcf\data\cronjob\log\CronjobLogEditor;
+use wcf\data\TDatabaseObjectToggle;
 use wcf\data\user\User;
 use wcf\data\AbstractDatabaseObjectAction;
 use wcf\data\IToggleAction;
@@ -23,6 +24,8 @@ use wcf\util\DateUtil;
  * @method     CronjobEditor           getSingleObject()
  */
 class CronjobAction extends AbstractDatabaseObjectAction implements IToggleAction {
+       use TDatabaseObjectToggle;
+       
        /**
         * @inheritDoc
         */
@@ -92,17 +95,6 @@ class CronjobAction extends AbstractDatabaseObjectAction implements IToggleActio
                }
        }
        
-       /**
-        * @inheritDoc
-        */
-       public function toggle() {
-               foreach ($this->getObjects() as $cronjob) {
-                       $cronjob->update([
-                               'isDisabled' => $cronjob->isDisabled ? 0 : 1
-                       ]);
-               }
-       }
-       
        /**
         * Validates the 'execute' action.
         */
index cba73d476b8e007191e20cc6489918b38eee3674..ef234a1df4d5292c074495c94c5cbe8764e5c72c 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\data\custom\option;
 use wcf\data\AbstractDatabaseObjectAction;
 use wcf\data\IToggleAction;
+use wcf\data\TDatabaseObjectToggle;
 
 /**
  * Executes option-related actions.
@@ -17,6 +18,8 @@ use wcf\data\IToggleAction;
  * @method     CustomOptionEditor      getSingleObject()
  */
 abstract class CustomOptionAction extends AbstractDatabaseObjectAction implements IToggleAction {
+       use TDatabaseObjectToggle;
+       
        /**
         * @inheritDoc
         */
@@ -26,22 +29,4 @@ abstract class CustomOptionAction extends AbstractDatabaseObjectAction implement
         * @inheritDoc
         */
        protected $requireACP = ['create', 'delete', 'update'];
-       
-       /**
-        * @inheritDoc
-        */
-       public function validateToggle() {
-               $this->validateUpdate();
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function toggle() {
-               foreach ($this->getObjects() as $optionEditor) {
-                       $optionEditor->update([
-                               'isDisabled' => 1 - $optionEditor->isDisabled
-                       ]);
-               }
-       }
 }
index 3855f0eeef3549397ed97d93e55631de2791657d..a514e04ba57a7169af0cb9b87d70001199d23609 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\data\language;
 use wcf\data\AbstractDatabaseObjectAction;
 use wcf\data\IToggleAction;
+use wcf\data\TDatabaseObjectToggle;
 use wcf\system\exception\UserInputException;
 use wcf\system\WCF;
 
@@ -18,6 +19,8 @@ use wcf\system\WCF;
  * @method     LanguageEditor          getSingleObject()
  */
 class LanguageAction extends AbstractDatabaseObjectAction implements IToggleAction {
+       use TDatabaseObjectToggle;
+       
        /**
         * @inheritDoc
         */
@@ -81,14 +84,4 @@ class LanguageAction extends AbstractDatabaseObjectAction implements IToggleActi
                        }
                }
        }
-       
-       /**
-        * @inheritDoc
-        */
-       public function toggle() {
-               foreach ($this->getObjects() as $language) {
-                       $isDisabled = $language->isDisabled ? 0 : 1;
-                       $language->update(['isDisabled' => $isDisabled]);
-               }
-       }
 }
index fcfabafa5b51a67cb9fdcb96df0bfa7b459d1e73..d23ce807b61de7eecbd122d547d8c5c6c8168db2 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\data\package\update\server;
 use wcf\data\AbstractDatabaseObjectAction;
 use wcf\data\IToggleAction;
+use wcf\data\TDatabaseObjectToggle;
 
 /**
  * Executes package update server-related actions.
@@ -16,6 +17,8 @@ use wcf\data\IToggleAction;
  * @method     PackageUpdateServerEditor       getSingleObject()
  */
 class PackageUpdateServerAction extends AbstractDatabaseObjectAction implements IToggleAction {
+       use TDatabaseObjectToggle;
+       
        /**
         * @inheritDoc
         */
@@ -40,20 +43,4 @@ class PackageUpdateServerAction extends AbstractDatabaseObjectAction implements
         * @inheritDoc
         */
        protected $requireACP = ['create', 'delete', 'toggle', 'update'];
-       
-       /**
-        * @inheritDoc
-        */
-       public function validateToggle() {
-               parent::validateUpdate();
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function toggle() {
-               foreach ($this->getObjects() as $server) {
-                       $server->update(['isDisabled' => $server->isDisabled ? 0 : 1]);
-               }
-       }
 }
index b464bf75c965f3f04c1c5ac26e8ec7f4c482accb..9766eaf69661a12b5d796287324b2fd7e815c2d7 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\data\paid\subscription;
 use wcf\data\AbstractDatabaseObjectAction;
 use wcf\data\IToggleAction;
+use wcf\data\TDatabaseObjectToggle;
 
 /**
  * Executes paid subscription-related actions.
@@ -15,6 +16,8 @@ use wcf\data\IToggleAction;
  * @method     PaidSubscriptionEditor          getSingleObject()
  */
 class PaidSubscriptionAction extends AbstractDatabaseObjectAction implements IToggleAction {
+       use TDatabaseObjectToggle;
+       
        /**
         * @inheritDoc
         */
@@ -59,22 +62,4 @@ class PaidSubscriptionAction extends AbstractDatabaseObjectAction implements ITo
                        reset($this->objects)->setShowOrder($this->parameters['data']['showOrder']);
                }
        }
-       
-       /**
-        * @inheritDoc
-        */
-       public function toggle() {
-               foreach ($this->getObjects() as $object) {
-                       $object->update([
-                               'isDisabled' => $object->isDisabled ? 0 : 1
-                       ]);
-               }
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function validateToggle() {
-               parent::validateUpdate();
-       }
 }
index 5631a845e228324a7a5d6bcc10a03066227799bb..5c704447301ab77a5edf119fb145567bc93445b5 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\data\style;
+use wcf\data\TDatabaseObjectToggle;
 use wcf\data\user\cover\photo\UserCoverPhoto;
 use wcf\data\user\UserAction;
 use wcf\data\AbstractDatabaseObjectAction;
@@ -32,6 +33,8 @@ use wcf\util\FileUtil;
  * @method     StyleEditor     getSingleObject()
  */
 class StyleAction extends AbstractDatabaseObjectAction implements IToggleAction, IUploadAction {
+       use TDatabaseObjectToggle;
+       
        /**
         * @inheritDoc
         */
@@ -1013,16 +1016,6 @@ BROWSERCONFIG;
                }
        }
        
-       /**
-        * @inheritDoc
-        */
-       public function toggle() {
-               foreach ($this->getObjects() as $style) {
-                       $isDisabled = $style->isDisabled ? 0 : 1;
-                       $style->update(['isDisabled' => $isDisabled]);
-               }
-       }
-       
        /**
         * Validates parameters to change user style.
         */
index 518b6aebea1166bb78f29d37e2fd77d071bfe551..daaa1be1f2ff92609539a2700cf94ce19d76c4f3 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\data\user\group\assignment;
 use wcf\data\AbstractDatabaseObjectAction;
 use wcf\data\IToggleAction;
+use wcf\data\TDatabaseObjectToggle;
 use wcf\system\condition\ConditionHandler;
 
 /**
@@ -17,6 +18,8 @@ use wcf\system\condition\ConditionHandler;
  * @method     UserGroupAssignmentEditor       getSingleObject()
  */
 class UserGroupAssignmentAction extends AbstractDatabaseObjectAction implements IToggleAction {
+       use TDatabaseObjectToggle;
+       
        /**
         * @inheritDoc
         */
@@ -40,22 +43,4 @@ class UserGroupAssignmentAction extends AbstractDatabaseObjectAction implements
                
                return parent::delete();
        }
-       
-       /**
-        * @inheritDoc
-        */
-       public function toggle() {
-               foreach ($this->getObjects() as $assignment) {
-                       $assignment->update([
-                               'isDisabled' => $assignment->isDisabled ? 0 : 1
-                       ]);
-               }
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function validateToggle() {
-               parent::validateUpdate();
-       }
 }
index c74b4a350333b6e899cb70d578d129b5c07b77a8..860dcfde8c27b0c18887a43e2165d7a380d6b50e 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\data\user\option;
 use wcf\data\AbstractDatabaseObjectAction;
 use wcf\data\IToggleAction;
+use wcf\data\TDatabaseObjectToggle;
 use wcf\system\exception\PermissionDeniedException;
 
 /**
@@ -17,6 +18,8 @@ use wcf\system\exception\PermissionDeniedException;
  * @method     UserOptionEditor        getSingleObject()
  */
 class UserOptionAction extends AbstractDatabaseObjectAction implements IToggleAction {
+       use TDatabaseObjectToggle;
+       
        /**
         * @inheritDoc
         */
@@ -54,22 +57,4 @@ class UserOptionAction extends AbstractDatabaseObjectAction implements IToggleAc
                        }
                }
        }
-       
-       /**
-        * @inheritDoc
-        */
-       public function toggle() {
-               foreach ($this->getObjects() as $optionEditor) {
-                       $optionEditor->update([
-                               'isDisabled' => 1 - $optionEditor->isDisabled
-                       ]);
-               }
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function validateToggle() {
-               $this->validateUpdate();
-       }
 }