4 * Resolve an author or committer name, like
5 * `"Abraham Lincoln <alincoln@logcab.in>"`, into a valid Phabricator user
6 * account, like `@alincoln`.
8 final class DiffusionResolveUserQuery
extends Phobject
{
12 public function withName($name) {
17 public function execute() {
18 return $this->findUserPHID($this->name
);
21 private function findUserPHID($user_name) {
22 if (!strlen($user_name)) {
26 $phid = $this->findUserByUserName($user_name);
31 $phid = $this->findUserByEmailAddress($user_name);
36 $phid = $this->findUserByRealName($user_name);
41 // No hits yet, try to parse it as an email address.
43 $email = new PhutilEmailAddress($user_name);
45 $phid = $this->findUserByEmailAddress($email->getAddress());
50 $display_name = $email->getDisplayName();
52 $phid = $this->findUserByUserName($display_name);
57 $phid = $this->findUserByRealName($display_name);
67 private function findUserByUserName($user_name) {
68 $by_username = id(new PhabricatorUser())->loadOneWhere(
73 return $by_username->getPHID();
80 private function findUserByRealName($real_name) {
81 // Note, real names are not guaranteed unique, which is why we do it this
83 $by_realname = id(new PhabricatorUser())->loadAllWhere(
87 if (count($by_realname) == 1) {
88 return head($by_realname)->getPHID();
95 private function findUserByEmailAddress($email_address) {
96 $by_email = PhabricatorUser
::loadOneWithEmailAddress($email_address);
99 return $by_email->getPHID();