From: Marcel Werk Date: Thu, 26 May 2016 17:21:07 +0000 (+0200) Subject: Overhauled language import form X-Git-Tag: 3.0.0_Beta_1~1618 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=d00afef872eb56f6da0c0b4ad75114449da99bd5;p=GitHub%2FWoltLab%2FWCF.git Overhauled language import form --- diff --git a/CHANGELOG.md b/CHANGELOG.md index b7eb96edd1..76e45d787d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ * `\wcf\form\AbstractCaptchaForm`: added parameter to force captcha usage for registered users. * Added global disable switch for languages. * Overhauled page tracking in sessions / user online locations +* Overhauled language import form #### CMS diff --git a/wcfsetup/install/files/acp/templates/languageImport.tpl b/wcfsetup/install/files/acp/templates/languageImport.tpl index 89dc5e7b27..d1c3c8cee7 100644 --- a/wcfsetup/install/files/acp/templates/languageImport.tpl +++ b/wcfsetup/install/files/acp/templates/languageImport.tpl @@ -22,11 +22,11 @@
- -
+ +
- - {if $errorField == 'languageFile'} + + {if $errorField == 'languageUpload'} {if $errorType == 'empty'} {lang}wcf.global.form.error.empty{/lang} @@ -35,19 +35,27 @@ {/if} {/if} - {lang}wcf.acp.language.import.source.file.description{/lang}
- -
+ +
- - {if $errorField == 'languageUpload'} + + {if $errorField == 'sourceLanguageID'} - {lang}wcf.acp.language.import.error{/lang} {$errorType} + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {else} + {lang}wcf.acp.language.add.source.error.{@$errorType}{/lang} + {/if} {/if} + {lang}wcf.acp.language.add.source.description{/lang}
diff --git a/wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php b/wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php index c9d5a016e6..bcd7e9fd53 100644 --- a/wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php @@ -38,28 +38,28 @@ class LanguageImportForm extends AbstractForm { public $filename = ''; /** - * import field - * @var string + * language object + * @var Language */ - public $importField = 'languageFile'; + public $language; /** - * language object - * @var \wcf\data\language\Language + * list of available languages + * @var Language[] */ - public $language = null; + public $languages = []; /** - * import language file - * @var string + * source language object + * @var Language */ - public $languageFile = ''; + public $sourceLanguage; /** - * list of available languages - * @var Language[] + * source language id + * @var integer */ - public $languages = []; + public $sourceLanguageID = 0; /** * @inheritDoc @@ -67,15 +67,10 @@ class LanguageImportForm extends AbstractForm { public function readFormParameters() { parent::readFormParameters(); - // import - if (isset($_POST['languageFile']) && !empty($_POST['languageFile'])) { - $this->languageFile = $_POST['languageFile']; - $this->filename = $_POST['languageFile']; - } if (isset($_FILES['languageUpload']) && !empty($_FILES['languageUpload']['tmp_name'])) { - $this->importField = 'languageUpload'; $this->filename = $_FILES['languageUpload']['tmp_name']; } + if (isset($_POST['sourceLanguageID'])) $this->sourceLanguageID = intval($_POST['sourceLanguageID']); } /** @@ -86,7 +81,17 @@ class LanguageImportForm extends AbstractForm { // check file if (!file_exists($this->filename)) { - throw new UserInputException('languageFile'); + throw new UserInputException('languageUpload'); + } + + if (empty($this->sourceLanguageID)) { + throw new UserInputException('sourceLanguageID'); + } + + // get language + $this->sourceLanguage = LanguageFactory::getInstance()->getLanguage($this->sourceLanguageID); + if (!$this->sourceLanguage->languageID) { + throw new UserInputException('sourceLanguageID'); } // try to import @@ -96,10 +101,10 @@ class LanguageImportForm extends AbstractForm { $xml->load($this->filename); // import xml document - $this->language = LanguageEditor::importFromXML($xml, -1); + $this->language = LanguageEditor::importFromXML($xml, -1, $this->sourceLanguage); } catch (SystemException $e) { - throw new UserInputException($this->importField, $e->getMessage()); + throw new UserInputException('languageUpload', $e->getMessage()); } } @@ -117,6 +122,15 @@ class LanguageImportForm extends AbstractForm { WCF::getTPL()->assign('success', true); } + /** + * @inheritDoc + */ + public function readData() { + parent::readData(); + + $this->languages = LanguageFactory::getInstance()->getLanguages(); + } + /** * @inheritDoc */ @@ -125,7 +139,7 @@ class LanguageImportForm extends AbstractForm { WCF::getTPL()->assign([ 'languages' => $this->languages, - 'languageFile' => $this->languageFile + 'sourceLanguageID' => $this->sourceLanguageID ]); } diff --git a/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php b/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php index 41f81e28fb..c296a9f206 100644 --- a/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php +++ b/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php @@ -367,11 +367,12 @@ class LanguageEditor extends DatabaseObjectEditor implements IEditableCachedObje * Imports language items from an XML file into a new or a current language. * Updates the relevant language files automatically. * - * @param XML $xml + * @param XML $xml * @param integer $packageID + * @param Language $source * @return LanguageEditor */ - public static function importFromXML(XML $xml, $packageID) { + public static function importFromXML(XML $xml, $packageID, Language $source = null) { $languageCode = self::readLanguageCodeFromXML($xml); // try to find an existing language with the given language code @@ -386,6 +387,11 @@ class LanguageEditor extends DatabaseObjectEditor implements IEditableCachedObje 'languageCode' => $languageCode, 'languageName' => $languageName ]); + + if ($source) { + $sourceEditor = new LanguageEditor($source); + $sourceEditor->copy($language); + } } // import xml