Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / query / PhabricatorRepositorySyncEventQuery.php
blobcc568ef8e1ca406203d36090dd775a066b00e94c
1 <?php
3 final class PhabricatorRepositorySyncEventQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $phids;
8 private $repositoryPHIDs;
9 private $epochMin;
10 private $epochMax;
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 withEpochBetween($min, $max) {
28 $this->epochMin = $min;
29 $this->epochMax = $max;
30 return $this;
33 public function newResultObject() {
34 return new PhabricatorRepositorySyncEvent();
37 protected function willFilterPage(array $events) {
38 $repository_phids = mpull($events, 'getRepositoryPHID');
39 $repository_phids = array_filter($repository_phids);
41 if ($repository_phids) {
42 $repositories = id(new PhabricatorRepositoryQuery())
43 ->setViewer($this->getViewer())
44 ->withPHIDs($repository_phids)
45 ->execute();
46 $repositories = mpull($repositories, null, 'getPHID');
47 } else {
48 $repositories = array();
51 foreach ($events as $key => $event) {
52 $phid = $event->getRepositoryPHID();
54 if (empty($repositories[$phid])) {
55 unset($events[$key]);
56 $this->didRejectResult($event);
57 continue;
60 $event->attachRepository($repositories[$phid]);
63 return $events;
66 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
67 $where = parent::buildWhereClauseParts($conn);
69 if ($this->ids !== null) {
70 $where[] = qsprintf(
71 $conn,
72 'id IN (%Ld)',
73 $this->ids);
76 if ($this->phids !== null) {
77 $where[] = qsprintf(
78 $conn,
79 'phid IN (%Ls)',
80 $this->phids);
83 if ($this->repositoryPHIDs !== null) {
84 $where[] = qsprintf(
85 $conn,
86 'repositoryPHID IN (%Ls)',
87 $this->repositoryPHIDs);
90 if ($this->epochMin !== null) {
91 $where[] = qsprintf(
92 $conn,
93 'epoch >= %d',
94 $this->epochMin);
97 if ($this->epochMax !== null) {
98 $where[] = qsprintf(
99 $conn,
100 'epoch <= %d',
101 $this->epochMax);
104 return $where;
107 public function getQueryApplicationClass() {
108 return 'PhabricatorDiffusionApplication';