Resolve TODO in MediaAction
authorMatthias Schmidt <gravatronics@live.com>
Sun, 3 Jan 2016 09:11:38 +0000 (10:11 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 3 Jan 2016 09:11:38 +0000 (10:11 +0100)
wcfsetup/install/files/lib/acp/form/MediaEditForm.class.php
wcfsetup/install/files/lib/data/media/MediaAction.class.php

index 2e425700c553ffc870fc8120b3e20c344568f2f7..aa39604022f616446efd643359fdda004d2b1bf0 100644 (file)
@@ -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)))) {
index 9957afbd10eed72621d88c1b4b4e243c6d08734f..6f224f13355b66b0274b3c5632890fb7e2ed9aaf 100644 (file)
@@ -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');
+               }
        }
        
        /**