Fix editing devtools project with broken path
authorMatthias Schmidt <gravatronics@live.com>
Wed, 10 Apr 2019 17:19:27 +0000 (19:19 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Wed, 10 Apr 2019 17:19:27 +0000 (19:19 +0200)
See #2772

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

index 5f64c1b6f00e8609abfe8e82a6f149d1ab4111e9..aefed8dfbaff25502bba3471d81eaa076f93c9a5 100644 (file)
 {if $action === 'add'}
        <p class="info">{lang}wcf.acp.devtools.project.add.info{/lang}</p>
 {elseif $action === 'edit'}
-       <p class="warning">{lang}wcf.acp.devtools.project.edit.warning{/lang}</p>
+       {if $hasBrokenPath}
+               <p class="warning">{lang}wcf.acp.devtools.project.edit.error.brokenPath{/lang}</p>
+       {else}
+               <p class="error">{lang}wcf.acp.devtools.project.edit.warning{/lang}</p>
+       {/if}
 {/if}
 
 {@$form->getHtml()}
index 766c480c80e2dd92ef3ce9dfca4f47fa42d1857e..0fb83b47b37e3100827284999826dd7f790c5bd9 100644 (file)
@@ -947,14 +947,24 @@ class DevtoolsProjectAddForm extends AbstractFormBuilderForm {
                }
                
                if ($data['data']['mode'] !== 'import') {
-                       $xmlData = array_merge($data, $data['data']);
-                       unset($xmlData['data'], $xmlData['mode']);
-                       $packageXmlWriter = new DevtoolsPackageXmlWriter($project, $xmlData);
-                       $packageXmlWriter->write();
+                       $this->writePackageXml($project, $data);
                }
                
                $this->saved();
                
                WCF::getTPL()->assign('success', true);
        }
+       
+       /**
+        * Writes the updated `package.xml` file for the given project using the given data.
+        *
+        * @param       DevtoolsProject         $project
+        * @param       array                   $data
+        */
+       protected function writePackageXml(DevtoolsProject $project, array $data) {
+               $xmlData = array_merge($data, $data['data']);
+               unset($xmlData['data'], $xmlData['mode']);
+               $packageXmlWriter = new DevtoolsPackageXmlWriter($project, $xmlData);
+               $packageXmlWriter->write();
+       }
 }
index 0306b4941b6154d7e27ce643ab59271a8538d77f..5696ac6340a311d8d7b3c91774d4bf02165029fd 100644 (file)
@@ -2,6 +2,8 @@
 namespace wcf\acp\form;
 use wcf\data\devtools\project\DevtoolsProject;
 use wcf\system\exception\IllegalLinkException;
+use wcf\system\form\builder\container\TabMenuFormContainer;
+use wcf\system\form\builder\container\TabTabMenuFormContainer;
 use wcf\system\form\builder\field\BooleanFormField;
 use wcf\system\form\builder\field\devtools\project\DevtoolsProjectExcludedPackagesFormField;
 use wcf\system\form\builder\field\devtools\project\DevtoolsProjectInstructionsFormField;
@@ -10,6 +12,7 @@ use wcf\system\form\builder\field\devtools\project\DevtoolsProjectRequiredPackag
 use wcf\system\form\builder\field\MultipleSelectionFormField;
 use wcf\system\form\builder\field\TextFormField;
 use wcf\system\language\LanguageFactory;
+use wcf\system\WCF;
 
 /**
  * Shows the devtools project edit form.
@@ -26,11 +29,40 @@ class DevtoolsProjectEditForm extends DevtoolsProjectAddForm {
         */
        public $activeMenuItem = 'wcf.acp.menu.link.devtools.project.list';
        
+       /**
+        * @var bool 
+        */
+       public $hasBrokenPath = false;
+       
        /**
         * @inheritDoc
         */
        public $formAction = 'edit';
        
+       /**
+        * @inheritDoc
+        */
+       public function assignVariables() {
+               parent::assignVariables();
+               
+               WCF::getTPL()->assign([
+                       'hasBrokenPath' => $this->hasBrokenPath
+               ]);
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function buildForm() {
+               parent::buildForm();
+               
+               // only show `name` and `path` field which are stored in database if path to
+               // `package.xml` file is broken
+               if ($this->hasBrokenPath) {
+                       $this->tooglePackageXmlFieldAvailabilty(false);
+               }
+       }
+       
        /**
         * @inheritDoc
         */
@@ -42,6 +74,24 @@ class DevtoolsProjectEditForm extends DevtoolsProjectAddForm {
                        if (!$this->formObject->projectID) {
                                throw new IllegalLinkException();
                        }
+                       
+                       if (!file_exists($this->formObject->getPackageXmlPath())) {
+                               $this->hasBrokenPath = true;
+                       }
+               }
+       }
+       
+       /**
+        * @inheritDoc
+        * @since       5.2
+        */
+       public function saved() {
+               parent::saved();
+               
+               if ($this->hasBrokenPath) {
+                       $this->tooglePackageXmlFieldAvailabilty(true);
+                       
+                       $this->hasBrokenPath = false;
                }
        }
        
@@ -52,6 +102,10 @@ class DevtoolsProjectEditForm extends DevtoolsProjectAddForm {
        protected function setFormObjectData() {
                parent::setFormObjectData();
                
+               if ($this->hasBrokenPath) {
+                       return;
+               }
+               
                // set additional data based on `package.xml` file
                $packageArchive = $this->formObject->getPackageArchive();
                
@@ -226,4 +280,32 @@ class DevtoolsProjectEditForm extends DevtoolsProjectAddForm {
                $instructionsField = $this->form->getNodeById('instructions');
                $instructionsField->value($instructions);
        }
+       
+       protected function tooglePackageXmlFieldAvailabilty($available) {
+               /** @var TabMenuFormContainer $tabMenu */
+               $tabMenu = $this->form->getNodeById('project');
+               
+               /** @var TabTabMenuFormContainer $tab */
+               foreach ($tabMenu->children() as $tab) {
+                       if ($tab->getId() !== 'dataTab') {
+                               $tab->available($available);
+                       }
+                       else {
+                               foreach ($tab->children() as $section) {
+                                       if ($section->getId() !== 'data') {
+                                               $section->available($available);
+                                       }
+                               }
+                       }
+               }
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       protected function writePackageXml(DevtoolsProject $project, array $data) {
+               if (!$this->hasBrokenPath) {
+                       parent::writePackageXml($project, $data);
+               }
+       }
 }
index 04432fdb2a9105fced0a6227b735523d813ac217..17199487fcd20f2be2a6960598be7761df633bcc 100644 (file)
                <item name="wcf.acp.devtools.project.pip.entry.delete.confirmMessage"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Willst du{else}Wollen Sie{/if} den Eintrag wirklich löschen?]]></item>
                <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>
        </category>
        <category name="wcf.acp.email">
                <item name="wcf.acp.email.smtp.test"><![CDATA[SMTP-Verbindungstest]]></item>
index 4ec7a031d7d3a700f7049bdd71907e1ef28e4527..0dea3f0ad6c458e0e43ada6b0d7b1f8ae8b42b7b 100644 (file)
                <item name="wcf.acp.devtools.project.pip.entry.delete.confirmMessage"><![CDATA[Do you really want to delete the entry?]]></item>
                <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>
        </category>
        <category name="wcf.acp.email">
                <item name="wcf.acp.email.smtp.test"><![CDATA[SMTP Connection Test]]></item>