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