--- /dev/null
+<?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
+ ]);
+ }
+ }
+}
namespace wcf\data\captcha\question;
use wcf\data\AbstractDatabaseObjectAction;
use wcf\data\IToggleAction;
+use wcf\data\TDatabaseObjectToggle;
/**
* Executes captcha question-related actions.
* @method CaptchaQuestionEditor getSingleObject()
*/
class CaptchaQuestionAction extends AbstractDatabaseObjectAction implements IToggleAction {
+ use TDatabaseObjectToggle;
+
/**
* @inheritDoc
*/
* @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();
- }
}
<?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;
* @method CronjobEditor getSingleObject()
*/
class CronjobAction extends AbstractDatabaseObjectAction implements IToggleAction {
+ use TDatabaseObjectToggle;
+
/**
* @inheritDoc
*/
}
}
- /**
- * @inheritDoc
- */
- public function toggle() {
- foreach ($this->getObjects() as $cronjob) {
- $cronjob->update([
- 'isDisabled' => $cronjob->isDisabled ? 0 : 1
- ]);
- }
- }
-
/**
* Validates the 'execute' action.
*/
namespace wcf\data\custom\option;
use wcf\data\AbstractDatabaseObjectAction;
use wcf\data\IToggleAction;
+use wcf\data\TDatabaseObjectToggle;
/**
* Executes option-related actions.
* @method CustomOptionEditor getSingleObject()
*/
abstract class CustomOptionAction extends AbstractDatabaseObjectAction implements IToggleAction {
+ use TDatabaseObjectToggle;
+
/**
* @inheritDoc
*/
* @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
- ]);
- }
- }
}
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;
* @method LanguageEditor getSingleObject()
*/
class LanguageAction extends AbstractDatabaseObjectAction implements IToggleAction {
+ use TDatabaseObjectToggle;
+
/**
* @inheritDoc
*/
}
}
}
-
- /**
- * @inheritDoc
- */
- public function toggle() {
- foreach ($this->getObjects() as $language) {
- $isDisabled = $language->isDisabled ? 0 : 1;
- $language->update(['isDisabled' => $isDisabled]);
- }
- }
}
namespace wcf\data\package\update\server;
use wcf\data\AbstractDatabaseObjectAction;
use wcf\data\IToggleAction;
+use wcf\data\TDatabaseObjectToggle;
/**
* Executes package update server-related actions.
* @method PackageUpdateServerEditor getSingleObject()
*/
class PackageUpdateServerAction extends AbstractDatabaseObjectAction implements IToggleAction {
+ use TDatabaseObjectToggle;
+
/**
* @inheritDoc
*/
* @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]);
- }
- }
}
namespace wcf\data\paid\subscription;
use wcf\data\AbstractDatabaseObjectAction;
use wcf\data\IToggleAction;
+use wcf\data\TDatabaseObjectToggle;
/**
* Executes paid subscription-related actions.
* @method PaidSubscriptionEditor getSingleObject()
*/
class PaidSubscriptionAction extends AbstractDatabaseObjectAction implements IToggleAction {
+ use TDatabaseObjectToggle;
+
/**
* @inheritDoc
*/
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();
- }
}
<?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;
* @method StyleEditor getSingleObject()
*/
class StyleAction extends AbstractDatabaseObjectAction implements IToggleAction, IUploadAction {
+ use TDatabaseObjectToggle;
+
/**
* @inheritDoc
*/
}
}
- /**
- * @inheritDoc
- */
- public function toggle() {
- foreach ($this->getObjects() as $style) {
- $isDisabled = $style->isDisabled ? 0 : 1;
- $style->update(['isDisabled' => $isDisabled]);
- }
- }
-
/**
* Validates parameters to change user style.
*/
namespace wcf\data\user\group\assignment;
use wcf\data\AbstractDatabaseObjectAction;
use wcf\data\IToggleAction;
+use wcf\data\TDatabaseObjectToggle;
use wcf\system\condition\ConditionHandler;
/**
* @method UserGroupAssignmentEditor getSingleObject()
*/
class UserGroupAssignmentAction extends AbstractDatabaseObjectAction implements IToggleAction {
+ use TDatabaseObjectToggle;
+
/**
* @inheritDoc
*/
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();
- }
}
namespace wcf\data\user\option;
use wcf\data\AbstractDatabaseObjectAction;
use wcf\data\IToggleAction;
+use wcf\data\TDatabaseObjectToggle;
use wcf\system\exception\PermissionDeniedException;
/**
* @method UserOptionEditor getSingleObject()
*/
class UserOptionAction extends AbstractDatabaseObjectAction implements IToggleAction {
+ use TDatabaseObjectToggle;
+
/**
* @inheritDoc
*/
}
}
}
-
- /**
- * @inheritDoc
- */
- public function toggle() {
- foreach ($this->getObjects() as $optionEditor) {
- $optionEditor->update([
- 'isDisabled' => 1 - $optionEditor->isDisabled
- ]);
- }
- }
-
- /**
- * @inheritDoc
- */
- public function validateToggle() {
- $this->validateUpdate();
- }
}