From 4de5e949ca38061c96309b3fd640c4fd8ceb08b0 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 15 Oct 2012 14:51:12 -0700 Subject: [PATCH] Raise a better error in Phame when trying to set two blogs to the same domain Summary: Currently the exception escapes to top level. Instead, intercept it and complain. Test Plan: Tried to set two blogs to the same domain. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T1373 Differential Revision: https://secure.phabricator.com/D3701 --- .../controller/blog/PhameBlogEditController.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/applications/phame/controller/blog/PhameBlogEditController.php b/src/applications/phame/controller/blog/PhameBlogEditController.php index 7da19afdc3..c3af88a262 100644 --- a/src/applications/phame/controller/blog/PhameBlogEditController.php +++ b/src/applications/phame/controller/blog/PhameBlogEditController.php @@ -80,6 +80,8 @@ final class PhameBlogEditController $blog->setName($name); $blog->setDescription($description); + $blog->setDomain($custom_domain); + $blog->setSkin($skin); if (!empty($custom_domain)) { $error = $blog->validateCustomDomain($custom_domain); @@ -87,9 +89,7 @@ final class PhameBlogEditController $errors[] = $error; $e_custom_domain = 'Invalid'; } - $blog->setDomain($custom_domain); } - $blog->setSkin($skin); $blog->setViewPolicy($request->getStr('can_view')); $blog->setEditPolicy($request->getStr('can_edit')); @@ -102,9 +102,14 @@ final class PhameBlogEditController PhabricatorPolicyCapability::CAN_EDIT); if (!$errors) { - $blog->save(); - return id(new AphrontRedirectResponse()) - ->setURI($this->getApplicationURI('blog/view/'.$blog->getID().'/')); + try { + $blog->save(); + return id(new AphrontRedirectResponse()) + ->setURI($this->getApplicationURI('blog/view/'.$blog->getID().'/')); + } catch (AphrontQueryDuplicateKeyException $ex) { + $errors[] = 'Domain must be unique.'; + $e_custom_domain = 'Not Unique'; + } } }