@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 DrydockQuery<DrydockLog>
5 */
6final class DrydockLogQuery extends DrydockQuery {
7
8 private $ids;
9 private $blueprintPHIDs;
10 private $resourcePHIDs;
11 private $leasePHIDs;
12 private $operationPHIDs;
13
14 public function withIDs(array $ids) {
15 $this->ids = $ids;
16 return $this;
17 }
18
19 public function withBlueprintPHIDs(array $phids) {
20 $this->blueprintPHIDs = $phids;
21 return $this;
22 }
23
24 public function withResourcePHIDs(array $phids) {
25 $this->resourcePHIDs = $phids;
26 return $this;
27 }
28
29 public function withLeasePHIDs(array $phids) {
30 $this->leasePHIDs = $phids;
31 return $this;
32 }
33
34 public function withOperationPHIDs(array $phids) {
35 $this->operationPHIDs = $phids;
36 return $this;
37 }
38
39 public function newResultObject() {
40 return new DrydockLog();
41 }
42
43 protected function didFilterPage(array $logs) {
44 $blueprint_phids = array_filter(mpull($logs, 'getBlueprintPHID'));
45 if ($blueprint_phids) {
46 $blueprints = id(new DrydockBlueprintQuery())
47 ->setParentQuery($this)
48 ->setViewer($this->getViewer())
49 ->withPHIDs($blueprint_phids)
50 ->execute();
51 $blueprints = mpull($blueprints, null, 'getPHID');
52 } else {
53 $blueprints = array();
54 }
55
56 foreach ($logs as $key => $log) {
57 $blueprint = null;
58 $blueprint_phid = $log->getBlueprintPHID();
59 if ($blueprint_phid) {
60 $blueprint = idx($blueprints, $blueprint_phid);
61 }
62 $log->attachBlueprint($blueprint);
63 }
64
65 $resource_phids = array_filter(mpull($logs, 'getResourcePHID'));
66 if ($resource_phids) {
67 $resources = id(new DrydockResourceQuery())
68 ->setParentQuery($this)
69 ->setViewer($this->getViewer())
70 ->withPHIDs($resource_phids)
71 ->execute();
72 $resources = mpull($resources, null, 'getPHID');
73 } else {
74 $resources = array();
75 }
76
77 foreach ($logs as $key => $log) {
78 $resource = null;
79 $resource_phid = $log->getResourcePHID();
80 if ($resource_phid) {
81 $resource = idx($resources, $resource_phid);
82 }
83 $log->attachResource($resource);
84 }
85
86 $lease_phids = array_filter(mpull($logs, 'getLeasePHID'));
87 if ($lease_phids) {
88 $leases = id(new DrydockLeaseQuery())
89 ->setParentQuery($this)
90 ->setViewer($this->getViewer())
91 ->withPHIDs($lease_phids)
92 ->execute();
93 $leases = mpull($leases, null, 'getPHID');
94 } else {
95 $leases = array();
96 }
97
98 foreach ($logs as $key => $log) {
99 $lease = null;
100 $lease_phid = $log->getLeasePHID();
101 if ($lease_phid) {
102 $lease = idx($leases, $lease_phid);
103 }
104 $log->attachLease($lease);
105 }
106
107 $operation_phids = array_filter(mpull($logs, 'getOperationPHID'));
108 if ($operation_phids) {
109 $operations = id(new DrydockRepositoryOperationQuery())
110 ->setParentQuery($this)
111 ->setViewer($this->getViewer())
112 ->withPHIDs($operation_phids)
113 ->execute();
114 $operations = mpull($operations, null, 'getPHID');
115 } else {
116 $operations = array();
117 }
118
119 foreach ($logs as $key => $log) {
120 $operation = null;
121 $operation_phid = $log->getOperationPHID();
122 if ($operation_phid) {
123 $operation = idx($operations, $operation_phid);
124 }
125 $log->attachOperation($operation);
126 }
127
128 return $logs;
129 }
130
131 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
132 $where = parent::buildWhereClauseParts($conn);
133
134 if ($this->ids !== null) {
135 $where[] = qsprintf(
136 $conn,
137 'id IN (%Ls)',
138 $this->ids);
139 }
140
141 if ($this->blueprintPHIDs !== null) {
142 $where[] = qsprintf(
143 $conn,
144 'blueprintPHID IN (%Ls)',
145 $this->blueprintPHIDs);
146 }
147
148 if ($this->resourcePHIDs !== null) {
149 $where[] = qsprintf(
150 $conn,
151 'resourcePHID IN (%Ls)',
152 $this->resourcePHIDs);
153 }
154
155 if ($this->leasePHIDs !== null) {
156 $where[] = qsprintf(
157 $conn,
158 'leasePHID IN (%Ls)',
159 $this->leasePHIDs);
160 }
161
162 if ($this->operationPHIDs !== null) {
163 $where[] = qsprintf(
164 $conn,
165 'operationPHID IN (%Ls)',
166 $this->operationPHIDs);
167 }
168
169 return $where;
170 }
171
172}