Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/query/HarbormasterBuildStepQuery.php
12256 views
1
<?php
2
3
final class HarbormasterBuildStepQuery
4
extends PhabricatorCursorPagedPolicyAwareQuery {
5
6
private $ids;
7
private $phids;
8
private $buildPlanPHIDs;
9
10
public function withIDs(array $ids) {
11
$this->ids = $ids;
12
return $this;
13
}
14
15
public function withPHIDs(array $phids) {
16
$this->phids = $phids;
17
return $this;
18
}
19
20
public function withBuildPlanPHIDs(array $phids) {
21
$this->buildPlanPHIDs = $phids;
22
return $this;
23
}
24
25
public function newResultObject() {
26
return new HarbormasterBuildStep();
27
}
28
29
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
30
$where = parent::buildWhereClauseParts($conn);
31
32
if ($this->ids !== null) {
33
$where[] = qsprintf(
34
$conn,
35
'id IN (%Ld)',
36
$this->ids);
37
}
38
39
if ($this->phids !== null) {
40
$where[] = qsprintf(
41
$conn,
42
'phid in (%Ls)',
43
$this->phids);
44
}
45
46
if ($this->buildPlanPHIDs !== null) {
47
$where[] = qsprintf(
48
$conn,
49
'buildPlanPHID in (%Ls)',
50
$this->buildPlanPHIDs);
51
}
52
53
return $where;
54
}
55
56
protected function willFilterPage(array $page) {
57
$plans = array();
58
59
$buildplan_phids = array_filter(mpull($page, 'getBuildPlanPHID'));
60
if ($buildplan_phids) {
61
$plans = id(new PhabricatorObjectQuery())
62
->setViewer($this->getViewer())
63
->withPHIDs($buildplan_phids)
64
->setParentQuery($this)
65
->execute();
66
$plans = mpull($plans, null, 'getPHID');
67
}
68
69
foreach ($page as $key => $build) {
70
$buildable_phid = $build->getBuildPlanPHID();
71
if (empty($plans[$buildable_phid])) {
72
unset($page[$key]);
73
continue;
74
}
75
$build->attachBuildPlan($plans[$buildable_phid]);
76
}
77
78
return $page;
79
}
80
81
public function getQueryApplicationClass() {
82
return 'PhabricatorHarbormasterApplication';
83
}
84
85
}
86
87