From: Matthias Schmidt Date: Sat, 5 Jan 2019 09:03:30 +0000 (+0100) Subject: Fix language PIP GUI if no language files exist yet X-Git-Tag: 5.2.0_Alpha_1~378 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ed044fab24491ba25547b83c35ef3a3070a47c65;p=GitHub%2FWoltLab%2FWCF.git Fix language PIP GUI if no language files exist yet See #2545 --- diff --git a/wcfsetup/install/files/lib/system/devtools/pip/TMultiXmlGuiPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/devtools/pip/TMultiXmlGuiPackageInstallationPlugin.class.php index aef8888755..6ceb695a8f 100644 --- a/wcfsetup/install/files/lib/system/devtools/pip/TMultiXmlGuiPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/devtools/pip/TMultiXmlGuiPackageInstallationPlugin.class.php @@ -38,7 +38,7 @@ trait TMultiXmlGuiPackageInstallationPlugin { * @param IFormDocument $form */ public function addEntry(IFormDocument $form) { - foreach ($this->getProjectXmls() as $xml) { + foreach ($this->getProjectXmls(true) as $xml) { $newElement = $this->createAndInsertNewXmlElement($xml, $form); $this->saveObject($newElement); @@ -72,7 +72,7 @@ trait TMultiXmlGuiPackageInstallationPlugin { */ public function editEntry(IFormDocument $form, $identifier) { $newElement = null; - foreach ($this->getProjectXmls() as $xml) { + foreach ($this->getProjectXmls(true) as $xml) { $element = $this->getElementByIdentifier($xml, $identifier); $newElement = $this->replaceXmlElement($xml, $form, $identifier); @@ -134,9 +134,10 @@ trait TMultiXmlGuiPackageInstallationPlugin { /** * Returns the xml objects for this pip. * + * @param boolean $createXmlFiles if `true` and if a relevant XML file does not exist, it is created * @return XML[] */ - abstract protected function getProjectXmls(); + abstract protected function getProjectXmls($createXmlFiles = false); /** * @inheritDoc diff --git a/wcfsetup/install/files/lib/system/package/plugin/LanguagePackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/LanguagePackageInstallationPlugin.class.php index b53b730230..c5cfd0ccb7 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/LanguagePackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/LanguagePackageInstallationPlugin.class.php @@ -27,6 +27,7 @@ use wcf\system\language\LanguageFactory; use wcf\system\package\PackageArchive; use wcf\system\WCF; use wcf\util\DOMUtil; +use wcf\util\FileUtil; use wcf\util\StringUtil; use wcf\util\XML; @@ -473,23 +474,16 @@ class LanguagePackageInstallationPlugin extends AbstractXMLPackageInstallationPl ]); // add one field per language - foreach ($this->getProjectXmls() as $xml) { - $languageCode = $xml->getDocument()->documentElement->getAttribute('languagecode'); - $languageName = LanguageFactory::getInstance()->getLanguageByCode($languageCode)->languageName; - - if ($dataContainer->getNodeById($languageCode) !== null) { - throw new \LogicException("Duplicate language file with language code '{$languageCode}'."); - } - + foreach (LanguageFactory::getInstance()->getLanguages() as $language) { $description = null; - $descriptionLanguageItem = 'wcf.acp.pip.language.languageItemValue.' . $languageCode . '.description'; + $descriptionLanguageItem = 'wcf.acp.pip.language.languageItemValue.' . $language->languageCode . '.description'; if (WCF::getLanguage()->get($descriptionLanguageItem, true) !== '') { $description = $descriptionLanguageItem; } $dataContainer->appendChild( - MultilineTextFormField::create($languageCode) - ->label($languageName) + MultilineTextFormField::create($language->languageCode) + ->label($language->languageName) ->description($description) ); } @@ -642,27 +636,45 @@ XML; /** * Returns the xml objects for this pip. - * + * + * @param boolean $createXmlFiles if `true` and if a relevant XML file does not exist, it is created * @return XML[] */ - protected function getProjectXmls() { + protected function getProjectXmls($createXmlFiles = false) { $xmls = []; - foreach ($this->installation->getProject()->getLanguageFiles() as $languageFile) { - $xml = new XML(); - if (!file_exists($languageFile)) { - $xml->loadXML($languageFile, $this->getEmptyXml(substr(basename($languageFile), 0, -4))); - } - else { - $xml->load($languageFile); + if ($createXmlFiles) { + $directory = $this->installation->getProject()->path . ($this->installation->getProject()->isCore() ? 'wcfsetup/install/lang/' : 'language/'); + if (!is_dir($directory)) { + FileUtil::makePath($directory); } - // only consider installed languages - $languageCode = $xml->getDocument()->documentElement->getAttribute('languagecode'); - if (LanguageFactory::getInstance()->getLanguageByCode($languageCode) !== null) { + foreach (LanguageFactory::getInstance()->getLanguages() as $language) { + $languageFile = $directory . $language->languageCode . '.xml'; + + $xml = new XML(); + if (!file_exists($languageFile)) { + $xml->loadXML($languageFile, $this->getEmptyXml(substr(basename($languageFile), 0, -4))); + } + else { + $xml->load($languageFile); + } + $xmls[] = $xml; } } + else { + foreach ($this->installation->getProject()->getLanguageFiles() as $languageFile) { + $xml = new XML(); + $xml->load($languageFile); + + // only consider installed languages + $languageCode = $xml->getDocument()->documentElement->getAttribute('languagecode'); + if (LanguageFactory::getInstance()->getLanguageByCode($languageCode) !== null) { + $xmls[] = $xml; + } + } + } return $xmls; }