Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / drydock / query / DrydockLogQuery.php
blobd7e1f77ae6fd96aee1fb2b6e0bb600f2d5dc0ee1
1 <?php
3 final class DrydockLogQuery extends DrydockQuery {
5 private $ids;
6 private $blueprintPHIDs;
7 private $resourcePHIDs;
8 private $leasePHIDs;
9 private $operationPHIDs;
11 public function withIDs(array $ids) {
12 $this->ids = $ids;
13 return $this;
16 public function withBlueprintPHIDs(array $phids) {
17 $this->blueprintPHIDs = $phids;
18 return $this;
21 public function withResourcePHIDs(array $phids) {
22 $this->resourcePHIDs = $phids;
23 return $this;
26 public function withLeasePHIDs(array $phids) {
27 $this->leasePHIDs = $phids;
28 return $this;
31 public function withOperationPHIDs(array $phids) {
32 $this->operationPHIDs = $phids;
33 return $this;
36 public function newResultObject() {
37 return new DrydockLog();
40 protected function didFilterPage(array $logs) {
41 $blueprint_phids = array_filter(mpull($logs, 'getBlueprintPHID'));
42 if ($blueprint_phids) {
43 $blueprints = id(new DrydockBlueprintQuery())
44 ->setParentQuery($this)
45 ->setViewer($this->getViewer())
46 ->withPHIDs($blueprint_phids)
47 ->execute();
48 $blueprints = mpull($blueprints, null, 'getPHID');
49 } else {
50 $blueprints = array();
53 foreach ($logs as $key => $log) {
54 $blueprint = null;
55 $blueprint_phid = $log->getBlueprintPHID();
56 if ($blueprint_phid) {
57 $blueprint = idx($blueprints, $blueprint_phid);
59 $log->attachBlueprint($blueprint);
62 $resource_phids = array_filter(mpull($logs, 'getResourcePHID'));
63 if ($resource_phids) {
64 $resources = id(new DrydockResourceQuery())
65 ->setParentQuery($this)
66 ->setViewer($this->getViewer())
67 ->withPHIDs($resource_phids)
68 ->execute();
69 $resources = mpull($resources, null, 'getPHID');
70 } else {
71 $resources = array();
74 foreach ($logs as $key => $log) {
75 $resource = null;
76 $resource_phid = $log->getResourcePHID();
77 if ($resource_phid) {
78 $resource = idx($resources, $resource_phid);
80 $log->attachResource($resource);
83 $lease_phids = array_filter(mpull($logs, 'getLeasePHID'));
84 if ($lease_phids) {
85 $leases = id(new DrydockLeaseQuery())
86 ->setParentQuery($this)
87 ->setViewer($this->getViewer())
88 ->withPHIDs($lease_phids)
89 ->execute();
90 $leases = mpull($leases, null, 'getPHID');
91 } else {
92 $leases = array();
95 foreach ($logs as $key => $log) {
96 $lease = null;
97 $lease_phid = $log->getLeasePHID();
98 if ($lease_phid) {
99 $lease = idx($leases, $lease_phid);
101 $log->attachLease($lease);
104 $operation_phids = array_filter(mpull($logs, 'getOperationPHID'));
105 if ($operation_phids) {
106 $operations = id(new DrydockRepositoryOperationQuery())
107 ->setParentQuery($this)
108 ->setViewer($this->getViewer())
109 ->withPHIDs($operation_phids)
110 ->execute();
111 $operations = mpull($operations, null, 'getPHID');
112 } else {
113 $operations = array();
116 foreach ($logs as $key => $log) {
117 $operation = null;
118 $operation_phid = $log->getOperationPHID();
119 if ($operation_phid) {
120 $operation = idx($operations, $operation_phid);
122 $log->attachOperation($operation);
125 return $logs;
128 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
129 $where = parent::buildWhereClauseParts($conn);
131 if ($this->ids !== null) {
132 $where[] = qsprintf(
133 $conn,
134 'id IN (%Ls)',
135 $this->ids);
138 if ($this->blueprintPHIDs !== null) {
139 $where[] = qsprintf(
140 $conn,
141 'blueprintPHID IN (%Ls)',
142 $this->blueprintPHIDs);
145 if ($this->resourcePHIDs !== null) {
146 $where[] = qsprintf(
147 $conn,
148 'resourcePHID IN (%Ls)',
149 $this->resourcePHIDs);
152 if ($this->leasePHIDs !== null) {
153 $where[] = qsprintf(
154 $conn,
155 'leasePHID IN (%Ls)',
156 $this->leasePHIDs);
159 if ($this->operationPHIDs !== null) {
160 $where[] = qsprintf(
161 $conn,
162 'operationPHID IN (%Ls)',
163 $this->operationPHIDs);
166 return $where;