From c00733a292e88c79d97712e22053c3636091e90f Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Mon, 21 Apr 2014 15:44:35 -0700 Subject: [PATCH] Project - add editor-level support for detecting name conflicts Summary: Fixes T4833. I wish there was an elegant way to catch this exception but I think the stack is written such that we really should just do this one-off query here... Test Plan: from the "create project" link under "edit task" I received a more detailed exception than the report in T4833 post patch. I also tested editing an existing project - yay - and editing an existing project to some other existing project's name - got a nice error dialogue. Reviewers: epriestley Reviewed By: epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T4833 Differential Revision: https://secure.phabricator.com/D8834 --- .../PhabricatorProjectTransactionEditor.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/applications/project/editor/PhabricatorProjectTransactionEditor.php b/src/applications/project/editor/PhabricatorProjectTransactionEditor.php index dba6403757..82c17697f6 100644 --- a/src/applications/project/editor/PhabricatorProjectTransactionEditor.php +++ b/src/applications/project/editor/PhabricatorProjectTransactionEditor.php @@ -179,6 +179,25 @@ final class PhabricatorProjectTransactionEditor $error->setIsMissingFieldError(true); $errors[] = $error; } + + if (!$xactions) { + break; + } + + $name = last($xactions)->getNewValue(); + $name_used_already = id(new PhabricatorProjectQuery()) + ->setViewer($this->getActor()) + ->withNames(array($name)) + ->executeOne(); + if ($name_used_already && + ($name_used_already->getPHID() != $object->getPHID())) { + $error = new PhabricatorApplicationTransactionValidationError( + $type, + pht(''), + pht('Project name is already used.'), + nonempty(last($xactions), null)); + $errors[] = $error; + } break; }