From: Matthias Schmidt Date: Sun, 3 Jan 2016 09:11:38 +0000 (+0100) Subject: Resolve TODO in MediaAction X-Git-Tag: 3.0.0_Beta_1~2030^2~179 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=201b01c68d8404d5c0e1d5c6929ece2081f0a9c4;p=GitHub%2FWoltLab%2FWCF.git Resolve TODO in MediaAction --- 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'); + } } /**