@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
1<?php
2
3/**
4 * @extends PhabricatorCursorPagedPolicyAwareQuery<PhabricatorRepositoryIdentity>
5 */
6final class PhabricatorRepositoryIdentityQuery
7 extends PhabricatorCursorPagedPolicyAwareQuery {
8
9 private $ids;
10 private $phids;
11 private $identityNames;
12 private $emailAddresses;
13 private $assignedPHIDs;
14 private $effectivePHIDs;
15 private $identityNameLike;
16 private $hasEffectivePHID;
17 private $relatedPHIDs;
18
19 public function withIDs(array $ids) {
20 $this->ids = $ids;
21 return $this;
22 }
23
24 public function withPHIDs(array $phids) {
25 $this->phids = $phids;
26 return $this;
27 }
28
29 public function withIdentityNames(array $names) {
30 $this->identityNames = $names;
31 return $this;
32 }
33
34 public function withIdentityNameLike($name_like) {
35 $this->identityNameLike = $name_like;
36 return $this;
37 }
38
39 public function withEmailAddresses(array $addresses) {
40 $this->emailAddresses = $addresses;
41 return $this;
42 }
43
44 public function withAssignedPHIDs(array $assigned) {
45 $this->assignedPHIDs = $assigned;
46 return $this;
47 }
48
49 public function withEffectivePHIDs(array $effective) {
50 $this->effectivePHIDs = $effective;
51 return $this;
52 }
53
54 public function withRelatedPHIDs(array $related) {
55 $this->relatedPHIDs = $related;
56 return $this;
57 }
58
59 public function withHasEffectivePHID($has_effective_phid) {
60 $this->hasEffectivePHID = $has_effective_phid;
61 return $this;
62 }
63
64 public function newResultObject() {
65 return new PhabricatorRepositoryIdentity();
66 }
67
68 protected function getPrimaryTableAlias() {
69 return 'identity';
70 }
71
72 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
73 $where = parent::buildWhereClauseParts($conn);
74
75 if ($this->ids !== null) {
76 $where[] = qsprintf(
77 $conn,
78 'identity.id IN (%Ld)',
79 $this->ids);
80 }
81
82 if ($this->phids !== null) {
83 $where[] = qsprintf(
84 $conn,
85 'identity.phid IN (%Ls)',
86 $this->phids);
87 }
88
89 if ($this->assignedPHIDs !== null) {
90 $where[] = qsprintf(
91 $conn,
92 'identity.manuallySetUserPHID IN (%Ls)',
93 $this->assignedPHIDs);
94 }
95
96 if ($this->effectivePHIDs !== null) {
97 $where[] = qsprintf(
98 $conn,
99 'identity.currentEffectiveUserPHID IN (%Ls)',
100 $this->effectivePHIDs);
101 }
102
103 if ($this->hasEffectivePHID !== null) {
104 if ($this->hasEffectivePHID) {
105 $where[] = qsprintf(
106 $conn,
107 'identity.currentEffectiveUserPHID IS NOT NULL');
108 } else {
109 $where[] = qsprintf(
110 $conn,
111 'identity.currentEffectiveUserPHID IS NULL');
112 }
113 }
114
115 if ($this->identityNames !== null) {
116 $name_hashes = array();
117 foreach ($this->identityNames as $name) {
118 $name_hashes[] = PhabricatorHash::digestForIndex($name);
119 }
120
121 $where[] = qsprintf(
122 $conn,
123 'identity.identityNameHash IN (%Ls)',
124 $name_hashes);
125 }
126
127 if ($this->emailAddresses !== null) {
128 $where[] = qsprintf(
129 $conn,
130 'identity.emailAddress IN (%Ls)',
131 $this->emailAddresses);
132 }
133
134 if ($this->identityNameLike != null) {
135 $where[] = qsprintf(
136 $conn,
137 'identity.identityNameRaw LIKE %~',
138 $this->identityNameLike);
139 }
140
141 if ($this->relatedPHIDs !== null) {
142 $where[] = qsprintf(
143 $conn,
144 '(identity.manuallySetUserPHID IN (%Ls) OR
145 identity.currentEffectiveUserPHID IN (%Ls) OR
146 identity.automaticGuessedUserPHID IN (%Ls))',
147 $this->relatedPHIDs,
148 $this->relatedPHIDs,
149 $this->relatedPHIDs);
150 }
151
152 return $where;
153 }
154
155 public function getQueryApplicationClass() {
156 return PhabricatorDiffusionApplication::class;
157 }
158
159}