@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<HeraldWebhookRequest>
5 */
6final class HeraldWebhookRequestQuery
7 extends PhabricatorCursorPagedPolicyAwareQuery {
8
9 private $ids;
10 private $phids;
11 private $webhookPHIDs;
12 private $lastRequestEpochMin;
13 private $lastRequestEpochMax;
14 private $lastRequestResults;
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 withWebhookPHIDs(array $phids) {
27 $this->webhookPHIDs = $phids;
28 return $this;
29 }
30
31 public function newResultObject() {
32 return new HeraldWebhookRequest();
33 }
34
35 public function withLastRequestEpochBetween($epoch_min, $epoch_max) {
36 $this->lastRequestEpochMin = $epoch_min;
37 $this->lastRequestEpochMax = $epoch_max;
38 return $this;
39 }
40
41 public function withLastRequestResults(array $results) {
42 $this->lastRequestResults = $results;
43 return $this;
44 }
45
46 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
47 $where = parent::buildWhereClauseParts($conn);
48
49 if ($this->ids !== null) {
50 $where[] = qsprintf(
51 $conn,
52 'id IN (%Ld)',
53 $this->ids);
54 }
55
56 if ($this->phids !== null) {
57 $where[] = qsprintf(
58 $conn,
59 'phid IN (%Ls)',
60 $this->phids);
61 }
62
63 if ($this->webhookPHIDs !== null) {
64 $where[] = qsprintf(
65 $conn,
66 'webhookPHID IN (%Ls)',
67 $this->webhookPHIDs);
68 }
69
70 if ($this->lastRequestEpochMin !== null) {
71 $where[] = qsprintf(
72 $conn,
73 'lastRequestEpoch >= %d',
74 $this->lastRequestEpochMin);
75 }
76
77 if ($this->lastRequestEpochMax !== null) {
78 $where[] = qsprintf(
79 $conn,
80 'lastRequestEpoch <= %d',
81 $this->lastRequestEpochMax);
82 }
83
84 if ($this->lastRequestResults !== null) {
85 $where[] = qsprintf(
86 $conn,
87 'lastRequestResult IN (%Ls)',
88 $this->lastRequestResults);
89 }
90
91 return $where;
92 }
93
94 protected function willFilterPage(array $requests) {
95 $hook_phids = mpull($requests, 'getWebhookPHID');
96
97 $hooks = id(new HeraldWebhookQuery())
98 ->setViewer($this->getViewer())
99 ->setParentQuery($this)
100 ->withPHIDs($hook_phids)
101 ->execute();
102 $hooks = mpull($hooks, null, 'getPHID');
103
104 foreach ($requests as $key => $request) {
105 $hook_phid = $request->getWebhookPHID();
106 $hook = idx($hooks, $hook_phid);
107
108 if (!$hook) {
109 unset($requests[$key]);
110 $this->didRejectResult($request);
111 continue;
112 }
113
114 $request->attachWebhook($hook);
115 }
116
117 return $requests;
118 }
119
120
121 public function getQueryApplicationClass() {
122 return PhabricatorHeraldApplication::class;
123 }
124
125}