Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / query / PhabricatorRepositoryPushEventQuery.php
blobd1ce937b860de10e90921f9a9ac5646d5969f6ed
1 <?php
3 final class PhabricatorRepositoryPushEventQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $phids;
8 private $repositoryPHIDs;
9 private $pusherPHIDs;
10 private $needLogs;
12 public function withIDs(array $ids) {
13 $this->ids = $ids;
14 return $this;
17 public function withPHIDs(array $phids) {
18 $this->phids = $phids;
19 return $this;
22 public function withRepositoryPHIDs(array $repository_phids) {
23 $this->repositoryPHIDs = $repository_phids;
24 return $this;
27 public function withPusherPHIDs(array $pusher_phids) {
28 $this->pusherPHIDs = $pusher_phids;
29 return $this;
32 public function needLogs($need_logs) {
33 $this->needLogs = $need_logs;
34 return $this;
37 public function newResultObject() {
38 return new PhabricatorRepositoryPushEvent();
41 protected function willFilterPage(array $events) {
42 $repository_phids = mpull($events, 'getRepositoryPHID');
43 $repositories = id(new PhabricatorRepositoryQuery())
44 ->setViewer($this->getViewer())
45 ->withPHIDs($repository_phids)
46 ->execute();
47 $repositories = mpull($repositories, null, 'getPHID');
49 foreach ($events as $key => $event) {
50 $phid = $event->getRepositoryPHID();
51 if (empty($repositories[$phid])) {
52 unset($events[$key]);
53 continue;
55 $event->attachRepository($repositories[$phid]);
58 return $events;
61 protected function didFilterPage(array $events) {
62 $phids = mpull($events, 'getPHID');
64 if ($this->needLogs) {
65 $logs = id(new PhabricatorRepositoryPushLogQuery())
66 ->setParentQuery($this)
67 ->setViewer($this->getViewer())
68 ->withPushEventPHIDs($phids)
69 ->execute();
70 $logs = mgroup($logs, 'getPushEventPHID');
71 foreach ($events as $key => $event) {
72 $event_logs = idx($logs, $event->getPHID(), array());
73 $event->attachLogs($event_logs);
77 return $events;
80 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
81 $where = parent::buildWhereClauseParts($conn);
83 if ($this->ids !== null) {
84 $where[] = qsprintf(
85 $conn,
86 'id IN (%Ld)',
87 $this->ids);
90 if ($this->phids !== null) {
91 $where[] = qsprintf(
92 $conn,
93 'phid IN (%Ls)',
94 $this->phids);
97 if ($this->repositoryPHIDs !== null) {
98 $where[] = qsprintf(
99 $conn,
100 'repositoryPHID IN (%Ls)',
101 $this->repositoryPHIDs);
104 if ($this->pusherPHIDs !== null) {
105 $where[] = qsprintf(
106 $conn,
107 'pusherPHID in (%Ls)',
108 $this->pusherPHIDs);
111 return $where;
114 public function getQueryApplicationClass() {
115 return 'PhabricatorDiffusionApplication';