Add missing check if project path is unique
authorMatthias Schmidt <gravatronics@live.com>
Sun, 23 Jul 2017 08:20:33 +0000 (10:20 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 23 Jul 2017 08:20:33 +0000 (10:20 +0200)
See #2331

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 ccf77c0e05f27cbf5783afeacd392c94115895ff..ae3f8f1f77dd1624bd2295c7022d64fc6851e166 100644 (file)
@@ -66,13 +66,13 @@ class DevtoolsProjectAddForm extends AbstractForm {
                        throw new UserInputException('name');
                }
                else {
-                       $sql = "SELECT  COUNT(*) AS count
+                       $sql = "SELECT  COUNT(*)
                                FROM    wcf".WCF_N."_devtools_project
                                WHERE   name = ?";
                        $statement = WCF::getDB()->prepareStatement($sql);
                        $statement->execute([$this->name]);
-                       $count = $statement->fetchColumn();
-                       if ($count > 0) {
+                       
+                       if ($statement->fetchColumn()) {
                                throw new UserInputException('name', 'notUnique');
                        }
                }
@@ -88,10 +88,27 @@ class DevtoolsProjectAddForm extends AbstractForm {
                                throw new UserInputException('path', $errorType);
                        }
                        
+                       $this->validateUniquePath();
+                       
                        $this->path = $path;
                }
        }
        
+       /**
+        * Checks that the project path is not used by another project.
+        */
+       protected function validateUniquePath() {
+               $sql = "SELECT  COUNT(*)
+                       FROM    wcf".WCF_N."_devtools_project
+                       WHERE   path = ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute([$this->path]);
+               
+               if ($statement->fetchColumn()) {
+                       throw new UserInputException('path', 'notUnique');
+               }
+       }
+       
        /**
         * @inheritDoc
         */
index 3c60a3a3e6bcfce206c68a65973e391a332548ac..187015f2e6031225dcad1039d3af12204d012473 100644 (file)
@@ -4,6 +4,7 @@ use wcf\data\devtools\project\DevtoolsProject;
 use wcf\data\devtools\project\DevtoolsProjectAction;
 use wcf\form\AbstractForm;
 use wcf\system\exception\IllegalLinkException;
+use wcf\system\exception\UserInputException;
 use wcf\system\WCF;
 
 /**
@@ -46,6 +47,23 @@ class DevtoolsProjectEditForm extends DevtoolsProjectAddForm {
                }
        }
        
+       /** @noinspection PhpMissingParentCallCommonInspection */
+       /**
+        * @inheritDoc
+        */
+       protected function validateUniquePath() {
+               $sql = "SELECT  COUNT(*)
+                       FROM    wcf".WCF_N."_devtools_project
+                       WHERE   path = ?
+                               AND projectID <> ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute([$this->path, $this->objectID]);
+               
+               if ($statement->fetchColumn()) {
+                       throw new UserInputException('path', 'notUnique');
+               }
+       }
+       
        /**
         * @inheritDoc
         */
@@ -58,6 +76,7 @@ class DevtoolsProjectEditForm extends DevtoolsProjectAddForm {
                }
        }
        
+       /** @noinspection PhpMissingParentCallCommonInspection */
        /**
         * @inheritDoc
         */
index 52c15a02ca8a400dbeb808953b0e5199c40d66c0..8090c77695a7ecafe2e07e7781b5a4e09f0089c7 100644 (file)
                <item name="wcf.acp.devtools.project.path.error.missingExclude"><![CDATA[In der <kbd>package.xml</kbd> fehlt die <kbd>&gt;excludedpackage&lt;</kbd>-Anweisung für <kbd>com.woltlab.wcf</kbd>.]]></item>
                <item name="wcf.acp.devtools.project.path.error.notInstalled"><![CDATA[Das Paket muss bereits installiert sein.]]></item>
                <item name="wcf.acp.devtools.project.path.error.notFound"><![CDATA[Der Pfad ist ungültig.]]></item>
+               <item name="wcf.acp.devtools.project.path.error.notUnique"><![CDATA[Der Pfad wird bereits von einem anderen Projekt verwendet.]]></item>
                <item name="wcf.acp.devtools.project.path.error.versionMismatch"><![CDATA[Die Version in der <kbd>package.xml</kbd> passt nicht zur installierten Version, möglicherweise wurde eine falsches Verzeichnis ausgewählt.]]></item>
                <item name="wcf.acp.devtools.project.sync"><![CDATA[Daten-Abgleich]]></item>
                <item name="wcf.acp.devtools.pip.defaultFilename"><![CDATA[Suchmuster]]></item>
index d5fff7ae99bb8a554184aeebdc41018a64c45f0e..0d728b5aef4e37b305f88ea48690ecb62fed9d18 100644 (file)
                <item name="wcf.acp.devtools.project.path.error.missingExclude"><![CDATA[The <kbd>package.xml</kbd> is missing the <kbd>&gt;excludedpackage&lt;</kbd> instruction for <kbd>com.woltlab.wcf</kbd>.]]></item>
                <item name="wcf.acp.devtools.project.path.error.notInstalled"><![CDATA[The package must be installed already.]]></item>
                <item name="wcf.acp.devtools.project.path.error.notFound"><![CDATA[The path is invalid.]]></item>
+               <item name="wcf.acp.devtools.project.path.error.notUnique"><![CDATA[The path is already used by another project.]]></item>
                <item name="wcf.acp.devtools.project.path.error.versionMismatch"><![CDATA[The version shown in the <kbd>package.xml</kbd> does not match the installed version, you may have selected the wrong path.]]></item>
                <item name="wcf.acp.devtools.project.sync"><![CDATA[Sync Data]]></item>
                <item name="wcf.acp.devtools.pip.defaultFilename"><![CDATA[Search Pattern]]></item>