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