@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 81 lines 1.7 kB view raw
1<?php 2 3/** 4 * @extends DrydockQuery<DrydockCommand> 5 */ 6final class DrydockCommandQuery extends DrydockQuery { 7 8 private $ids; 9 private $targetPHIDs; 10 private $consumed; 11 12 public function withIDs(array $ids) { 13 $this->ids = $ids; 14 return $this; 15 } 16 17 public function withTargetPHIDs(array $phids) { 18 $this->targetPHIDs = $phids; 19 return $this; 20 } 21 22 public function withConsumed($consumed) { 23 $this->consumed = $consumed; 24 return $this; 25 } 26 27 public function newResultObject() { 28 return new DrydockCommand(); 29 } 30 31 protected function willFilterPage(array $commands) { 32 $target_phids = mpull($commands, 'getTargetPHID'); 33 34 $targets = id(new PhabricatorObjectQuery()) 35 ->setViewer($this->getViewer()) 36 ->setParentQuery($this) 37 ->withPHIDs($target_phids) 38 ->execute(); 39 $targets = mpull($targets, null, 'getPHID'); 40 41 foreach ($commands as $key => $command) { 42 $target = idx($targets, $command->getTargetPHID()); 43 if (!$target) { 44 $this->didRejectResult($command); 45 unset($commands[$key]); 46 continue; 47 } 48 $command->attachCommandTarget($target); 49 } 50 51 return $commands; 52 } 53 54 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 55 $where = parent::buildWhereClauseParts($conn); 56 57 if ($this->ids !== null) { 58 $where[] = qsprintf( 59 $conn, 60 'id IN (%Ld)', 61 $this->ids); 62 } 63 64 if ($this->targetPHIDs !== null) { 65 $where[] = qsprintf( 66 $conn, 67 'targetPHID IN (%Ls)', 68 $this->targetPHIDs); 69 } 70 71 if ($this->consumed !== null) { 72 $where[] = qsprintf( 73 $conn, 74 'isConsumed = %d', 75 (int)$this->consumed); 76 } 77 78 return $where; 79 } 80 81}