From 8aa772a64f8908bd3c3fbf82a3fc90e4e752952b Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 1 Oct 2016 14:08:09 +0200 Subject: [PATCH] Improve order of box field validation Validate in order as fields appear in form and do not implicitly reset the selected controller if name is invalid. --- .../files/lib/acp/form/BoxAddForm.class.php | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php b/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php index fdd3280ac9..9df2a42793 100644 --- a/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php @@ -281,6 +281,10 @@ class BoxAddForm extends AbstractForm { $this->readBoxImages(); } + + if ($this->boxType === 'system') { + $this->boxController = ObjectTypeCache::getInstance()->getObjectType($this->boxControllerID); + } } /** @@ -312,7 +316,6 @@ class BoxAddForm extends AbstractForm { // validate controller if ($this->boxType === 'system') { - $this->boxController = ObjectTypeCache::getInstance()->getObjectType($this->boxControllerID); if ($this->boxController === null || $this->boxController->getDefinition()->definitionName != 'com.woltlab.wcf.boxController') { throw new UserInputException('boxController'); } @@ -365,16 +368,8 @@ class BoxAddForm extends AbstractForm { $this->externalURL = ''; } - // validate page ids - if (!empty($this->pageIDs)) { - $conditionBuilder = new PreparedStatementConditionBuilder(); - $conditionBuilder->add('pageID IN (?)', [$this->pageIDs]); - $sql = "SELECT pageID - FROM wcf".WCF_N."_page - " . $conditionBuilder; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute($conditionBuilder->getParameters()); - $this->pageIDs = $statement->fetchAll(\PDO::FETCH_COLUMN); + if ($this->boxController && $this->boxController->getProcessor() instanceof IConditionBoxController) { + $this->boxController->getProcessor()->validateConditions(); } // validate images @@ -398,10 +393,6 @@ class BoxAddForm extends AbstractForm { } } - if ($this->boxController && $this->boxController->getProcessor() instanceof IConditionBoxController) { - $this->boxController->getProcessor()->validateConditions(); - } - if ($this->boxType == 'text') { if ($this->isMultilingual) { foreach (LanguageFactory::getInstance()->getLanguages() as $language) { @@ -414,6 +405,18 @@ class BoxAddForm extends AbstractForm { $this->htmlInputProcessors[0]->process((!empty($this->content[0]) ? $this->content[0] : ''), 'com.woltlab.wcf.box.content'); } } + + // validate page ids + if (!empty($this->pageIDs)) { + $conditionBuilder = new PreparedStatementConditionBuilder(); + $conditionBuilder->add('pageID IN (?)', [$this->pageIDs]); + $sql = "SELECT pageID + FROM wcf".WCF_N."_page + " . $conditionBuilder; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditionBuilder->getParameters()); + $this->pageIDs = $statement->fetchAll(\PDO::FETCH_COLUMN); + } } /** -- 2.20.1