Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / harbormaster / query / HarbormasterBuildMessageQuery.php
blob393ca0a493e506547c0e3b77fd9235a0651245af
1 <?php
3 final class HarbormasterBuildMessageQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $receiverPHIDs;
8 private $consumed;
10 public function withIDs(array $ids) {
11 $this->ids = $ids;
12 return $this;
15 public function withReceiverPHIDs(array $phids) {
16 $this->receiverPHIDs = $phids;
17 return $this;
20 public function withConsumed($consumed) {
21 $this->consumed = $consumed;
22 return $this;
25 public function newResultObject() {
26 return new HarbormasterBuildMessage();
29 protected function willFilterPage(array $page) {
30 $receiver_phids = array_filter(mpull($page, 'getReceiverPHID'));
31 if ($receiver_phids) {
32 $receivers = id(new PhabricatorObjectQuery())
33 ->setViewer($this->getViewer())
34 ->withPHIDs($receiver_phids)
35 ->setParentQuery($this)
36 ->execute();
37 $receivers = mpull($receivers, null, 'getPHID');
38 } else {
39 $receivers = array();
42 foreach ($page as $key => $message) {
43 $receiver_phid = $message->getReceiverPHID();
45 if (empty($receivers[$receiver_phid])) {
46 unset($page[$key]);
47 $this->didRejectResult($message);
48 continue;
51 $message->attachReceiver($receivers[$receiver_phid]);
54 return $page;
57 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
58 $where = parent::buildWhereClauseParts($conn);
60 if ($this->ids !== null) {
61 $where[] = qsprintf(
62 $conn,
63 'id IN (%Ld)',
64 $this->ids);
67 if ($this->receiverPHIDs !== null) {
68 $where[] = qsprintf(
69 $conn,
70 'receiverPHID IN (%Ls)',
71 $this->receiverPHIDs);
74 if ($this->consumed !== null) {
75 $where[] = qsprintf(
76 $conn,
77 'isConsumed = %d',
78 (int)$this->consumed);
81 return $where;
84 public function getQueryApplicationClass() {
85 return 'PhabricatorHarbormasterApplication';