diff --git a/src/applications/people/PhabricatorUserEditor.php b/src/applications/people/PhabricatorUserEditor.php index 6fa19424d3..e92b7b5198 100644 --- a/src/applications/people/PhabricatorUserEditor.php +++ b/src/applications/people/PhabricatorUserEditor.php @@ -68,13 +68,16 @@ final class PhabricatorUserEditor { $this->willAddEmail($email); $user->openTransaction(); - $user->save(); - - $email->setUserPHID($user->getPHID()); - try { + $user->save(); + $email->setUserPHID($user->getPHID()); $email->save(); } catch (AphrontQueryDuplicateKeyException $ex) { + // We might have written the user but failed to write the email; if + // so, erase the IDs we attached. + $user->setID(null); + $user->setPHID(null); + $user->killTransaction(); throw $ex; } diff --git a/src/applications/people/controller/PhabricatorPeopleEditController.php b/src/applications/people/controller/PhabricatorPeopleEditController.php index 16ac401b3d..c2e314adf4 100644 --- a/src/applications/people/controller/PhabricatorPeopleEditController.php +++ b/src/applications/people/controller/PhabricatorPeopleEditController.php @@ -139,6 +139,8 @@ final class PhabricatorPeopleEditController } else if (!PhabricatorUserEmail::isAllowedAddress($new_email)) { $e_email = 'Invalid'; $errors[] = PhabricatorUserEmail::describeAllowedAddresses(); + } else { + $e_email = null; } if ($request->getStr('role') == 'agent') {