3 final class DiffusionRepositoryIdentityEngine
10 public function setViewer(PhabricatorUser
$viewer) {
11 $this->viewer
= $viewer;
15 public function getViewer() {
19 public function setSourcePHID($source_phid) {
20 $this->sourcePHID
= $source_phid;
24 public function getSourcePHID() {
25 if (!$this->sourcePHID
) {
26 throw new PhutilInvalidStateException('setSourcePHID');
29 return $this->sourcePHID
;
32 public function setDryRun($dry_run) {
33 $this->dryRun
= $dry_run;
37 public function getDryRun() {
41 public function newResolvedIdentity($raw_identity) {
42 $identity = $this->loadRawIdentity($raw_identity);
45 $identity = $this->newIdentity($raw_identity);
48 return $this->updateIdentity($identity);
51 public function newUpdatedIdentity(PhabricatorRepositoryIdentity
$identity) {
52 return $this->updateIdentity($identity);
55 private function loadRawIdentity($raw_identity) {
56 $viewer = $this->getViewer();
58 return id(new PhabricatorRepositoryIdentityQuery())
60 ->withIdentityNames(array($raw_identity))
64 private function newIdentity($raw_identity) {
65 $source_phid = $this->getSourcePHID();
67 return id(new PhabricatorRepositoryIdentity())
68 ->setAuthorPHID($source_phid)
69 ->setIdentityName($raw_identity);
72 private function resolveIdentity(PhabricatorRepositoryIdentity
$identity) {
73 $raw_identity = $identity->getIdentityName();
75 return id(new DiffusionResolveUserQuery())
76 ->withName($raw_identity)
80 private function updateIdentity(PhabricatorRepositoryIdentity
$identity) {
82 // If we're updating an identity and it has a manual user PHID associated
83 // with it but the user is no longer valid, remove the value. This likely
84 // corresponds to a user that was destroyed.
86 $assigned_phid = $identity->getManuallySetUserPHID();
87 $unassigned = DiffusionIdentityUnassignedDatasource
::FUNCTION_TOKEN
;
88 if ($assigned_phid && ($assigned_phid !== $unassigned)) {
89 $viewer = $this->getViewer();
90 $user = id(new PhabricatorPeopleQuery())
92 ->withPHIDs(array($assigned_phid))
95 $identity->setManuallySetUserPHID(null);
99 $resolved_phid = $this->resolveIdentity($identity);
101 $identity->setAutomaticGuessedUserPHID($resolved_phid);
103 if ($this->getDryRun()) {
104 $identity->makeEphemeral();
112 public function didUpdateEmailAddress($raw_address) {
113 PhabricatorWorker
::scheduleTask(
114 'PhabricatorRepositoryIdentityChangeWorker',
116 'emailAddresses' => array($raw_address),