Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / drydock / query / DrydockCommandQuery.php
blobfef6170ec95bfc53d065ddabe427254954818c75
1 <?php
3 final class DrydockCommandQuery extends DrydockQuery {
5 private $ids;
6 private $targetPHIDs;
7 private $consumed;
9 public function withIDs(array $ids) {
10 $this->ids = $ids;
11 return $this;
14 public function withTargetPHIDs(array $phids) {
15 $this->targetPHIDs = $phids;
16 return $this;
19 public function withConsumed($consumed) {
20 $this->consumed = $consumed;
21 return $this;
24 public function newResultObject() {
25 return new DrydockCommand();
28 protected function willFilterPage(array $commands) {
29 $target_phids = mpull($commands, 'getTargetPHID');
31 $targets = id(new PhabricatorObjectQuery())
32 ->setViewer($this->getViewer())
33 ->setParentQuery($this)
34 ->withPHIDs($target_phids)
35 ->execute();
36 $targets = mpull($targets, null, 'getPHID');
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;
45 $command->attachCommandTarget($target);
48 return $commands;
51 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
52 $where = parent::buildWhereClauseParts($conn);
54 if ($this->ids !== null) {
55 $where[] = qsprintf(
56 $conn,
57 'id IN (%Ld)',
58 $this->ids);
61 if ($this->targetPHIDs !== null) {
62 $where[] = qsprintf(
63 $conn,
64 'targetPHID IN (%Ls)',
65 $this->targetPHIDs);
68 if ($this->consumed !== null) {
69 $where[] = qsprintf(
70 $conn,
71 'isConsumed = %d',
72 (int)$this->consumed);
75 return $where;