Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / drydock / query / DrydockRepositoryOperationQuery.php
blob6ef5d1b29528613d65d46aaeb50db64aa260d89a
1 <?php
3 final class DrydockRepositoryOperationQuery extends DrydockQuery {
5 private $ids;
6 private $phids;
7 private $objectPHIDs;
8 private $repositoryPHIDs;
9 private $operationStates;
10 private $operationTypes;
11 private $isDismissed;
12 private $authorPHIDs;
14 public function withIDs(array $ids) {
15 $this->ids = $ids;
16 return $this;
19 public function withPHIDs(array $phids) {
20 $this->phids = $phids;
21 return $this;
24 public function withObjectPHIDs(array $object_phids) {
25 $this->objectPHIDs = $object_phids;
26 return $this;
29 public function withRepositoryPHIDs(array $repository_phids) {
30 $this->repositoryPHIDs = $repository_phids;
31 return $this;
34 public function withOperationStates(array $states) {
35 $this->operationStates = $states;
36 return $this;
39 public function withOperationTypes(array $types) {
40 $this->operationTypes = $types;
41 return $this;
44 public function withIsDismissed($dismissed) {
45 $this->isDismissed = $dismissed;
46 return $this;
49 public function withAuthorPHIDs(array $phids) {
50 $this->authorPHIDs = $phids;
51 return $this;
54 public function newResultObject() {
55 return new DrydockRepositoryOperation();
58 protected function willFilterPage(array $operations) {
59 $implementations = DrydockRepositoryOperationType::getAllOperationTypes();
61 $viewer = $this->getViewer();
63 foreach ($operations as $key => $operation) {
64 $impl = idx($implementations, $operation->getOperationType());
65 if (!$impl) {
66 $this->didRejectResult($operation);
67 unset($operations[$key]);
68 continue;
70 $impl = id(clone $impl)
71 ->setViewer($viewer)
72 ->setOperation($operation);
74 $operation->attachImplementation($impl);
77 $repository_phids = mpull($operations, 'getRepositoryPHID');
78 if ($repository_phids) {
79 $repositories = id(new PhabricatorRepositoryQuery())
80 ->setViewer($this->getViewer())
81 ->setParentQuery($this)
82 ->withPHIDs($repository_phids)
83 ->execute();
84 $repositories = mpull($repositories, null, 'getPHID');
85 } else {
86 $repositories = array();
89 foreach ($operations as $key => $operation) {
90 $repository = idx($repositories, $operation->getRepositoryPHID());
91 if (!$repository) {
92 $this->didRejectResult($operation);
93 unset($operations[$key]);
94 continue;
96 $operation->attachRepository($repository);
99 return $operations;
102 protected function didFilterPage(array $operations) {
103 $object_phids = mpull($operations, 'getObjectPHID');
104 if ($object_phids) {
105 $objects = id(new PhabricatorObjectQuery())
106 ->setViewer($this->getViewer())
107 ->setParentQuery($this)
108 ->withPHIDs($object_phids)
109 ->execute();
110 $objects = mpull($objects, null, 'getPHID');
111 } else {
112 $objects = array();
115 foreach ($operations as $key => $operation) {
116 $object = idx($objects, $operation->getObjectPHID());
117 $operation->attachObject($object);
120 return $operations;
123 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
124 $where = parent::buildWhereClauseParts($conn);
126 if ($this->ids !== null) {
127 $where[] = qsprintf(
128 $conn,
129 'id IN (%Ld)',
130 $this->ids);
133 if ($this->phids !== null) {
134 $where[] = qsprintf(
135 $conn,
136 'phid IN (%Ls)',
137 $this->phids);
140 if ($this->objectPHIDs !== null) {
141 $where[] = qsprintf(
142 $conn,
143 'objectPHID IN (%Ls)',
144 $this->objectPHIDs);
147 if ($this->repositoryPHIDs !== null) {
148 $where[] = qsprintf(
149 $conn,
150 'repositoryPHID IN (%Ls)',
151 $this->repositoryPHIDs);
154 if ($this->operationStates !== null) {
155 $where[] = qsprintf(
156 $conn,
157 'operationState IN (%Ls)',
158 $this->operationStates);
161 if ($this->operationTypes !== null) {
162 $where[] = qsprintf(
163 $conn,
164 'operationType IN (%Ls)',
165 $this->operationTypes);
168 if ($this->isDismissed !== null) {
169 $where[] = qsprintf(
170 $conn,
171 'isDismissed = %d',
172 (int)$this->isDismissed);
175 if ($this->authorPHIDs !== null) {
176 $where[] = qsprintf(
177 $conn,
178 'authorPHID IN (%Ls)',
179 $this->authorPHIDs);
182 return $where;