Something went wrong. Try again.
@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
Something went wrong. Try again.
3.0 kB · 120 lines
PHP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121<?php
final class DiffusionRepositoryIdentityEngine extends Phobject {
private $viewer; private $sourcePHID; private $dryRun;
public function setViewer(PhabricatorUser $viewer) { $this->viewer = $viewer; return $this; }
public function getViewer() { return $this->viewer; }
public function setSourcePHID($source_phid) { $this->sourcePHID = $source_phid; return $this; }
public function getSourcePHID() { if (!$this->sourcePHID) { throw new PhutilInvalidStateException('setSourcePHID'); }
return $this->sourcePHID; }
public function setDryRun($dry_run) { $this->dryRun = $dry_run; return $this; }
public function getDryRun() { return $this->dryRun; }
public function newResolvedIdentity($raw_identity) { $identity = $this->loadRawIdentity($raw_identity);
if (!$identity) { $identity = $this->newIdentity($raw_identity); }
return $this->updateIdentity($identity); }
public function newUpdatedIdentity(PhabricatorRepositoryIdentity $identity) { return $this->updateIdentity($identity); }
private function loadRawIdentity($raw_identity) { $viewer = $this->getViewer();
return id(new PhabricatorRepositoryIdentityQuery()) ->setViewer($viewer) ->withIdentityNames(array($raw_identity)) ->executeOne(); }
private function newIdentity($raw_identity) { $source_phid = $this->getSourcePHID();
return id(new PhabricatorRepositoryIdentity()) ->setAuthorPHID($source_phid) ->setIdentityName($raw_identity); }
private function resolveIdentity(PhabricatorRepositoryIdentity $identity) { $raw_identity = $identity->getIdentityName();
return id(new DiffusionResolveUserQuery()) ->withName($raw_identity) ->execute(); }
private function updateIdentity(PhabricatorRepositoryIdentity $identity) {
// If we're updating an identity and it has a manual user PHID associated // with it but the user is no longer valid, remove the value. This likely // corresponds to a user that was destroyed.
$assigned_phid = $identity->getManuallySetUserPHID(); $unassigned = DiffusionIdentityUnassignedDatasource::FUNCTION_TOKEN; if ($assigned_phid && ($assigned_phid !== $unassigned)) { $viewer = $this->getViewer(); $user = id(new PhabricatorPeopleQuery()) ->setViewer($viewer) ->withPHIDs(array($assigned_phid)) ->executeOne(); if (!$user) { $identity->setManuallySetUserPHID(null); } }
$resolved_phid = $this->resolveIdentity($identity);
$identity->setAutomaticGuessedUserPHID($resolved_phid);
if ($this->getDryRun()) { $identity->makeEphemeral(); } else { $identity->save(); }
return $identity; }
public function didUpdateEmailAddress($raw_address) { PhabricatorWorker::scheduleTask( 'PhabricatorRepositoryIdentityChangeWorker', array( 'emailAddresses' => array($raw_address), )); }
}