From: Tim Düsterhus Date: Wed, 19 Aug 2020 13:38:03 +0000 (+0200) Subject: Prevent adding duplicate package update servers X-Git-Tag: 5.3.0_Alpha_1~22^2~12 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=7488027f4e9fb9eff312a923e7a35423c60117f9;p=GitHub%2FWoltLab%2FWCF.git Prevent adding duplicate package update servers --- diff --git a/wcfsetup/install/files/acp/templates/packageUpdateServerAdd.tpl b/wcfsetup/install/files/acp/templates/packageUpdateServerAdd.tpl index e3fa427145..860461c2b9 100644 --- a/wcfsetup/install/files/acp/templates/packageUpdateServerAdd.tpl +++ b/wcfsetup/install/files/acp/templates/packageUpdateServerAdd.tpl @@ -30,6 +30,8 @@ {if $errorType == 'empty'} {lang}wcf.global.form.error.empty{/lang} + {elseif $errorType[duplicate]|isset} + {lang}wcf.acp.updateServer.serverURL.error.duplicate{/lang} {else} {lang}wcf.acp.updateServer.serverURL.error.{@$errorType}{/lang} {/if} diff --git a/wcfsetup/install/files/lib/acp/form/PackageUpdateServerAddForm.class.php b/wcfsetup/install/files/lib/acp/form/PackageUpdateServerAddForm.class.php index b8ac6729f6..932d8ce09b 100755 --- a/wcfsetup/install/files/lib/acp/form/PackageUpdateServerAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PackageUpdateServerAddForm.class.php @@ -2,6 +2,7 @@ namespace wcf\acp\form; use wcf\data\package\update\server\PackageUpdateServer; use wcf\data\package\update\server\PackageUpdateServerAction; +use wcf\data\package\update\server\PackageUpdateServerList; use wcf\form\AbstractForm; use wcf\system\exception\UserInputException; use wcf\system\request\LinkHandler; @@ -63,6 +64,13 @@ class PackageUpdateServerAddForm extends AbstractForm { public function validate() { parent::validate(); + $this->validateServerURL(); + } + + /** + * Validates the server URL. + */ + protected function validateServerURL() { if (empty($this->serverURL)) { throw new UserInputException('serverURL'); } @@ -70,6 +78,27 @@ class PackageUpdateServerAddForm extends AbstractForm { if (!PackageUpdateServer::isValidServerURL($this->serverURL)) { throw new UserInputException('serverURL', 'invalid'); } + + if (($duplicate = $this->findDuplicateServer())) { + throw new UserInputException('serverURL', [ + 'duplicate' => $duplicate, + ]); + } + } + + /** + * Returns the first package update server with a matching serverURL. + */ + protected function findDuplicateServer() { + $packageServerList = new PackageUpdateServerList(); + $packageServerList->readObjects(); + foreach ($packageServerList as $packageServer) { + if ($packageServer->serverURL == $this->serverURL) { + return $packageServer; + } + } + + return null; } /** diff --git a/wcfsetup/install/files/lib/acp/form/PackageUpdateServerEditForm.class.php b/wcfsetup/install/files/lib/acp/form/PackageUpdateServerEditForm.class.php index 7da86b669b..b9f94889ac 100755 --- a/wcfsetup/install/files/lib/acp/form/PackageUpdateServerEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PackageUpdateServerEditForm.class.php @@ -45,6 +45,13 @@ class PackageUpdateServerEditForm extends PackageUpdateServerAddForm { } } + /** + * Does nothing. + */ + public function validateServerURL() { + // The server URL cannot be modified, thus we do not need to validate it. + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 77501017c5..79a862faf3 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -2783,6 +2783,7 @@ Kein Abschnitt darf leer sein und alle Abschnitten dürfen nur folgende Zeichen + packageUpdateServerID}{/link}">den bestehenden Paketserver bearbeiten.]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 7ec9d1dd76..ed5600a9ff 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -2710,6 +2710,7 @@ If you have already bought the licenses for the listed apps, th + packageUpdateServerID}{/link}">edit the existing server.]]>