3 final class DrydockResourceQuery
extends DrydockQuery
{
9 private $blueprintPHIDs;
10 private $datasourceQuery;
11 private $needUnconsumedCommands;
13 public function withIDs(array $ids) {
18 public function withPHIDs(array $phids) {
19 $this->phids
= $phids;
23 public function withTypes(array $types) {
24 $this->types
= $types;
28 public function withStatuses(array $statuses) {
29 $this->statuses
= $statuses;
33 public function withBlueprintPHIDs(array $blueprint_phids) {
34 $this->blueprintPHIDs
= $blueprint_phids;
38 public function withDatasourceQuery($query) {
39 $this->datasourceQuery
= $query;
43 public function needUnconsumedCommands($need) {
44 $this->needUnconsumedCommands
= $need;
48 public function newResultObject() {
49 return new DrydockResource();
52 protected function willFilterPage(array $resources) {
53 $blueprint_phids = mpull($resources, 'getBlueprintPHID');
55 $blueprints = id(new DrydockBlueprintQuery())
56 ->setViewer($this->getViewer())
57 ->withPHIDs($blueprint_phids)
59 $blueprints = mpull($blueprints, null, 'getPHID');
61 foreach ($resources as $key => $resource) {
62 $blueprint = idx($blueprints, $resource->getBlueprintPHID());
64 $this->didRejectResult($resource);
65 unset($resources[$key]);
68 $resource->attachBlueprint($blueprint);
74 protected function didFilterPage(array $resources) {
75 if ($this->needUnconsumedCommands
) {
76 $commands = id(new DrydockCommandQuery())
77 ->setViewer($this->getViewer())
78 ->setParentQuery($this)
79 ->withTargetPHIDs(mpull($resources, 'getPHID'))
82 $commands = mgroup($commands, 'getTargetPHID');
84 foreach ($resources as $resource) {
85 $list = idx($commands, $resource->getPHID(), array());
86 $resource->attachUnconsumedCommands($list);
93 protected function buildWhereClauseParts(AphrontDatabaseConnection
$conn) {
94 $where = parent
::buildWhereClauseParts($conn);
96 if ($this->ids
!== null) {
99 'resource.id IN (%Ld)',
103 if ($this->phids
!== null) {
106 'resource.phid IN (%Ls)',
110 if ($this->types
!== null) {
113 'resource.type IN (%Ls)',
117 if ($this->statuses
!== null) {
120 'resource.status IN (%Ls)',
124 if ($this->blueprintPHIDs
!== null) {
127 'resource.blueprintPHID IN (%Ls)',
128 $this->blueprintPHIDs
);
131 if ($this->datasourceQuery
!== null) {
134 'resource.name LIKE %>',
135 $this->datasourceQuery
);
141 protected function getPrimaryTableAlias() {