@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<PhabricatorConduitMethodCallLog>
5 */
6final class PhabricatorConduitLogQuery
7 extends PhabricatorCursorPagedPolicyAwareQuery {
8
9 private $ids;
10 private $callerPHIDs;
11 private $methods;
12 private $methodStatuses;
13 private $isSystemAgent;
14 private $epochMin;
15 private $epochMax;
16
17 public function withIDs(array $ids) {
18 $this->ids = $ids;
19 return $this;
20 }
21
22 public function withCallerPHIDs(array $phids) {
23 $this->callerPHIDs = $phids;
24 return $this;
25 }
26
27 public function withMethods(array $methods) {
28 $this->methods = $methods;
29 return $this;
30 }
31
32 public function withMethodStatuses(array $statuses) {
33 $this->methodStatuses = $statuses;
34 return $this;
35 }
36
37 public function withIsSystemAgent($system_agent) {
38 $this->isSystemAgent = $system_agent;
39 return $this;
40 }
41
42 public function withEpochBetween($epoch_min, $epoch_max) {
43 $this->epochMin = $epoch_min;
44 $this->epochMax = $epoch_max;
45 return $this;
46 }
47
48 public function newResultObject() {
49 return new PhabricatorConduitMethodCallLog();
50 }
51
52 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
53 $where = parent::buildWhereClauseParts($conn);
54
55 if ($this->ids !== null) {
56 $where[] = qsprintf(
57 $conn,
58 'conduitlog.id IN (%Ld)',
59 $this->ids);
60 }
61
62 if ($this->callerPHIDs !== null) {
63 $where[] = qsprintf(
64 $conn,
65 'conduitlog.callerPHID IN (%Ls)',
66 $this->callerPHIDs);
67 }
68
69 if ($this->methods !== null) {
70 $where[] = qsprintf(
71 $conn,
72 'conduitlog.method IN (%Ls)',
73 $this->methods);
74 }
75
76 if ($this->methodStatuses !== null) {
77 $statuses = array_fuse($this->methodStatuses);
78
79 $methods = id(new PhabricatorConduitMethodQuery())
80 ->setViewer($this->getViewer())
81 ->execute();
82
83 $method_names = array();
84 foreach ($methods as $method) {
85 $status = $method->getMethodStatus();
86 if (isset($statuses[$status])) {
87 $method_names[] = $method->getAPIMethodName();
88 }
89 }
90
91 if (!$method_names) {
92 throw new PhabricatorEmptyQueryException();
93 }
94
95 $where[] = qsprintf(
96 $conn,
97 'conduitlog.method IN (%Ls)',
98 $method_names);
99 }
100
101 if ($this->isSystemAgent !== null) {
102 $where[] = qsprintf(
103 $conn,
104 'u.isSystemAgent = %d',
105 (int)$this->isSystemAgent);
106 }
107
108 if ($this->epochMin !== null) {
109 $where[] = qsprintf(
110 $conn,
111 'conduitlog.dateCreated >= %d',
112 $this->epochMin);
113 }
114
115 if ($this->epochMax !== null) {
116 $where[] = qsprintf(
117 $conn,
118 'conduitlog.dateCreated <= %d',
119 $this->epochMax);
120 }
121
122 return $where;
123 }
124
125 protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
126 $joins = parent::buildJoinClauseParts($conn);
127
128 if ($this->isSystemAgent !== null) {
129 $user_table = new PhabricatorUser();
130 $joins[] = qsprintf(
131 $conn,
132 'JOIN %R u ON u.phid = conduitlog.callerPHID',
133 $user_table);
134 }
135
136 return $joins;
137 }
138
139 protected function getPrimaryTableAlias() {
140 return 'conduitlog';
141 }
142
143 public function getQueryApplicationClass() {
144 return PhabricatorConduitApplication::class;
145 }
146
147}