Prevent adding duplicate package update servers
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 19 Aug 2020 13:38:03 +0000 (15:38 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 19 Aug 2020 14:16:32 +0000 (16:16 +0200)
wcfsetup/install/files/acp/templates/packageUpdateServerAdd.tpl
wcfsetup/install/files/lib/acp/form/PackageUpdateServerAddForm.class.php
wcfsetup/install/files/lib/acp/form/PackageUpdateServerEditForm.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index e3fa4271451966d2a0ebe127cda10f6362af7cbd..860461c2b989ab190332b0f66567232d0b4dddc3 100644 (file)
@@ -30,6 +30,8 @@
                                        <small class="innerError">
                                                {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}
index b8ac6729f65f5ce236a8536180f5649f2307cc60..932d8ce09bd6b8f919826bef59dfa7f0dd3ae35e 100755 (executable)
@@ -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;
        }
        
        /**
index 7da86b669bff8c52a6d5e2fd250a266e05636c6a..b9f94889ac53f246c9cfb90244d9da44be258d87 100755 (executable)
@@ -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
         */
index 77501017c5063489f8191ef7b4267863a59d6a63..79a862faf3e3bfcd2071d6f06cf3aecbd31c5df5 100644 (file)
@@ -2783,6 +2783,7 @@ Kein Abschnitt darf leer sein und alle Abschnitten dürfen nur folgende Zeichen
                <item name="wcf.acp.updateServer.packages"><![CDATA[Pakete]]></item>
                <item name="wcf.acp.updateServer.serverURL"><![CDATA[Adresse]]></item>
                <item name="wcf.acp.updateServer.serverURL.error.invalid"><![CDATA[Die eingetragene Adresse ist ungültig.]]></item>
+               <item name="wcf.acp.updateServer.serverURL.error.duplicate"><![CDATA[Dieser Paketserver ist bereits hinterlegt. {if LANGUAGE_USE_INFORMAL_VARIANT}Du kannst{else}Sie können{/if} <a href="{link controller="PackageUpdateServerEdit" id=$errorType[duplicate]->packageUpdateServerID}{/link}"><strong>den bestehenden Paketserver bearbeiten</strong></a>.]]></item>
                <item name="wcf.acp.updateServer.status"><![CDATA[Status]]></item>
                <item name="wcf.acp.updateServer.lastUpdateTime"><![CDATA[Letzter Zugriff]]></item>
        </category>
index 7ec9d1dd766729b68d6d9ca8430bed69eca20554..ed5600a9ffc0a8e5ad229bb3d3565bbfa0eec312 100644 (file)
@@ -2710,6 +2710,7 @@ If you have <strong>already bought the licenses for the listed apps</strong>, th
                <item name="wcf.acp.updateServer.packages"><![CDATA[Packages]]></item>
                <item name="wcf.acp.updateServer.serverURL"><![CDATA[Address]]></item>
                <item name="wcf.acp.updateServer.serverURL.error.invalid"><![CDATA[The address is invalid.]]></item>
+               <item name="wcf.acp.updateServer.serverURL.error.duplicate"><![CDATA[The given server is already configured. You can <a href="{link controller="PackageUpdateServerEdit" id=$errorType[duplicate]->packageUpdateServerID}{/link}"><strong>edit the existing server</strong></a>.]]></item>
                <item name="wcf.acp.updateServer.status"><![CDATA[Status]]></item>
                <item name="wcf.acp.updateServer.lastUpdateTime"><![CDATA[Last Access]]></item>
        </category>