From 042f6bb80235f533a2ce0913b61ebf34420e18f0 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 23 Jul 2017 10:20:33 +0200 Subject: [PATCH] Add missing check if project path is unique See #2331 --- .../acp/form/DevtoolsProjectAddForm.class.php | 23 ++++++++++++++++--- .../form/DevtoolsProjectEditForm.class.php | 19 +++++++++++++++ wcfsetup/install/lang/de.xml | 1 + wcfsetup/install/lang/en.xml | 1 + 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/lib/acp/form/DevtoolsProjectAddForm.class.php b/wcfsetup/install/files/lib/acp/form/DevtoolsProjectAddForm.class.php index ccf77c0e05..ae3f8f1f77 100644 --- a/wcfsetup/install/files/lib/acp/form/DevtoolsProjectAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/DevtoolsProjectAddForm.class.php @@ -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 */ diff --git a/wcfsetup/install/files/lib/acp/form/DevtoolsProjectEditForm.class.php b/wcfsetup/install/files/lib/acp/form/DevtoolsProjectEditForm.class.php index 3c60a3a3e6..187015f2e6 100644 --- a/wcfsetup/install/files/lib/acp/form/DevtoolsProjectEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/DevtoolsProjectEditForm.class.php @@ -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 */ diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 52c15a02ca..8090c77695 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -382,6 +382,7 @@ package.xml fehlt die >excludedpackage<-Anweisung für com.woltlab.wcf.]]> + package.xml passt nicht zur installierten Version, möglicherweise wurde eine falsches Verzeichnis ausgewählt.]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index d5fff7ae99..0d728b5aef 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -365,6 +365,7 @@ package.xml is missing the >excludedpackage< instruction for com.woltlab.wcf.]]> + package.xml does not match the installed version, you may have selected the wrong path.]]> -- 2.20.1