Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/drydock/query/DrydockLogQuery.php
12256 views
1
<?php
2
3
final class DrydockLogQuery extends DrydockQuery {
4
5
private $ids;
6
private $blueprintPHIDs;
7
private $resourcePHIDs;
8
private $leasePHIDs;
9
private $operationPHIDs;
10
11
public function withIDs(array $ids) {
12
$this->ids = $ids;
13
return $this;
14
}
15
16
public function withBlueprintPHIDs(array $phids) {
17
$this->blueprintPHIDs = $phids;
18
return $this;
19
}
20
21
public function withResourcePHIDs(array $phids) {
22
$this->resourcePHIDs = $phids;
23
return $this;
24
}
25
26
public function withLeasePHIDs(array $phids) {
27
$this->leasePHIDs = $phids;
28
return $this;
29
}
30
31
public function withOperationPHIDs(array $phids) {
32
$this->operationPHIDs = $phids;
33
return $this;
34
}
35
36
public function newResultObject() {
37
return new DrydockLog();
38
}
39
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();
51
}
52
53
foreach ($logs as $key => $log) {
54
$blueprint = null;
55
$blueprint_phid = $log->getBlueprintPHID();
56
if ($blueprint_phid) {
57
$blueprint = idx($blueprints, $blueprint_phid);
58
}
59
$log->attachBlueprint($blueprint);
60
}
61
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();
72
}
73
74
foreach ($logs as $key => $log) {
75
$resource = null;
76
$resource_phid = $log->getResourcePHID();
77
if ($resource_phid) {
78
$resource = idx($resources, $resource_phid);
79
}
80
$log->attachResource($resource);
81
}
82
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();
93
}
94
95
foreach ($logs as $key => $log) {
96
$lease = null;
97
$lease_phid = $log->getLeasePHID();
98
if ($lease_phid) {
99
$lease = idx($leases, $lease_phid);
100
}
101
$log->attachLease($lease);
102
}
103
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();
114
}
115
116
foreach ($logs as $key => $log) {
117
$operation = null;
118
$operation_phid = $log->getOperationPHID();
119
if ($operation_phid) {
120
$operation = idx($operations, $operation_phid);
121
}
122
$log->attachOperation($operation);
123
}
124
125
return $logs;
126
}
127
128
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
129
$where = parent::buildWhereClauseParts($conn);
130
131
if ($this->ids !== null) {
132
$where[] = qsprintf(
133
$conn,
134
'id IN (%Ls)',
135
$this->ids);
136
}
137
138
if ($this->blueprintPHIDs !== null) {
139
$where[] = qsprintf(
140
$conn,
141
'blueprintPHID IN (%Ls)',
142
$this->blueprintPHIDs);
143
}
144
145
if ($this->resourcePHIDs !== null) {
146
$where[] = qsprintf(
147
$conn,
148
'resourcePHID IN (%Ls)',
149
$this->resourcePHIDs);
150
}
151
152
if ($this->leasePHIDs !== null) {
153
$where[] = qsprintf(
154
$conn,
155
'leasePHID IN (%Ls)',
156
$this->leasePHIDs);
157
}
158
159
if ($this->operationPHIDs !== null) {
160
$where[] = qsprintf(
161
$conn,
162
'operationPHID IN (%Ls)',
163
$this->operationPHIDs);
164
}
165
166
return $where;
167
}
168
169
}
170
171