@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<PhabricatorRepositoryPushEvent>
5 */
6final class PhabricatorRepositoryPushEventQuery
7 extends PhabricatorCursorPagedPolicyAwareQuery {
8
9 private $ids;
10 private $phids;
11 private $repositoryPHIDs;
12 private $pusherPHIDs;
13 private $needLogs;
14
15 public function withIDs(array $ids) {
16 $this->ids = $ids;
17 return $this;
18 }
19
20 public function withPHIDs(array $phids) {
21 $this->phids = $phids;
22 return $this;
23 }
24
25 public function withRepositoryPHIDs(array $repository_phids) {
26 $this->repositoryPHIDs = $repository_phids;
27 return $this;
28 }
29
30 public function withPusherPHIDs(array $pusher_phids) {
31 $this->pusherPHIDs = $pusher_phids;
32 return $this;
33 }
34
35 public function needLogs($need_logs) {
36 $this->needLogs = $need_logs;
37 return $this;
38 }
39
40 public function newResultObject() {
41 return new PhabricatorRepositoryPushEvent();
42 }
43
44 protected function willFilterPage(array $events) {
45 $repository_phids = mpull($events, 'getRepositoryPHID');
46 $repositories = id(new PhabricatorRepositoryQuery())
47 ->setViewer($this->getViewer())
48 ->withPHIDs($repository_phids)
49 ->execute();
50 $repositories = mpull($repositories, null, 'getPHID');
51
52 foreach ($events as $key => $event) {
53 $phid = $event->getRepositoryPHID();
54 if (empty($repositories[$phid])) {
55 unset($events[$key]);
56 continue;
57 }
58 $event->attachRepository($repositories[$phid]);
59 }
60
61 return $events;
62 }
63
64 protected function didFilterPage(array $events) {
65 $phids = mpull($events, 'getPHID');
66
67 if ($this->needLogs) {
68 $logs = id(new PhabricatorRepositoryPushLogQuery())
69 ->setParentQuery($this)
70 ->setViewer($this->getViewer())
71 ->withPushEventPHIDs($phids)
72 ->execute();
73 $logs = mgroup($logs, 'getPushEventPHID');
74 foreach ($events as $key => $event) {
75 $event_logs = idx($logs, $event->getPHID(), array());
76 $event->attachLogs($event_logs);
77 }
78 }
79
80 return $events;
81 }
82
83 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
84 $where = parent::buildWhereClauseParts($conn);
85
86 if ($this->ids !== null) {
87 $where[] = qsprintf(
88 $conn,
89 'id IN (%Ld)',
90 $this->ids);
91 }
92
93 if ($this->phids !== null) {
94 $where[] = qsprintf(
95 $conn,
96 'phid IN (%Ls)',
97 $this->phids);
98 }
99
100 if ($this->repositoryPHIDs !== null) {
101 $where[] = qsprintf(
102 $conn,
103 'repositoryPHID IN (%Ls)',
104 $this->repositoryPHIDs);
105 }
106
107 if ($this->pusherPHIDs !== null) {
108 $where[] = qsprintf(
109 $conn,
110 'pusherPHID in (%Ls)',
111 $this->pusherPHIDs);
112 }
113
114 return $where;
115 }
116
117 public function getQueryApplicationClass() {
118 return PhabricatorDiffusionApplication::class;
119 }
120
121}