From 201b01c68d8404d5c0e1d5c6929ece2081f0a9c4 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 3 Jan 2016 10:11:38 +0100 Subject: [PATCH] Resolve TODO in MediaAction --- .../lib/acp/form/MediaEditForm.class.php | 6 +++++- .../lib/data/media/MediaAction.class.php | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/wcfsetup/install/files/lib/acp/form/MediaEditForm.class.php b/wcfsetup/install/files/lib/acp/form/MediaEditForm.class.php index 2e425700c5..aa39604022 100644 --- a/wcfsetup/install/files/lib/acp/form/MediaEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/MediaEditForm.class.php @@ -165,12 +165,16 @@ class MediaEditForm extends AbstractForm { public function validate() { parent::validate(); + if (!$this->isMultilingual && !$this->languageID) { + throw new UserInputException('languageID'); + } + if ($this->languageID && !LanguageFactory::getInstance()->getLanguage($this->languageID)) { throw new UserInputException('languageID'); } foreach (['title', 'caption', 'altText'] as $i18nData) { - if (!I18nHandler::getInstance()->validateValue($i18nData, $this->isMultilingual? true : false, false)) { + if (!I18nHandler::getInstance()->validateValue($i18nData, $this->isMultilingual? true : false, true)) { if ($this->isMultilingual) { // in contrast to I18nHandler::validateValues(), we allow all fields to be empty if (empty(ArrayUtil::trim(I18nHandler::getInstance()->getValues($i18nData)))) { diff --git a/wcfsetup/install/files/lib/data/media/MediaAction.class.php b/wcfsetup/install/files/lib/data/media/MediaAction.class.php index 9957afbd10..6f224f1335 100644 --- a/wcfsetup/install/files/lib/data/media/MediaAction.class.php +++ b/wcfsetup/install/files/lib/data/media/MediaAction.class.php @@ -264,7 +264,24 @@ class MediaAction extends AbstractDatabaseObjectAction implements ISearchAction, } } - // TODO: check data + $this->readInteger('languageID', true, 'data'); + $this->readBoolean('isMultilingual', true, 'data'); + + // languageID: convert zero to null + if (!$this->parameters['data']['languageID']) $this->parameters['data']['languageID'] = null; + + // isMultilingual: convert boolean to integer + $this->parameters['data']['isMultilingual'] = intval($this->parameters['data']['isMultilingual']); + + // if data is not multilingual, a language id has to be given + if (!$this->parameters['data']['isMultilingual'] && !$this->parameters['data']['languageID']) { + throw new UserInputException('languageID'); + } + + // check language id + if ($this->parameters['data']['languageID'] && !LanguageFactory::getInstance()->getLanguage($this->parameters['data']['languageID'])) { + throw new UserInputException('languageID'); + } } /** -- 2.20.1