Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/query/HarbormasterBuildableQuery.php
12256 views
1
<?php
2
3
final class HarbormasterBuildableQuery
4
extends PhabricatorCursorPagedPolicyAwareQuery {
5
6
private $ids;
7
private $phids;
8
private $buildablePHIDs;
9
private $containerPHIDs;
10
private $statuses;
11
private $manualBuildables;
12
13
private $needContainerObjects;
14
private $needBuilds;
15
private $needTargets;
16
17
public function withIDs(array $ids) {
18
$this->ids = $ids;
19
return $this;
20
}
21
22
public function withPHIDs(array $phids) {
23
$this->phids = $phids;
24
return $this;
25
}
26
27
public function withBuildablePHIDs(array $buildable_phids) {
28
$this->buildablePHIDs = $buildable_phids;
29
return $this;
30
}
31
32
public function withContainerPHIDs(array $container_phids) {
33
$this->containerPHIDs = $container_phids;
34
return $this;
35
}
36
37
public function withManualBuildables($manual) {
38
$this->manualBuildables = $manual;
39
return $this;
40
}
41
42
public function needContainerObjects($need) {
43
$this->needContainerObjects = $need;
44
return $this;
45
}
46
47
public function withStatuses(array $statuses) {
48
$this->statuses = $statuses;
49
return $this;
50
}
51
52
public function needBuilds($need) {
53
$this->needBuilds = $need;
54
return $this;
55
}
56
57
public function needTargets($need) {
58
$this->needTargets = $need;
59
return $this;
60
}
61
62
public function newResultObject() {
63
return new HarbormasterBuildable();
64
}
65
66
protected function willFilterPage(array $page) {
67
$buildables = array();
68
69
$buildable_phids = array_filter(mpull($page, 'getBuildablePHID'));
70
if ($buildable_phids) {
71
$buildables = id(new PhabricatorObjectQuery())
72
->setViewer($this->getViewer())
73
->withPHIDs($buildable_phids)
74
->setParentQuery($this)
75
->execute();
76
$buildables = mpull($buildables, null, 'getPHID');
77
}
78
79
foreach ($page as $key => $buildable) {
80
$buildable_phid = $buildable->getBuildablePHID();
81
if (empty($buildables[$buildable_phid])) {
82
unset($page[$key]);
83
continue;
84
}
85
$buildable->attachBuildableObject($buildables[$buildable_phid]);
86
}
87
88
return $page;
89
}
90
91
protected function didFilterPage(array $page) {
92
if ($this->needContainerObjects) {
93
$container_phids = array_filter(mpull($page, 'getContainerPHID'));
94
95
if ($container_phids) {
96
$containers = id(new PhabricatorObjectQuery())
97
->setViewer($this->getViewer())
98
->withPHIDs($container_phids)
99
->setParentQuery($this)
100
->execute();
101
$containers = mpull($containers, null, 'getPHID');
102
} else {
103
$containers = array();
104
}
105
106
foreach ($page as $key => $buildable) {
107
$container_phid = $buildable->getContainerPHID();
108
$buildable->attachContainerObject(idx($containers, $container_phid));
109
}
110
}
111
112
if ($this->needBuilds || $this->needTargets) {
113
$builds = id(new HarbormasterBuildQuery())
114
->setViewer($this->getViewer())
115
->setParentQuery($this)
116
->withBuildablePHIDs(mpull($page, 'getPHID'))
117
->needBuildTargets($this->needTargets)
118
->execute();
119
$builds = mgroup($builds, 'getBuildablePHID');
120
foreach ($page as $key => $buildable) {
121
$buildable->attachBuilds(idx($builds, $buildable->getPHID(), array()));
122
}
123
}
124
125
return $page;
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 (%Ld)',
135
$this->ids);
136
}
137
138
if ($this->phids !== null) {
139
$where[] = qsprintf(
140
$conn,
141
'phid IN (%Ls)',
142
$this->phids);
143
}
144
145
if ($this->buildablePHIDs !== null) {
146
$where[] = qsprintf(
147
$conn,
148
'buildablePHID IN (%Ls)',
149
$this->buildablePHIDs);
150
}
151
152
if ($this->containerPHIDs !== null) {
153
$where[] = qsprintf(
154
$conn,
155
'containerPHID in (%Ls)',
156
$this->containerPHIDs);
157
}
158
159
if ($this->statuses !== null) {
160
$where[] = qsprintf(
161
$conn,
162
'buildableStatus in (%Ls)',
163
$this->statuses);
164
}
165
166
if ($this->manualBuildables !== null) {
167
$where[] = qsprintf(
168
$conn,
169
'isManualBuildable = %d',
170
(int)$this->manualBuildables);
171
}
172
173
return $where;
174
}
175
176
public function getQueryApplicationClass() {
177
return 'PhabricatorHarbormasterApplication';
178
}
179
180
}
181
182