Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / query / PhabricatorRepositoryPushLogQuery.php
blob16897a1e4bf17077caa177b35b8d058a43ca5aaf
1 <?php
3 final class PhabricatorRepositoryPushLogQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $phids;
8 private $repositoryPHIDs;
9 private $pusherPHIDs;
10 private $refTypes;
11 private $newRefs;
12 private $pushEventPHIDs;
13 private $epochMin;
14 private $epochMax;
15 private $blockingHeraldRulePHIDs;
17 public function withIDs(array $ids) {
18 $this->ids = $ids;
19 return $this;
22 public function withPHIDs(array $phids) {
23 $this->phids = $phids;
24 return $this;
27 public function withRepositoryPHIDs(array $repository_phids) {
28 $this->repositoryPHIDs = $repository_phids;
29 return $this;
32 public function withPusherPHIDs(array $pusher_phids) {
33 $this->pusherPHIDs = $pusher_phids;
34 return $this;
37 public function withRefTypes(array $ref_types) {
38 $this->refTypes = $ref_types;
39 return $this;
42 public function withNewRefs(array $new_refs) {
43 $this->newRefs = $new_refs;
44 return $this;
47 public function withPushEventPHIDs(array $phids) {
48 $this->pushEventPHIDs = $phids;
49 return $this;
52 public function withEpochBetween($min, $max) {
53 $this->epochMin = $min;
54 $this->epochMax = $max;
55 return $this;
58 public function withBlockingHeraldRulePHIDs(array $phids) {
59 $this->blockingHeraldRulePHIDs = $phids;
60 return $this;
63 public function newResultObject() {
64 return new PhabricatorRepositoryPushLog();
67 protected function willFilterPage(array $logs) {
68 $event_phids = mpull($logs, 'getPushEventPHID');
69 $events = id(new PhabricatorObjectQuery())
70 ->setParentQuery($this)
71 ->setViewer($this->getViewer())
72 ->withPHIDs($event_phids)
73 ->execute();
74 $events = mpull($events, null, 'getPHID');
76 foreach ($logs as $key => $log) {
77 $event = idx($events, $log->getPushEventPHID());
78 if (!$event) {
79 unset($logs[$key]);
80 continue;
82 $log->attachPushEvent($event);
85 return $logs;
88 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
89 $where = parent::buildWhereClauseParts($conn);
91 if ($this->ids !== null) {
92 $where[] = qsprintf(
93 $conn,
94 'log.id IN (%Ld)',
95 $this->ids);
98 if ($this->phids !== null) {
99 $where[] = qsprintf(
100 $conn,
101 'log.phid IN (%Ls)',
102 $this->phids);
105 if ($this->repositoryPHIDs !== null) {
106 $where[] = qsprintf(
107 $conn,
108 'log.repositoryPHID IN (%Ls)',
109 $this->repositoryPHIDs);
112 if ($this->pusherPHIDs !== null) {
113 $where[] = qsprintf(
114 $conn,
115 'log.pusherPHID in (%Ls)',
116 $this->pusherPHIDs);
119 if ($this->pushEventPHIDs !== null) {
120 $where[] = qsprintf(
121 $conn,
122 'log.pushEventPHID in (%Ls)',
123 $this->pushEventPHIDs);
126 if ($this->refTypes !== null) {
127 $where[] = qsprintf(
128 $conn,
129 'log.refType IN (%Ls)',
130 $this->refTypes);
133 if ($this->newRefs !== null) {
134 $where[] = qsprintf(
135 $conn,
136 'log.refNew IN (%Ls)',
137 $this->newRefs);
140 if ($this->epochMin !== null) {
141 $where[] = qsprintf(
142 $conn,
143 'log.epoch >= %d',
144 $this->epochMin);
147 if ($this->epochMax !== null) {
148 $where[] = qsprintf(
149 $conn,
150 'log.epoch <= %d',
151 $this->epochMax);
154 if ($this->blockingHeraldRulePHIDs !== null) {
155 $where[] = qsprintf(
156 $conn,
157 '(event.rejectCode = %d AND event.rejectDetails IN (%Ls))',
158 PhabricatorRepositoryPushLog::REJECT_HERALD,
159 $this->blockingHeraldRulePHIDs);
162 return $where;
165 protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
166 $joins = parent::buildJoinClauseParts($conn);
168 if ($this->shouldJoinPushEventTable()) {
169 $joins[] = qsprintf(
170 $conn,
171 'JOIN %T event ON event.phid = log.pushEventPHID',
172 id(new PhabricatorRepositoryPushEvent())->getTableName());
175 return $joins;
178 private function shouldJoinPushEventTable() {
179 if ($this->blockingHeraldRulePHIDs !== null) {
180 return true;
183 return false;
186 public function getQueryApplicationClass() {
187 return 'PhabricatorDiffusionApplication';
190 protected function getPrimaryTableAlias() {
191 return 'log';