@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3/**
4 * @extends PhabricatorCursorPagedPolicyAwareQuery<PhabricatorRepositoryPullEvent>
5 */
6final class PhabricatorRepositoryPullEventQuery
7 extends PhabricatorCursorPagedPolicyAwareQuery {
8
9 private $ids;
10 private $phids;
11 private $repositoryPHIDs;
12 private $pullerPHIDs;
13 private $epochMin;
14 private $epochMax;
15
16 public function withIDs(array $ids) {
17 $this->ids = $ids;
18 return $this;
19 }
20
21 public function withPHIDs(array $phids) {
22 $this->phids = $phids;
23 return $this;
24 }
25
26 public function withRepositoryPHIDs(array $repository_phids) {
27 $this->repositoryPHIDs = $repository_phids;
28 return $this;
29 }
30
31 public function withPullerPHIDs(array $puller_phids) {
32 $this->pullerPHIDs = $puller_phids;
33 return $this;
34 }
35
36 public function withEpochBetween($min, $max) {
37 $this->epochMin = $min;
38 $this->epochMax = $max;
39 return $this;
40 }
41
42 public function newResultObject() {
43 return new PhabricatorRepositoryPullEvent();
44 }
45
46 protected function willFilterPage(array $events) {
47 // If a pull targets an invalid repository or fails before authenticating,
48 // it may not have an associated repository.
49
50 $repository_phids = mpull($events, 'getRepositoryPHID');
51 $repository_phids = array_filter($repository_phids);
52
53 if ($repository_phids) {
54 $repositories = id(new PhabricatorRepositoryQuery())
55 ->setViewer($this->getViewer())
56 ->withPHIDs($repository_phids)
57 ->execute();
58 $repositories = mpull($repositories, null, 'getPHID');
59 } else {
60 $repositories = array();
61 }
62
63 foreach ($events as $key => $event) {
64 $phid = $event->getRepositoryPHID();
65 if (!$phid) {
66 $event->attachRepository(null);
67 continue;
68 }
69
70 if (empty($repositories[$phid])) {
71 unset($events[$key]);
72 $this->didRejectResult($event);
73 continue;
74 }
75
76 $event->attachRepository($repositories[$phid]);
77 }
78
79 return $events;
80 }
81
82 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
83 $where = parent::buildWhereClauseParts($conn);
84
85 if ($this->ids !== null) {
86 $where[] = qsprintf(
87 $conn,
88 'id IN (%Ld)',
89 $this->ids);
90 }
91
92 if ($this->phids !== null) {
93 $where[] = qsprintf(
94 $conn,
95 'phid IN (%Ls)',
96 $this->phids);
97 }
98
99 if ($this->repositoryPHIDs !== null) {
100 $where[] = qsprintf(
101 $conn,
102 'repositoryPHID IN (%Ls)',
103 $this->repositoryPHIDs);
104 }
105
106 if ($this->pullerPHIDs !== null) {
107 $where[] = qsprintf(
108 $conn,
109 'pullerPHID in (%Ls)',
110 $this->pullerPHIDs);
111 }
112
113 if ($this->epochMin !== null) {
114 $where[] = qsprintf(
115 $conn,
116 'epoch >= %d',
117 $this->epochMin);
118 }
119
120 if ($this->epochMax !== null) {
121 $where[] = qsprintf(
122 $conn,
123 'epoch <= %d',
124 $this->epochMax);
125 }
126
127 return $where;
128 }
129
130 public function getQueryApplicationClass() {
131 return PhabricatorDiffusionApplication::class;
132 }
133
134}