Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / repository / worker / PhabricatorRepositoryIdentityChangeWorker.php
blob3cc86d7f92bf9e53088ecfd1b280d4f9a01d5927
1 <?php
3 final class PhabricatorRepositoryIdentityChangeWorker
4 extends PhabricatorWorker {
6 protected function doWork() {
7 $viewer = PhabricatorUser::getOmnipotentUser();
9 $related_phids = $this->getTaskDataValue('relatedPHIDs');
10 $email_addresses = $this->getTaskDataValue('emailAddresses');
12 // Retain backward compatibility with older tasks which may still be in
13 // queue. Previously, this worker accepted a single "userPHID". See
14 // T13444. This can be removed in some future version of Phabricator once
15 // these tasks have likely flushed out of queue.
16 $legacy_phid = $this->getTaskDataValue('userPHID');
17 if ($legacy_phid) {
18 if (!is_array($related_phids)) {
19 $related_phids = array();
21 $related_phids[] = $legacy_phid;
24 // Note that we may arrive in this worker after the associated objects
25 // have already been destroyed, so we can't (and shouldn't) verify that
26 // PHIDs correspond to real objects. If you "bin/remove destroy" a user,
27 // we'll end up here with a now-bogus user PHID that we should
28 // disassociate from identities.
30 $identity_map = array();
32 if ($related_phids) {
33 $identities = id(new PhabricatorRepositoryIdentityQuery())
34 ->setViewer($viewer)
35 ->withRelatedPHIDs($related_phids)
36 ->execute();
37 $identity_map += mpull($identities, null, 'getPHID');
40 if ($email_addresses) {
41 $identities = id(new PhabricatorRepositoryIdentityQuery())
42 ->setViewer($viewer)
43 ->withEmailAddresses($email_addresses)
44 ->execute();
45 $identity_map += mpull($identities, null, 'getPHID');
48 // If we didn't find any related identities, we're all set.
49 if (!$identity_map) {
50 return;
53 $identity_engine = id(new DiffusionRepositoryIdentityEngine())
54 ->setViewer($viewer);
55 foreach ($identity_map as $identity) {
56 $identity_engine->newUpdatedIdentity($identity);