From 6afbb6102ddacaebb7170cf4f9c26aef996028d7 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 13 Nov 2019 20:22:48 -0800 Subject: [PATCH] Remove "PhabricatorEventType::TYPE_DIFFUSION_LOOKUPUSER" event Summary: Ref T13444. This is an ancient event and part of the old event system. It is not likely to be in use anymore, and repository identities should generally replace it nowadays anyway. Test Plan: Grepped for constant and related methods, no longer found any hits. Maniphest Tasks: T13444 Differential Revision: https://secure.phabricator.com/D20909 --- .../query/DiffusionResolveUserQuery.php | 41 ++++--------------- ...epositoryManagementLookupUsersWorkflow.php | 1 - ...oryManagementRebuildIdentitiesWorkflow.php | 1 - ...torRepositoryCommitMessageParserWorker.php | 1 - src/docs/user/userguide/events.diviner | 29 ------------- .../events/constant/PhabricatorEventType.php | 1 - 6 files changed, 8 insertions(+), 66 deletions(-) diff --git a/src/applications/diffusion/query/DiffusionResolveUserQuery.php b/src/applications/diffusion/query/DiffusionResolveUserQuery.php index a22408ce16..8ad13f660e 100644 --- a/src/applications/diffusion/query/DiffusionResolveUserQuery.php +++ b/src/applications/diffusion/query/DiffusionResolveUserQuery.php @@ -8,25 +8,14 @@ final class DiffusionResolveUserQuery extends Phobject { private $name; - private $commit; public function withName($name) { $this->name = $name; return $this; } - public function withCommit($commit) { - $this->commit = $commit; - return $this; - } - public function execute() { - $user_name = $this->name; - - $phid = $this->findUserPHID($this->name); - $phid = $this->fireLookupEvent($phid); - - return $phid; + return $this->findUserPHID($this->name); } private function findUserPHID($user_name) { @@ -75,33 +64,15 @@ final class DiffusionResolveUserQuery extends Phobject { } - /** - * Emit an event so installs can do custom lookup of commit authors who may - * not be naturally resolvable. - */ - private function fireLookupEvent($guess) { - - $type = PhabricatorEventType::TYPE_DIFFUSION_LOOKUPUSER; - $data = array( - 'commit' => $this->commit, - 'query' => $this->name, - 'result' => $guess, - ); - - $event = new PhabricatorEvent($type, $data); - PhutilEventEngine::dispatchEvent($event); - - return $event->getValue('result'); - } - - private function findUserByUserName($user_name) { $by_username = id(new PhabricatorUser())->loadOneWhere( 'userName = %s', $user_name); + if ($by_username) { return $by_username->getPHID(); } + return null; } @@ -112,18 +83,22 @@ final class DiffusionResolveUserQuery extends Phobject { $by_realname = id(new PhabricatorUser())->loadAllWhere( 'realName = %s', $real_name); + if (count($by_realname) == 1) { - return reset($by_realname)->getPHID(); + return head($by_realname)->getPHID(); } + return null; } private function findUserByEmailAddress($email_address) { $by_email = PhabricatorUser::loadOneWithEmailAddress($email_address); + if ($by_email) { return $by_email->getPHID(); } + return null; } diff --git a/src/applications/repository/management/PhabricatorRepositoryManagementLookupUsersWorkflow.php b/src/applications/repository/management/PhabricatorRepositoryManagementLookupUsersWorkflow.php index e02a8dc05c..ec65a8bcfa 100644 --- a/src/applications/repository/management/PhabricatorRepositoryManagementLookupUsersWorkflow.php +++ b/src/applications/repository/management/PhabricatorRepositoryManagementLookupUsersWorkflow.php @@ -99,7 +99,6 @@ final class PhabricatorRepositoryManagementLookupUsersWorkflow private function resolveUser(PhabricatorRepositoryCommit $commit, $name) { $phid = id(new DiffusionResolveUserQuery()) - ->withCommit($commit) ->withName($name) ->execute(); diff --git a/src/applications/repository/management/PhabricatorRepositoryManagementRebuildIdentitiesWorkflow.php b/src/applications/repository/management/PhabricatorRepositoryManagementRebuildIdentitiesWorkflow.php index 86cdcaa462..02ab6e9bf8 100644 --- a/src/applications/repository/management/PhabricatorRepositoryManagementRebuildIdentitiesWorkflow.php +++ b/src/applications/repository/management/PhabricatorRepositoryManagementRebuildIdentitiesWorkflow.php @@ -101,7 +101,6 @@ final class PhabricatorRepositoryManagementRebuildIdentitiesWorkflow if (empty($seen[$identity_key])) { try { $user_phid = id(new DiffusionResolveUserQuery()) - ->withCommit($commit) ->withName($identity_name) ->execute(); diff --git a/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php b/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php index c7f00df73e..e1cc5c90eb 100644 --- a/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php +++ b/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php @@ -182,7 +182,6 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker $user_name) { return id(new DiffusionResolveUserQuery()) - ->withCommit($commit) ->withName($user_name) ->execute(); } diff --git a/src/docs/user/userguide/events.diviner b/src/docs/user/userguide/events.diviner index dc9722a596..ea66448c8a 100644 --- a/src/docs/user/userguide/events.diviner +++ b/src/docs/user/userguide/events.diviner @@ -159,35 +159,6 @@ will be available yet. Data available on this event: - `repository` The @{class:PhabricatorRepository} the commit was discovered in. -== Diffusion: Lookup User == - -The constant for this event is -`PhabricatorEventType::TYPE_DIFFUSION_LOOKUPUSER`. - -This event is dispatched when the daemons are trying to link a commit to a -Phabricator user account. You can listen for it to improve the accuracy of -associating users with their commits. - -By default, Phabricator will try to find matches based on usernames, real names, -or email addresses, but this can result in incorrect matches (e.g., if you have -several employees with the same name) or failures to match (e.g., if someone -changed their email address). Listening for this event allows you to intercept -the lookup and supplement the results from another datasource. - -Data available on this event: - - - `commit` The @{class:PhabricatorRepositoryCommit} that data is being looked - up for. - - `query` The author or committer string being looked up. This will usually - be something like "Abraham Lincoln ", but - comes from the commit metadata so it may not be well-formatted. - - `result` The current result from the lookup (Phabricator's best guess at - the user PHID of the user named in the "query"). To substitute the result - with a different result, replace this with the correct PHID in your event - listener. - -Using @{class@libphutil:PhutilEmailAddress} may be helpful in parsing the query. - == Test: Did Run Test == The constant for this event is diff --git a/src/infrastructure/events/constant/PhabricatorEventType.php b/src/infrastructure/events/constant/PhabricatorEventType.php index 3dea7b36e6..7d3a8981bf 100644 --- a/src/infrastructure/events/constant/PhabricatorEventType.php +++ b/src/infrastructure/events/constant/PhabricatorEventType.php @@ -9,7 +9,6 @@ final class PhabricatorEventType extends PhutilEventType { const TYPE_DIFFERENTIAL_WILLMARKGENERATED = 'differential.willMarkGenerated'; const TYPE_DIFFUSION_DIDDISCOVERCOMMIT = 'diffusion.didDiscoverCommit'; - const TYPE_DIFFUSION_LOOKUPUSER = 'diffusion.lookupUser'; const TYPE_TEST_DIDRUNTEST = 'test.didRunTest';