Add license support for devtools project form
authorMatthias Schmidt <gravatronics@live.com>
Fri, 27 Sep 2019 15:38:43 +0000 (17:38 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Fri, 27 Sep 2019 15:38:43 +0000 (17:38 +0200)
See #2772

wcfsetup/install/files/lib/acp/form/DevtoolsProjectAddForm.class.php
wcfsetup/install/files/lib/acp/form/DevtoolsProjectEditForm.class.php
wcfsetup/install/files/lib/system/devtools/package/DevtoolsPackageXmlWriter.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 82187b19f441e330aca71204d525f5585ce78d09..179acca63cbead5f11c70e0d351cb78bfba6667d 100644 (file)
@@ -287,7 +287,13 @@ class DevtoolsProjectAddForm extends AbstractFormBuilderForm {
                                UrlFormField::create('packageUrl')
                                        ->label('wcf.acp.devtools.project.packageUrl')
                                        ->description('wcf.acp.devtools.project.packageUrl.description')
+                                       ->maximumLength(255),
+                               
+                               TextFormField::create('license')
+                                       ->label('wcf.acp.devtools.project.license')
                                        ->maximumLength(255)
+                                       ->i18n()
+                                       ->languageItemPattern('__NONE__')
                        ])
                        ->addDependency(
                                ValueFormFieldDependency::create('mode')
index a2412a65f27080cecaaaa781546f21407d991d65..595ba57e75cc45e674c5dc7b33ed58d32e2e41a2 100644 (file)
@@ -215,6 +215,30 @@ class DevtoolsProjectEditForm extends DevtoolsProjectAddForm {
                        $packageUrl->value($packageArchive->getPackageInfo('packageurl'));
                }
                
+               /** @var TextFormField $license */
+               $license = $this->form->getNodeById('license');
+               $xmlLicenses = $packageArchive->getPackageInfo('license');
+               if ($xmlLicenses !== null) {
+                       if (count($xmlLicenses) === 1) {
+                               $license->value(reset($xmlLicenses));
+                       }
+                       else {
+                               $licenses = [];
+                               foreach (LanguageFactory::getInstance()->getLanguages() as $language) {
+                                       $licenses[$language->languageID] = '';
+                                       
+                                       if (isset($xmlLicenses[$language->languageCode])) {
+                                               $licenses[$language->languageID] = $xmlLicenses[$language->languageCode];
+                                       }
+                                       else if (isset($xmlLicenses['default'])) {
+                                               $licenses[$language->languageID] = $xmlLicenses['default'];
+                                       }
+                               }
+                               
+                               $license->value($licenses);
+                       }
+               }
+               
                /** @var TextFormField $author */
                $author = $this->form->getNodeById('author');
                if ($packageArchive->getAuthorInfo('author') !== null) {
index 202a1cec255ec0f5e3aae3df1c09102b02e87f79..c4449c5187243e5ac2d0d09fc707ea3ad0513bf3 100644 (file)
@@ -198,88 +198,66 @@ class DevtoolsPackageXmlWriter {
        }
        
        /**
-        * Writes the `packageinformation` element.
+        * Writes a child of the `packageinformation` element with i18n data.
+        * 
+        * @param       string          $information
+        * @param       null|string     $elementName    is set to lowercase version of `$information` if missing
         */
-       protected function writePackageInformation() {
-               $this->xmlWriter->startElement('packageinformation');
-               
-               $this->xmlWriter->writeComment(" {$this->packageXmlData['packageIdentifier']} ");
+       protected function writeI18nPackageInformation($information, $elementName = null) {
+               if ($elementName === null) {
+                       $elementName = strtolower($information);
+               }
                
                $english = LanguageFactory::getInstance()->getLanguageByCode('en');
                
-               if (isset($this->packageXmlData['packageName_i18n'])) {
+               if (isset($this->packageXmlData[$information . '_i18n'])) {
                        $defaultLanguageID = null;
-                       if ($english !== null && isset($this->packageXmlData['packageName_i18n'][$english->languageID])) {
+                       if ($english !== null && isset($this->packageXmlData[$information . '_i18n'][$english->languageID])) {
                                $defaultLanguageID = $english->languageID;
                        }
                        else {
-                               reset($this->packageXmlData['packageName_i18n']);
-                               $defaultLanguageID = key($this->packageXmlData['packageName_i18n']);
+                               reset($this->packageXmlData[$information . '_i18n']);
+                               $defaultLanguageID = key($this->packageXmlData[$information . '_i18n']);
                        }
                        
                        $this->xmlWriter->writeElement(
-                               'packagename',
-                               $this->packageXmlData['packageName_i18n'][$defaultLanguageID],
+                               $elementName,
+                               $this->packageXmlData[$information . '_i18n'][$defaultLanguageID],
                                [],
-                               $this->requiresCdata($this->packageXmlData['packageName_i18n'][$defaultLanguageID])
+                               $this->requiresCdata($this->packageXmlData[$information . '_i18n'][$defaultLanguageID])
                        );
                        
-                       foreach ($this->packageXmlData['packageName_i18n'] as $languageID => $packageName) {
+                       foreach ($this->packageXmlData[$information . '_i18n'] as $languageID => $informationValue) {
                                if ($languageID !== $defaultLanguageID) {
                                        $this->xmlWriter->writeElement(
-                                               'packagename',
-                                               $packageName,
+                                               $elementName,
+                                               $informationValue,
                                                ['language' => LanguageFactory::getInstance()->getLanguage($languageID)->languageCode],
-                                               $this->requiresCdata($packageName)
+                                               $this->requiresCdata($informationValue)
                                        );
                                }
                        }
                }
                else {
                        $this->xmlWriter->writeElement(
-                               'packagename',
-                               $this->packageXmlData['packageName'],
+                               $elementName,
+                               $this->packageXmlData[$information],
                                [],
-                               $this->requiresCdata($this->packageXmlData['packageName'])
+                               $this->requiresCdata($this->packageXmlData[$information])
                        );
                }
+       }
+       
+       /**
+        * Writes the `packageinformation` element.
+        */
+       protected function writePackageInformation() {
+               $this->xmlWriter->startElement('packageinformation');
                
-               if (isset($this->packageXmlData['packageDescription_i18n'])) {
-                       $defaultLanguageID = null;
-                       if (isset($this->packageXmlData['packageDescription_i18n'][$english->languageID])) {
-                               $defaultLanguageID = $english->languageID;
-                       }
-                       else {
-                               reset($this->packageXmlData['packageDescription_i18n']);
-                               $defaultLanguageID = key($this->packageXmlData['packageDescription_i18n']);
-                       }
-                       
-                       $this->xmlWriter->writeElement(
-                               'packagedescription',
-                               $this->packageXmlData['packageDescription_i18n'][$defaultLanguageID],
-                               [],
-                               $this->requiresCdata($this->packageXmlData['packageDescription_i18n'][$defaultLanguageID])
-                       );
-                       
-                       foreach ($this->packageXmlData['packageDescription_i18n'] as $languageID => $packageDescription) {
-                               if ($languageID !== $defaultLanguageID) {
-                                       $this->xmlWriter->writeElement(
-                                               'packagedescription',
-                                               $packageDescription,
-                                               ['language' => LanguageFactory::getInstance()->getLanguage($languageID)->languageCode],
-                                               $this->requiresCdata($packageDescription)
-                                       );
-                               }
-                       }
-               }
-               else {
-                       $this->xmlWriter->writeElement(
-                               'packagedescription',
-                               $this->packageXmlData['packageDescription'],
-                               [],
-                               $this->requiresCdata($this->packageXmlData['packageDescription'])
-                       );
-               }
+               $this->xmlWriter->writeComment(" {$this->packageXmlData['packageIdentifier']} ");
+               
+               $this->writeI18nPackageInformation('packageName');
+               $this->writeI18nPackageInformation('packageDescription');
                
                if (!empty($this->packageXmlData['isApplication'])) {
                        $this->xmlWriter->writeElement(
@@ -317,6 +295,7 @@ class DevtoolsPackageXmlWriter {
                                $this->requiresCdata($this->packageXmlData['packageUrl'])
                        );
                }
+               $this->writeI18nPackageInformation('license');
                
                $this->xmlWriter->endElement();
        }
index 16ce850bd4a2b74362c65d81ca0e40c9dad0262d..57eb66e78dc06fea6ed0259879433fa377538e03 100644 (file)
                <item name="wcf.acp.devtools.project.pip.entry.delete.addDeleteInstruction.description"><![CDATA[Der Eintrag wird nicht nur aus der Datenbank gelöscht und die Installationsanweisung entfernt, sondern es wird auch explizit eine Löschanweisung hinzugefügt.]]></item>
                <item name="wcf.acp.devtools.project.edit.error.brokenPath"><![CDATA[Es existiert keine <kbd>package.xml</kbd> im angegebenen Pfad. Die Paket-Dateien wurden entweder gelöscht oder verschoben.]]></item>
                <item name="wcf.acp.devtools.project.edit.warning.missingElements"><![CDATA[Die folgenden Informationen fehlen in der <kbd>package.xml</kbd>-Datei: {implode from=$missingElements item=missingElement}<kbd>{$missingElement}</kbd>{/implode}.]]></item>
+               <item name="wcf.acp.devtools.project.license"><![CDATA[Lizenz]]></item>
        </category>
        <category name="wcf.acp.email">
                <item name="wcf.acp.email.smtp.test"><![CDATA[SMTP-Verbindungstest]]></item>
index 90d8903015f821f621adf2da040c9d2a93bf8ac9..e67282bdd2e88771588037bda591550cf299f9b0 100644 (file)
                <item name="wcf.acp.devtools.project.pip.entry.delete.addDeleteInstruction.description"><![CDATA[The entry will not only be deleted from database and its installation instruction removed, but a delete instruction will also be explicitly added.]]></item>
                <item name="wcf.acp.devtools.project.edit.error.brokenPath"><![CDATA[There is no <kbd>package.xml</kbd> in the given directory. The package files have either been deleted or moved.]]></item>
                <item name="wcf.acp.devtools.project.edit.warning.missingElements"><![CDATA[The following information is missing from the <kbd>package.xml</kbd> file: {implode from=$missingElements item=missingElement}<kbd>{$missingElement}</kbd>{/implode}.]]></item>
+               <item name="wcf.acp.devtools.project.license"><![CDATA[License]]></item>
        </category>
        <category name="wcf.acp.email">
                <item name="wcf.acp.email.smtp.test"><![CDATA[SMTP Connection Test]]></item>