Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / query / PhabricatorRepositoryIdentityQuery.php
blob2b05b542d5e413639f1dbd61d157d7f1ce26e379
1 <?php
3 final class PhabricatorRepositoryIdentityQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $phids;
8 private $identityNames;
9 private $emailAddresses;
10 private $assignedPHIDs;
11 private $effectivePHIDs;
12 private $identityNameLike;
13 private $hasEffectivePHID;
14 private $relatedPHIDs;
16 public function withIDs(array $ids) {
17 $this->ids = $ids;
18 return $this;
21 public function withPHIDs(array $phids) {
22 $this->phids = $phids;
23 return $this;
26 public function withIdentityNames(array $names) {
27 $this->identityNames = $names;
28 return $this;
31 public function withIdentityNameLike($name_like) {
32 $this->identityNameLike = $name_like;
33 return $this;
36 public function withEmailAddresses(array $addresses) {
37 $this->emailAddresses = $addresses;
38 return $this;
41 public function withAssignedPHIDs(array $assigned) {
42 $this->assignedPHIDs = $assigned;
43 return $this;
46 public function withEffectivePHIDs(array $effective) {
47 $this->effectivePHIDs = $effective;
48 return $this;
51 public function withRelatedPHIDs(array $related) {
52 $this->relatedPHIDs = $related;
53 return $this;
56 public function withHasEffectivePHID($has_effective_phid) {
57 $this->hasEffectivePHID = $has_effective_phid;
58 return $this;
61 public function newResultObject() {
62 return new PhabricatorRepositoryIdentity();
65 protected function getPrimaryTableAlias() {
66 return 'identity';
69 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
70 $where = parent::buildWhereClauseParts($conn);
72 if ($this->ids !== null) {
73 $where[] = qsprintf(
74 $conn,
75 'identity.id IN (%Ld)',
76 $this->ids);
79 if ($this->phids !== null) {
80 $where[] = qsprintf(
81 $conn,
82 'identity.phid IN (%Ls)',
83 $this->phids);
86 if ($this->assignedPHIDs !== null) {
87 $where[] = qsprintf(
88 $conn,
89 'identity.manuallySetUserPHID IN (%Ls)',
90 $this->assignedPHIDs);
93 if ($this->effectivePHIDs !== null) {
94 $where[] = qsprintf(
95 $conn,
96 'identity.currentEffectiveUserPHID IN (%Ls)',
97 $this->effectivePHIDs);
100 if ($this->hasEffectivePHID !== null) {
101 if ($this->hasEffectivePHID) {
102 $where[] = qsprintf(
103 $conn,
104 'identity.currentEffectiveUserPHID IS NOT NULL');
105 } else {
106 $where[] = qsprintf(
107 $conn,
108 'identity.currentEffectiveUserPHID IS NULL');
112 if ($this->identityNames !== null) {
113 $name_hashes = array();
114 foreach ($this->identityNames as $name) {
115 $name_hashes[] = PhabricatorHash::digestForIndex($name);
118 $where[] = qsprintf(
119 $conn,
120 'identity.identityNameHash IN (%Ls)',
121 $name_hashes);
124 if ($this->emailAddresses !== null) {
125 $where[] = qsprintf(
126 $conn,
127 'identity.emailAddress IN (%Ls)',
128 $this->emailAddresses);
131 if ($this->identityNameLike != null) {
132 $where[] = qsprintf(
133 $conn,
134 'identity.identityNameRaw LIKE %~',
135 $this->identityNameLike);
138 if ($this->relatedPHIDs !== null) {
139 $where[] = qsprintf(
140 $conn,
141 '(identity.manuallySetUserPHID IN (%Ls) OR
142 identity.currentEffectiveUserPHID IN (%Ls) OR
143 identity.automaticGuessedUserPHID IN (%Ls))',
144 $this->relatedPHIDs,
145 $this->relatedPHIDs,
146 $this->relatedPHIDs);
149 return $where;
152 public function getQueryApplicationClass() {
153 return 'PhabricatorDiffusionApplication';