Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/drydock/query/DrydockRepositoryOperationQuery.php
12256 views
1
<?php
2
3
final class DrydockRepositoryOperationQuery extends DrydockQuery {
4
5
private $ids;
6
private $phids;
7
private $objectPHIDs;
8
private $repositoryPHIDs;
9
private $operationStates;
10
private $operationTypes;
11
private $isDismissed;
12
private $authorPHIDs;
13
14
public function withIDs(array $ids) {
15
$this->ids = $ids;
16
return $this;
17
}
18
19
public function withPHIDs(array $phids) {
20
$this->phids = $phids;
21
return $this;
22
}
23
24
public function withObjectPHIDs(array $object_phids) {
25
$this->objectPHIDs = $object_phids;
26
return $this;
27
}
28
29
public function withRepositoryPHIDs(array $repository_phids) {
30
$this->repositoryPHIDs = $repository_phids;
31
return $this;
32
}
33
34
public function withOperationStates(array $states) {
35
$this->operationStates = $states;
36
return $this;
37
}
38
39
public function withOperationTypes(array $types) {
40
$this->operationTypes = $types;
41
return $this;
42
}
43
44
public function withIsDismissed($dismissed) {
45
$this->isDismissed = $dismissed;
46
return $this;
47
}
48
49
public function withAuthorPHIDs(array $phids) {
50
$this->authorPHIDs = $phids;
51
return $this;
52
}
53
54
public function newResultObject() {
55
return new DrydockRepositoryOperation();
56
}
57
58
protected function willFilterPage(array $operations) {
59
$implementations = DrydockRepositoryOperationType::getAllOperationTypes();
60
61
$viewer = $this->getViewer();
62
63
foreach ($operations as $key => $operation) {
64
$impl = idx($implementations, $operation->getOperationType());
65
if (!$impl) {
66
$this->didRejectResult($operation);
67
unset($operations[$key]);
68
continue;
69
}
70
$impl = id(clone $impl)
71
->setViewer($viewer)
72
->setOperation($operation);
73
74
$operation->attachImplementation($impl);
75
}
76
77
$repository_phids = mpull($operations, 'getRepositoryPHID');
78
if ($repository_phids) {
79
$repositories = id(new PhabricatorRepositoryQuery())
80
->setViewer($this->getViewer())
81
->setParentQuery($this)
82
->withPHIDs($repository_phids)
83
->execute();
84
$repositories = mpull($repositories, null, 'getPHID');
85
} else {
86
$repositories = array();
87
}
88
89
foreach ($operations as $key => $operation) {
90
$repository = idx($repositories, $operation->getRepositoryPHID());
91
if (!$repository) {
92
$this->didRejectResult($operation);
93
unset($operations[$key]);
94
continue;
95
}
96
$operation->attachRepository($repository);
97
}
98
99
return $operations;
100
}
101
102
protected function didFilterPage(array $operations) {
103
$object_phids = mpull($operations, 'getObjectPHID');
104
if ($object_phids) {
105
$objects = id(new PhabricatorObjectQuery())
106
->setViewer($this->getViewer())
107
->setParentQuery($this)
108
->withPHIDs($object_phids)
109
->execute();
110
$objects = mpull($objects, null, 'getPHID');
111
} else {
112
$objects = array();
113
}
114
115
foreach ($operations as $key => $operation) {
116
$object = idx($objects, $operation->getObjectPHID());
117
$operation->attachObject($object);
118
}
119
120
return $operations;
121
}
122
123
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
124
$where = parent::buildWhereClauseParts($conn);
125
126
if ($this->ids !== null) {
127
$where[] = qsprintf(
128
$conn,
129
'id IN (%Ld)',
130
$this->ids);
131
}
132
133
if ($this->phids !== null) {
134
$where[] = qsprintf(
135
$conn,
136
'phid IN (%Ls)',
137
$this->phids);
138
}
139
140
if ($this->objectPHIDs !== null) {
141
$where[] = qsprintf(
142
$conn,
143
'objectPHID IN (%Ls)',
144
$this->objectPHIDs);
145
}
146
147
if ($this->repositoryPHIDs !== null) {
148
$where[] = qsprintf(
149
$conn,
150
'repositoryPHID IN (%Ls)',
151
$this->repositoryPHIDs);
152
}
153
154
if ($this->operationStates !== null) {
155
$where[] = qsprintf(
156
$conn,
157
'operationState IN (%Ls)',
158
$this->operationStates);
159
}
160
161
if ($this->operationTypes !== null) {
162
$where[] = qsprintf(
163
$conn,
164
'operationType IN (%Ls)',
165
$this->operationTypes);
166
}
167
168
if ($this->isDismissed !== null) {
169
$where[] = qsprintf(
170
$conn,
171
'isDismissed = %d',
172
(int)$this->isDismissed);
173
}
174
175
if ($this->authorPHIDs !== null) {
176
$where[] = qsprintf(
177
$conn,
178
'authorPHID IN (%Ls)',
179
$this->authorPHIDs);
180
}
181
182
return $where;
183
}
184
185
}
186
187