Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/drydock/query/DrydockCommandQuery.php
12256 views
1
<?php
2
3
final class DrydockCommandQuery extends DrydockQuery {
4
5
private $ids;
6
private $targetPHIDs;
7
private $consumed;
8
9
public function withIDs(array $ids) {
10
$this->ids = $ids;
11
return $this;
12
}
13
14
public function withTargetPHIDs(array $phids) {
15
$this->targetPHIDs = $phids;
16
return $this;
17
}
18
19
public function withConsumed($consumed) {
20
$this->consumed = $consumed;
21
return $this;
22
}
23
24
public function newResultObject() {
25
return new DrydockCommand();
26
}
27
28
protected function willFilterPage(array $commands) {
29
$target_phids = mpull($commands, 'getTargetPHID');
30
31
$targets = id(new PhabricatorObjectQuery())
32
->setViewer($this->getViewer())
33
->setParentQuery($this)
34
->withPHIDs($target_phids)
35
->execute();
36
$targets = mpull($targets, null, 'getPHID');
37
38
foreach ($commands as $key => $command) {
39
$target = idx($targets, $command->getTargetPHID());
40
if (!$target) {
41
$this->didRejectResult($command);
42
unset($commands[$key]);
43
continue;
44
}
45
$command->attachCommandTarget($target);
46
}
47
48
return $commands;
49
}
50
51
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
52
$where = parent::buildWhereClauseParts($conn);
53
54
if ($this->ids !== null) {
55
$where[] = qsprintf(
56
$conn,
57
'id IN (%Ld)',
58
$this->ids);
59
}
60
61
if ($this->targetPHIDs !== null) {
62
$where[] = qsprintf(
63
$conn,
64
'targetPHID IN (%Ls)',
65
$this->targetPHIDs);
66
}
67
68
if ($this->consumed !== null) {
69
$where[] = qsprintf(
70
$conn,
71
'isConsumed = %d',
72
(int)$this->consumed);
73
}
74
75
return $where;
76
}
77
78
}
79
80