Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / query / PhabricatorRepositoryPullEventQuery.php
blob8d4f14e0cec57a4722b6177aed5cb6373684f8e5
1 <?php
3 final class PhabricatorRepositoryPullEventQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $phids;
8 private $repositoryPHIDs;
9 private $pullerPHIDs;
10 private $epochMin;
11 private $epochMax;
13 public function withIDs(array $ids) {
14 $this->ids = $ids;
15 return $this;
18 public function withPHIDs(array $phids) {
19 $this->phids = $phids;
20 return $this;
23 public function withRepositoryPHIDs(array $repository_phids) {
24 $this->repositoryPHIDs = $repository_phids;
25 return $this;
28 public function withPullerPHIDs(array $puller_phids) {
29 $this->pullerPHIDs = $puller_phids;
30 return $this;
33 public function withEpochBetween($min, $max) {
34 $this->epochMin = $min;
35 $this->epochMax = $max;
36 return $this;
39 public function newResultObject() {
40 return new PhabricatorRepositoryPullEvent();
43 protected function willFilterPage(array $events) {
44 // If a pull targets an invalid repository or fails before authenticating,
45 // it may not have an associated repository.
47 $repository_phids = mpull($events, 'getRepositoryPHID');
48 $repository_phids = array_filter($repository_phids);
50 if ($repository_phids) {
51 $repositories = id(new PhabricatorRepositoryQuery())
52 ->setViewer($this->getViewer())
53 ->withPHIDs($repository_phids)
54 ->execute();
55 $repositories = mpull($repositories, null, 'getPHID');
56 } else {
57 $repositories = array();
60 foreach ($events as $key => $event) {
61 $phid = $event->getRepositoryPHID();
62 if (!$phid) {
63 $event->attachRepository(null);
64 continue;
67 if (empty($repositories[$phid])) {
68 unset($events[$key]);
69 $this->didRejectResult($event);
70 continue;
73 $event->attachRepository($repositories[$phid]);
76 return $events;
79 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
80 $where = parent::buildWhereClauseParts($conn);
82 if ($this->ids !== null) {
83 $where[] = qsprintf(
84 $conn,
85 'id IN (%Ld)',
86 $this->ids);
89 if ($this->phids !== null) {
90 $where[] = qsprintf(
91 $conn,
92 'phid IN (%Ls)',
93 $this->phids);
96 if ($this->repositoryPHIDs !== null) {
97 $where[] = qsprintf(
98 $conn,
99 'repositoryPHID IN (%Ls)',
100 $this->repositoryPHIDs);
103 if ($this->pullerPHIDs !== null) {
104 $where[] = qsprintf(
105 $conn,
106 'pullerPHID in (%Ls)',
107 $this->pullerPHIDs);
110 if ($this->epochMin !== null) {
111 $where[] = qsprintf(
112 $conn,
113 'epoch >= %d',
114 $this->epochMin);
117 if ($this->epochMax !== null) {
118 $where[] = qsprintf(
119 $conn,
120 'epoch <= %d',
121 $this->epochMax);
124 return $where;
127 public function getQueryApplicationClass() {
128 return 'PhabricatorDiffusionApplication';