From 03f2d606b761de43d18f8e0a6de61d1235825158 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Wed, 10 Apr 2019 19:19:27 +0200 Subject: [PATCH] Fix editing devtools project with broken path See #2772 --- .../acp/templates/devtoolsProjectAdd.tpl | 6 +- .../acp/form/DevtoolsProjectAddForm.class.php | 18 +++- .../form/DevtoolsProjectEditForm.class.php | 82 +++++++++++++++++++ wcfsetup/install/lang/de.xml | 1 + wcfsetup/install/lang/en.xml | 1 + 5 files changed, 103 insertions(+), 5 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/devtoolsProjectAdd.tpl b/wcfsetup/install/files/acp/templates/devtoolsProjectAdd.tpl index 5f64c1b6f0..aefed8dfba 100644 --- a/wcfsetup/install/files/acp/templates/devtoolsProjectAdd.tpl +++ b/wcfsetup/install/files/acp/templates/devtoolsProjectAdd.tpl @@ -17,7 +17,11 @@ {if $action === 'add'}

{lang}wcf.acp.devtools.project.add.info{/lang}

{elseif $action === 'edit'} -

{lang}wcf.acp.devtools.project.edit.warning{/lang}

+ {if $hasBrokenPath} +

{lang}wcf.acp.devtools.project.edit.error.brokenPath{/lang}

+ {else} +

{lang}wcf.acp.devtools.project.edit.warning{/lang}

+ {/if} {/if} {@$form->getHtml()} diff --git a/wcfsetup/install/files/lib/acp/form/DevtoolsProjectAddForm.class.php b/wcfsetup/install/files/lib/acp/form/DevtoolsProjectAddForm.class.php index 766c480c80..0fb83b47b3 100644 --- a/wcfsetup/install/files/lib/acp/form/DevtoolsProjectAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/DevtoolsProjectAddForm.class.php @@ -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(); + } } diff --git a/wcfsetup/install/files/lib/acp/form/DevtoolsProjectEditForm.class.php b/wcfsetup/install/files/lib/acp/form/DevtoolsProjectEditForm.class.php index 0306b4941b..5696ac6340 100644 --- a/wcfsetup/install/files/lib/acp/form/DevtoolsProjectEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/DevtoolsProjectEditForm.class.php @@ -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); + } + } } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 04432fdb2a..17199487fc 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -595,6 +595,7 @@ + package.xml im angegebenen Pfad. Die Paket-Dateien wurden entweder gelöscht oder verschoben.]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 4ec7a031d7..0dea3f0ad6 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -571,6 +571,7 @@ + package.xml in the given directory. The package files have either been deleted or moved.]]> -- 2.20.1