Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/query/HarbormasterBuildArtifactQuery.php
12256 views
1
<?php
2
3
final class HarbormasterBuildArtifactQuery
4
extends PhabricatorCursorPagedPolicyAwareQuery {
5
6
private $ids;
7
private $buildTargetPHIDs;
8
private $artifactTypes;
9
private $artifactIndexes;
10
private $keyBuildPHID;
11
private $keyBuildGeneration;
12
private $isReleased;
13
14
public function withIDs(array $ids) {
15
$this->ids = $ids;
16
return $this;
17
}
18
19
public function withBuildTargetPHIDs(array $build_target_phids) {
20
$this->buildTargetPHIDs = $build_target_phids;
21
return $this;
22
}
23
24
public function withArtifactTypes(array $artifact_types) {
25
$this->artifactTypes = $artifact_types;
26
return $this;
27
}
28
29
public function withArtifactIndexes(array $artifact_indexes) {
30
$this->artifactIndexes = $artifact_indexes;
31
return $this;
32
}
33
34
public function withIsReleased($released) {
35
$this->isReleased = $released;
36
return $this;
37
}
38
39
public function newResultObject() {
40
return new HarbormasterBuildArtifact();
41
}
42
43
protected function willFilterPage(array $page) {
44
$build_targets = array();
45
46
$build_target_phids = array_filter(mpull($page, 'getBuildTargetPHID'));
47
if ($build_target_phids) {
48
$build_targets = id(new HarbormasterBuildTargetQuery())
49
->setViewer($this->getViewer())
50
->withPHIDs($build_target_phids)
51
->setParentQuery($this)
52
->execute();
53
$build_targets = mpull($build_targets, null, 'getPHID');
54
}
55
56
foreach ($page as $key => $build_log) {
57
$build_target_phid = $build_log->getBuildTargetPHID();
58
if (empty($build_targets[$build_target_phid])) {
59
unset($page[$key]);
60
continue;
61
}
62
$build_log->attachBuildTarget($build_targets[$build_target_phid]);
63
}
64
65
return $page;
66
}
67
68
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
69
$where = parent::buildWhereClauseParts($conn);
70
71
if ($this->ids !== null) {
72
$where[] = qsprintf(
73
$conn,
74
'id IN (%Ld)',
75
$this->ids);
76
}
77
78
if ($this->buildTargetPHIDs !== null) {
79
$where[] = qsprintf(
80
$conn,
81
'buildTargetPHID IN (%Ls)',
82
$this->buildTargetPHIDs);
83
}
84
85
if ($this->artifactTypes !== null) {
86
$where[] = qsprintf(
87
$conn,
88
'artifactType in (%Ls)',
89
$this->artifactTypes);
90
}
91
92
if ($this->artifactIndexes !== null) {
93
$where[] = qsprintf(
94
$conn,
95
'artifactIndex IN (%Ls)',
96
$this->artifactIndexes);
97
}
98
99
if ($this->isReleased !== null) {
100
$where[] = qsprintf(
101
$conn,
102
'isReleased = %d',
103
(int)$this->isReleased);
104
}
105
106
return $where;
107
}
108
109
public function getQueryApplicationClass() {
110
return 'PhabricatorHarbormasterApplication';
111
}
112
113
}
114
115