Path: blob/master/src/applications/diffusion/identity/DiffusionRepositoryIdentityEngine.php
12242 views
<?php12final class DiffusionRepositoryIdentityEngine3extends Phobject {45private $viewer;6private $sourcePHID;7private $dryRun;89public function setViewer(PhabricatorUser $viewer) {10$this->viewer = $viewer;11return $this;12}1314public function getViewer() {15return $this->viewer;16}1718public function setSourcePHID($source_phid) {19$this->sourcePHID = $source_phid;20return $this;21}2223public function getSourcePHID() {24if (!$this->sourcePHID) {25throw new PhutilInvalidStateException('setSourcePHID');26}2728return $this->sourcePHID;29}3031public function setDryRun($dry_run) {32$this->dryRun = $dry_run;33return $this;34}3536public function getDryRun() {37return $this->dryRun;38}3940public function newResolvedIdentity($raw_identity) {41$identity = $this->loadRawIdentity($raw_identity);4243if (!$identity) {44$identity = $this->newIdentity($raw_identity);45}4647return $this->updateIdentity($identity);48}4950public function newUpdatedIdentity(PhabricatorRepositoryIdentity $identity) {51return $this->updateIdentity($identity);52}5354private function loadRawIdentity($raw_identity) {55$viewer = $this->getViewer();5657return id(new PhabricatorRepositoryIdentityQuery())58->setViewer($viewer)59->withIdentityNames(array($raw_identity))60->executeOne();61}6263private function newIdentity($raw_identity) {64$source_phid = $this->getSourcePHID();6566return id(new PhabricatorRepositoryIdentity())67->setAuthorPHID($source_phid)68->setIdentityName($raw_identity);69}7071private function resolveIdentity(PhabricatorRepositoryIdentity $identity) {72$raw_identity = $identity->getIdentityName();7374return id(new DiffusionResolveUserQuery())75->withName($raw_identity)76->execute();77}7879private function updateIdentity(PhabricatorRepositoryIdentity $identity) {8081// If we're updating an identity and it has a manual user PHID associated82// with it but the user is no longer valid, remove the value. This likely83// corresponds to a user that was destroyed.8485$assigned_phid = $identity->getManuallySetUserPHID();86$unassigned = DiffusionIdentityUnassignedDatasource::FUNCTION_TOKEN;87if ($assigned_phid && ($assigned_phid !== $unassigned)) {88$viewer = $this->getViewer();89$user = id(new PhabricatorPeopleQuery())90->setViewer($viewer)91->withPHIDs(array($assigned_phid))92->executeOne();93if (!$user) {94$identity->setManuallySetUserPHID(null);95}96}9798$resolved_phid = $this->resolveIdentity($identity);99100$identity->setAutomaticGuessedUserPHID($resolved_phid);101102if ($this->getDryRun()) {103$identity->makeEphemeral();104} else {105$identity->save();106}107108return $identity;109}110111public function didUpdateEmailAddress($raw_address) {112PhabricatorWorker::scheduleTask(113'PhabricatorRepositoryIdentityChangeWorker',114array(115'emailAddresses' => array($raw_address),116));117}118119}120121122