@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<PhabricatorProjectColumn>
5 */
6final class PhabricatorProjectColumnQuery
7 extends PhabricatorCursorPagedPolicyAwareQuery {
8
9 private $ids;
10 private $phids;
11 private $projectPHIDs;
12 private $proxyPHIDs;
13 private $statuses;
14 private $isProxyColumn;
15 private $triggerPHIDs;
16 private $needTriggers;
17
18 public function withIDs(array $ids) {
19 $this->ids = $ids;
20 return $this;
21 }
22
23 public function withPHIDs(array $phids) {
24 $this->phids = $phids;
25 return $this;
26 }
27
28 public function withProjectPHIDs(array $project_phids) {
29 $this->projectPHIDs = $project_phids;
30 return $this;
31 }
32
33 public function withProxyPHIDs(array $proxy_phids) {
34 $this->proxyPHIDs = $proxy_phids;
35 return $this;
36 }
37
38 public function withStatuses(array $status) {
39 $this->statuses = $status;
40 return $this;
41 }
42
43 public function withIsProxyColumn($is_proxy) {
44 $this->isProxyColumn = $is_proxy;
45 return $this;
46 }
47
48 public function withTriggerPHIDs(array $trigger_phids) {
49 $this->triggerPHIDs = $trigger_phids;
50 return $this;
51 }
52
53 public function needTriggers($need_triggers) {
54 $this->needTriggers = true;
55 return $this;
56 }
57
58 public function newResultObject() {
59 return new PhabricatorProjectColumn();
60 }
61
62 protected function willFilterPage(array $page) {
63 $projects = array();
64
65 $project_phids = array_filter(mpull($page, 'getProjectPHID'));
66 if ($project_phids) {
67 $projects = id(new PhabricatorProjectQuery())
68 ->setParentQuery($this)
69 ->setViewer($this->getViewer())
70 ->withPHIDs($project_phids)
71 ->execute();
72 $projects = mpull($projects, null, 'getPHID');
73 }
74
75 foreach ($page as $key => $column) {
76 $phid = $column->getProjectPHID();
77 $project = idx($projects, $phid);
78 if (!$project) {
79 $this->didRejectResult($page[$key]);
80 unset($page[$key]);
81 continue;
82 }
83 $column->attachProject($project);
84 }
85
86 $proxy_phids = array_filter(mpull($page, 'getProjectPHID'));
87
88 return $page;
89 }
90
91 protected function didFilterPage(array $page) {
92 $proxy_phids = array();
93 foreach ($page as $column) {
94 $proxy_phid = $column->getProxyPHID();
95 if ($proxy_phid !== null) {
96 $proxy_phids[$proxy_phid] = $proxy_phid;
97 }
98 }
99
100 if ($proxy_phids) {
101 $proxies = id(new PhabricatorObjectQuery())
102 ->setParentQuery($this)
103 ->setViewer($this->getViewer())
104 ->withPHIDs($proxy_phids)
105 ->execute();
106 $proxies = mpull($proxies, null, 'getPHID');
107 } else {
108 $proxies = array();
109 }
110
111 foreach ($page as $key => $column) {
112 $proxy_phid = $column->getProxyPHID();
113
114 if ($proxy_phid !== null) {
115 $proxy = idx($proxies, $proxy_phid);
116
117 // Only attach valid proxies, so we don't end up getting surprised if
118 // an install somehow gets junk into their database.
119 if (!($proxy instanceof PhabricatorColumnProxyInterface)) {
120 $proxy = null;
121 }
122
123 if (!$proxy) {
124 $this->didRejectResult($column);
125 unset($page[$key]);
126 continue;
127 }
128 } else {
129 $proxy = null;
130 }
131
132 $column->attachProxy($proxy);
133 }
134
135 if ($this->needTriggers) {
136 $trigger_phids = array();
137 foreach ($page as $column) {
138 if ($column->canHaveTrigger()) {
139 $trigger_phid = $column->getTriggerPHID();
140 if ($trigger_phid) {
141 $trigger_phids[] = $trigger_phid;
142 }
143 }
144 }
145
146 if ($trigger_phids) {
147 $triggers = id(new PhabricatorProjectTriggerQuery())
148 ->setViewer($this->getViewer())
149 ->setParentQuery($this)
150 ->withPHIDs($trigger_phids)
151 ->execute();
152 $triggers = mpull($triggers, null, 'getPHID');
153 } else {
154 $triggers = array();
155 }
156
157 foreach ($page as $column) {
158 $trigger = null;
159
160 if ($column->canHaveTrigger()) {
161 $trigger_phid = $column->getTriggerPHID();
162 if ($trigger_phid) {
163 $trigger = idx($triggers, $trigger_phid);
164 }
165 }
166
167 $column->attachTrigger($trigger);
168 }
169 }
170
171 return $page;
172 }
173
174 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
175 $where = parent::buildWhereClauseParts($conn);
176
177 if ($this->ids !== null) {
178 $where[] = qsprintf(
179 $conn,
180 'id IN (%Ld)',
181 $this->ids);
182 }
183
184 if ($this->phids !== null) {
185 $where[] = qsprintf(
186 $conn,
187 'phid IN (%Ls)',
188 $this->phids);
189 }
190
191 if ($this->projectPHIDs !== null) {
192 $where[] = qsprintf(
193 $conn,
194 'projectPHID IN (%Ls)',
195 $this->projectPHIDs);
196 }
197
198 if ($this->proxyPHIDs !== null) {
199 $where[] = qsprintf(
200 $conn,
201 'proxyPHID IN (%Ls)',
202 $this->proxyPHIDs);
203 }
204
205 if ($this->statuses !== null) {
206 $where[] = qsprintf(
207 $conn,
208 'status IN (%Ld)',
209 $this->statuses);
210 }
211
212 if ($this->triggerPHIDs !== null) {
213 $where[] = qsprintf(
214 $conn,
215 'triggerPHID IN (%Ls)',
216 $this->triggerPHIDs);
217 }
218
219 if ($this->isProxyColumn !== null) {
220 if ($this->isProxyColumn) {
221 $where[] = qsprintf($conn, 'proxyPHID IS NOT NULL');
222 } else {
223 $where[] = qsprintf($conn, 'proxyPHID IS NULL');
224 }
225 }
226
227 return $where;
228 }
229
230 public function getQueryApplicationClass() {
231 return PhabricatorProjectApplication::class;
232 }
233
234}