Explicitly handle misformatted package.xml files when editing project
authorMatthias Schmidt <gravatronics@live.com>
Tue, 7 May 2019 16:16:21 +0000 (18:16 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 7 May 2019 16:16:21 +0000 (18:16 +0200)
Close #2924

wcfsetup/install/files/acp/templates/devtoolsProjectAdd.tpl
wcfsetup/install/files/lib/acp/form/DevtoolsProjectEditForm.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 8853e26d5f8d4e47636f4315f030a5b1d9a49508..70a6f902d12a877d7bb5dffa4baa99bcf1b66d54 100644 (file)
        {else}
                <p class="warning">{lang}wcf.acp.devtools.project.edit.warning{/lang}</p>
        {/if}
+       
+       {if !$missingElements|empty}
+               <p class="warning">{lang}wcf.acp.devtools.project.edit.warning.missingElements{/lang}</p>
+       {/if}
 {/if}
 
 {@$form->getHtml()}
index 5696ac6340a311d8d7b3c91774d4bf02165029fd..7b8c5b0ce2981f1bca4b7ec19f152430a7f430d4 100644 (file)
@@ -30,14 +30,20 @@ class DevtoolsProjectEditForm extends DevtoolsProjectAddForm {
        public $activeMenuItem = 'wcf.acp.menu.link.devtools.project.list';
        
        /**
-        * @var bool 
+        * @inheritDoc
+        */
+       public $formAction = 'edit';
+       
+       /**
+        * @var bool
         */
        public $hasBrokenPath = false;
        
        /**
-        * @inheritDoc
+        * list of missing XML elements that should be present
+        * @var string[]
         */
-       public $formAction = 'edit';
+       public $missingElements = [];
        
        /**
         * @inheritDoc
@@ -46,7 +52,8 @@ class DevtoolsProjectEditForm extends DevtoolsProjectAddForm {
                parent::assignVariables();
                
                WCF::getTPL()->assign([
-                       'hasBrokenPath' => $this->hasBrokenPath
+                       'hasBrokenPath' => $this->hasBrokenPath,
+                       'missingElements' => $this->missingElements
                ]);
        }
        
@@ -111,49 +118,64 @@ class DevtoolsProjectEditForm extends DevtoolsProjectAddForm {
                
                /** @var TextFormField $packageIdentifier */
                $packageIdentifier = $this->form->getNodeById('packageIdentifier');
-               $packageIdentifier->value($packageArchive->getPackageInfo('name'));
+               if ($packageArchive->getPackageInfo('name') !== null) {
+                       $packageIdentifier->value($packageArchive->getPackageInfo('name'));
+               }
+               else {
+                       $this->missingElements[] = 'name';
+               }
                
                /** @var TextFormField $packageName */
                $packageName = $this->form->getNodeById('packageName');
                $xmlPackageNames = $packageArchive->getPackageInfo('packageName');
-               if (count($xmlPackageNames) === 1) {
-                       $packageName->value(reset($xmlPackageNames));
-               }
-               else {
-                       $packageNames = [];
-                       foreach (LanguageFactory::getInstance()->getLanguages() as $language) {
-                               $packageNames[$language->languageID] = '';
-                               
-                               if (isset($xmlPackageNames[$language->languageCode])) {
-                                       $packageNames[$language->languageID] = $xmlPackageNames[$language->languageCode];
-                               }
-                               else if (isset($xmlPackageNames['default'])) {
-                                       $packageNames[$language->languageID] = $xmlPackageNames['default'];
+               if ($xmlPackageNames !== null) {
+                       if (count($xmlPackageNames) === 1) {
+                               $packageName->value(reset($xmlPackageNames));
+                       }
+                       else {
+                               $packageNames = [];
+                               foreach (LanguageFactory::getInstance()->getLanguages() as $language) {
+                                       $packageNames[$language->languageID] = '';
+                                       
+                                       if (isset($xmlPackageNames[$language->languageCode])) {
+                                               $packageNames[$language->languageID] = $xmlPackageNames[$language->languageCode];
+                                       }
+                                       else if (isset($xmlPackageNames['default'])) {
+                                               $packageNames[$language->languageID] = $xmlPackageNames['default'];
+                                       }
                                }
+                               
+                               $packageName->value($packageNames);
                        }
-                       
-                       $packageName->value($packageNames);
+               }
+               else {
+                       $this->missingElements[] = 'packageName';
                }
                
                /** @var TextFormField $packageDescription */
                $packageDescription = $this->form->getNodeById('packageDescription');
                $xmlPackageDescriptions = $packageArchive->getPackageInfo('packageDescription');
-               if (count($xmlPackageDescriptions) === 1) {
-                       $packageDescription->value(reset($xmlPackageDescriptions));
-               }
-               else {
-                       $packageDescriptions = [];
-                       foreach (LanguageFactory::getInstance()->getLanguages() as $language) {
-                               $packageDescriptions[$language->languageID] = '';
-                               
-                               if (isset($xmlPackageDescriptions[$language->languageCode])) {
-                                       $packageDescriptions[$language->languageID] = $xmlPackageDescriptions[$language->languageCode];
-                               } else if (isset($xmlPackageDescriptions['default'])) {
-                                       $packageDescriptions[$language->languageID] = $xmlPackageDescriptions['default'];
+               if ($xmlPackageDescriptions !== null) {
+                       if (count($xmlPackageDescriptions) === 1) {
+                               $packageDescription->value(reset($xmlPackageDescriptions));
+                       }
+                       else {
+                               $packageDescriptions = [];
+                               foreach (LanguageFactory::getInstance()->getLanguages() as $language) {
+                                       $packageDescriptions[$language->languageID] = '';
+                                       
+                                       if (isset($xmlPackageDescriptions[$language->languageCode])) {
+                                               $packageDescriptions[$language->languageID] = $xmlPackageDescriptions[$language->languageCode];
+                                       } else if (isset($xmlPackageDescriptions['default'])) {
+                                               $packageDescriptions[$language->languageID] = $xmlPackageDescriptions['default'];
+                                       }
                                }
+                               
+                               $packageDescription->value($packageDescriptions);
                        }
-                       
-                       $packageDescription->value($packageDescriptions);
+               }
+               else {
+                       $this->missingElements[] = 'packageDescription';
                }
                
                if (!empty($packageArchive->getPackageInfo('isApplication'))) {
@@ -170,11 +192,21 @@ class DevtoolsProjectEditForm extends DevtoolsProjectAddForm {
                
                /** @var TextFormField $version */
                $version = $this->form->getNodeById('version');
-               $version->value($packageArchive->getPackageInfo('version'));
+               if ($packageArchive->getPackageInfo('version') !== null) {
+                       $version->value($packageArchive->getPackageInfo('version'));
+               }
+               else {
+                       $this->missingElements[] = 'packageDescription';
+               }
                
                /** @var TextFormField $date */
                $date = $this->form->getNodeById('date');
-               $date->value(date('Y-m-d', $packageArchive->getPackageInfo('date')));
+               if ($packageArchive->getPackageInfo('date') !== null) {
+                       $date->value(date('Y-m-d', $packageArchive->getPackageInfo('date')));
+               }
+               else {
+                       $this->missingElements[] = 'date';
+               }
                
                if ($packageArchive->getPackageInfo('packageurl') !== null) {
                        /** @var TextFormField $packageUrl */
@@ -184,7 +216,12 @@ class DevtoolsProjectEditForm extends DevtoolsProjectAddForm {
                
                /** @var TextFormField $author */
                $author = $this->form->getNodeById('author');
-               $author->value($packageArchive->getAuthorInfo('author'));
+               if ($packageArchive->getAuthorInfo('author') !== null) {
+                       $author->value($packageArchive->getAuthorInfo('author'));
+               }
+               else {
+                       $this->missingElements[] = 'author';
+               }
                
                if ($packageArchive->getAuthorInfo('authorURL') !== null) {
                        /** @var TextFormField $authorUrl */
index 5f2526730d1161c0d90ccb6248629c107cec3645..37a592bdfe795cecb746af7192833190287a11fa 100644 (file)
                <item name="wcf.acp.devtools.project.pip.entry.delete.addDeleteInstruction"><![CDATA[Löschanweisung hinzufügen]]></item>
                <item name="wcf.acp.devtools.project.pip.entry.delete.addDeleteInstruction.description"><![CDATA[Der Eintrag wird nicht nur aus der Datenbank gelöscht und 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>
        </category>
        <category name="wcf.acp.email">
                <item name="wcf.acp.email.smtp.test"><![CDATA[SMTP-Verbindungstest]]></item>
index 67c1c4278f9a6c126b500056a8b25c30ab932c8a..cd9c8a03fbe000329b35eacb8a36f518e0f0e955 100644 (file)
                <item name="wcf.acp.devtools.project.pip.entry.delete.addDeleteInstruction"><![CDATA[Add delete instruction]]></item>
                <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>
        </category>
        <category name="wcf.acp.email">
                <item name="wcf.acp.email.smtp.test"><![CDATA[SMTP Connection Test]]></item>
@@ -861,7 +862,6 @@ This protocol file contains {$data[count]} new entries. The first three error me
                <item name="wcf.acp.group.type.owner"><![CDATA[Owner]]></item>
                <item name="wcf.acp.group.type.owner.description"><![CDATA[The owner group features a few irrevocable permissions and is protected from edits by other groups, only the owner group can edit itself. Members of this group can add other users to this group, but cannot remove themselves.]]></item>
                <item name="wcf.acp.group.ownerGroupPermission"><![CDATA[The owner group always has this permission, it cannot be revoked.]]></item>
-               
                <item name="wcf.acp.group.missingOwnerGroup"><![CDATA[No owner group has been configured yet, <a href="{link controller='UserGroupPromoteOwner'}{/link}">please set it up now</a>.]]></item>
                <item name="wcf.acp.group.promoteOwner"><![CDATA[Set Up the Owner Group]]></item>
                <item name="wcf.acp.group.promoteOwner.group"><![CDATA[Select the owner group]]></item>