From: Matthias Schmidt Date: Sat, 1 Oct 2016 12:38:06 +0000 (+0200) Subject: Fix handling of box conditions and additional data upon controller change X-Git-Tag: 3.0.0_Beta_2~41 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5235fa34fb38c523c5b03bf9305233587c33c937;p=GitHub%2FWoltLab%2FWCF.git Fix handling of box conditions and additional data upon controller change --- diff --git a/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php b/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php index 9df2a42793..e2c5692ace 100644 --- a/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php @@ -500,9 +500,15 @@ class BoxAddForm extends AbstractForm { 'identifier' => 'com.woltlab.wcf.genericBox'.$boxEditor->boxID ]); - if ($this->boxController && $this->boxController->getProcessor() instanceof IConditionBoxController) { - $this->boxController->getProcessor()->setBox($box, false); - $this->boxController->getProcessor()->saveConditions(); + if ($this->boxController) { + if ($this->boxController->getProcessor() instanceof IConditionBoxController) { + $this->boxController->getProcessor()->setBox($box, false); + } + else { + $this->boxController->getProcessor()->setBox($box); + } + + $this->boxController->getProcessor()->saveAdditionalData(); } // save acl diff --git a/wcfsetup/install/files/lib/acp/form/BoxEditForm.class.php b/wcfsetup/install/files/lib/acp/form/BoxEditForm.class.php index b526dffa63..ab1c5dfe9b 100644 --- a/wcfsetup/install/files/lib/acp/form/BoxEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/BoxEditForm.class.php @@ -6,6 +6,7 @@ use wcf\data\object\type\ObjectTypeCache; use wcf\form\AbstractForm; use wcf\system\acl\simple\SimpleAclHandler; use wcf\system\box\IConditionBoxController; +use wcf\system\condition\ConditionHandler; use wcf\system\exception\IllegalLinkException; use wcf\system\language\LanguageFactory; use wcf\system\WCF; @@ -117,9 +118,22 @@ class BoxEditForm extends BoxAddForm { $this->objectAction = new BoxAction([$this->box], 'update', ['data' => array_merge($this->additionalFields, $data), 'content' => $content, 'pageIDs' => $this->pageIDs]); $this->objectAction->executeAction(); - if ($this->boxController && $this->boxController->getProcessor() instanceof IConditionBoxController) { - $this->boxController->getProcessor()->setBox($this->box, false); - $this->boxController->getProcessor()->saveConditions(); + // delete old conditions + if ($this->box->getController() && $this->box->getController() instanceof IConditionBoxController && $this->box->getController()->getConditionDefinition() && (!$this->boxController || (!($this->boxController->getProcessor() instanceof IConditionBoxController)) || !$this->boxController->getProcessor()->getConditionDefinition())) { + ConditionHandler::getInstance()->deleteConditions($this->box->getController()->getConditionDefinition(), [$this->box->boxID]); + } + + if ($this->boxController) { + // pass updated box to box controller as in `BoxAddForm::save()` + $box = new Box($this->box->boxID); + if ($this->boxController->getProcessor() instanceof IConditionBoxController) { + $this->boxController->getProcessor()->setBox($box, false); + } + else { + $this->boxController->getProcessor()->setBox($box); + } + + $this->boxController->getProcessor()->saveAdditionalData(); } SimpleAclHandler::getInstance()->setValues('com.woltlab.wcf.box', $this->box->boxID, $this->aclValues); diff --git a/wcfsetup/install/files/lib/system/box/AbstractBoxController.class.php b/wcfsetup/install/files/lib/system/box/AbstractBoxController.class.php index 73742704eb..2a7dd9ef69 100644 --- a/wcfsetup/install/files/lib/system/box/AbstractBoxController.class.php +++ b/wcfsetup/install/files/lib/system/box/AbstractBoxController.class.php @@ -1,6 +1,9 @@ box = $box; } + /** + * @inheritDoc + */ + public function saveAdditionalData() { + // always write additional data to make sure that the additional data of the previous box controller + // are properly overwritten + (new BoxAction([$this->box], 'update', [ + 'data' => ['additionalData' => serialize($this->getAdditionalData())] + ]))->executeAction(); + } + + /** + * Returns the additional data of the box. + * + * @return array + */ + protected function getAdditionalData() { + return []; + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/box/AbstractDatabaseObjectListBoxController.class.php b/wcfsetup/install/files/lib/system/box/AbstractDatabaseObjectListBoxController.class.php index e768df7d71..7ceac1d1e7 100644 --- a/wcfsetup/install/files/lib/system/box/AbstractDatabaseObjectListBoxController.class.php +++ b/wcfsetup/install/files/lib/system/box/AbstractDatabaseObjectListBoxController.class.php @@ -1,7 +1,7 @@ objectList = $this->getObjectList(); - if ($this->box->limit) { + if ($this->limit) { $this->objectList->sqlLimit = $this->box->limit; } - if ($this->box->sortOrder && $this->box->sortField) { + if ($this->sortOrder && $this->sortField) { $alias = $this->objectList->getDatabaseTableAlias(); - $this->objectList->sqlOrderBy = $this->box->sortField . ' ' . $this->box->sortOrder . ", " . ($alias ? $alias . "." : "") . $this->objectList->getDatabaseTableIndexName() . " " . $this->box->sortOrder; + $this->objectList->sqlOrderBy = $this->sortField . ' ' . $this->sortOrder . ", " . ($alias ? $alias . "." : "") . $this->objectList->getDatabaseTableIndexName() . " " . $this->sortOrder; } if ($this->conditionDefinition) { @@ -252,19 +250,17 @@ abstract class AbstractDatabaseObjectListBoxController extends AbstractBoxContro /** * @inheritDoc */ - public function saveConditions() { - if (($this->sortField && $this->sortOrder) || $this->limit) { - (new BoxAction([$this->box], 'update', [ - 'data' => [ - 'additionalData' => serialize(array_merge($this->box->additionalData, $this->getAdditionalData())) - ] - ]))->executeAction(); - } + public function saveAdditionalData() { + parent::saveAdditionalData(); if ($this->conditionDefinition) { // do not use Box::getConditions() here to avoid setting box data by internally calling // Box::getController() - ConditionHandler::getInstance()->updateConditions($this->box->boxID, ConditionHandler::getInstance()->getConditions($this->conditionDefinition, $this->box->boxID), $this->conditionObjectTypes); + ConditionHandler::getInstance()->updateConditions( + $this->box->boxID, + ConditionHandler::getInstance()->getConditions($this->conditionDefinition, $this->box->boxID), + $this->conditionObjectTypes + ); } } @@ -279,9 +275,14 @@ abstract class AbstractDatabaseObjectListBoxController extends AbstractBoxContro parent::setBox($box); if ($setConditionData) { - $this->limit = $this->box->limit; - $this->sortOrder = $this->box->sortOrder; - $this->sortField = $this->box->sortField; + if ($this->defaultLimit !== null) { + $this->limit = $this->box->limit; + } + + if (!empty($this->validSortFields)) { + $this->sortOrder = $this->box->sortOrder; + $this->sortField = $this->box->sortField; + } if ($this->conditionDefinition) { $conditions = []; diff --git a/wcfsetup/install/files/lib/system/box/IBoxController.class.php b/wcfsetup/install/files/lib/system/box/IBoxController.class.php index d4db587735..525e4deac1 100644 --- a/wcfsetup/install/files/lib/system/box/IBoxController.class.php +++ b/wcfsetup/install/files/lib/system/box/IBoxController.class.php @@ -64,6 +64,11 @@ interface IBoxController { */ public function setBox(Box $box); + /** + * Saves additional box data for box set via `setBox()`. + */ + public function saveAdditionalData(); + /** * Returns a list of supported box positions. * diff --git a/wcfsetup/install/files/lib/system/box/IConditionBoxController.class.php b/wcfsetup/install/files/lib/system/box/IConditionBoxController.class.php index c9f02ad860..d36d6046f1 100644 --- a/wcfsetup/install/files/lib/system/box/IConditionBoxController.class.php +++ b/wcfsetup/install/files/lib/system/box/IConditionBoxController.class.php @@ -38,11 +38,6 @@ interface IConditionBoxController extends IBoxController { */ public function readConditions(); - /** - * Saves the conditions for the box. - */ - public function saveConditions(); - /** * Validates the read conditions for the box. */