Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / conduit / query / PhabricatorConduitLogQuery.php
blob23a5b4678662aa8678626b48c3557f2c014222ce
1 <?php
3 final class PhabricatorConduitLogQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $callerPHIDs;
8 private $methods;
9 private $methodStatuses;
10 private $epochMin;
11 private $epochMax;
13 public function withIDs(array $ids) {
14 $this->ids = $ids;
15 return $this;
18 public function withCallerPHIDs(array $phids) {
19 $this->callerPHIDs = $phids;
20 return $this;
23 public function withMethods(array $methods) {
24 $this->methods = $methods;
25 return $this;
28 public function withMethodStatuses(array $statuses) {
29 $this->methodStatuses = $statuses;
30 return $this;
33 public function withEpochBetween($epoch_min, $epoch_max) {
34 $this->epochMin = $epoch_min;
35 $this->epochMax = $epoch_max;
36 return $this;
39 public function newResultObject() {
40 return new PhabricatorConduitMethodCallLog();
43 protected function loadPage() {
44 return $this->loadStandardPage($this->newResultObject());
47 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
48 $where = parent::buildWhereClauseParts($conn);
50 if ($this->ids !== null) {
51 $where[] = qsprintf(
52 $conn,
53 'id IN (%Ld)',
54 $this->ids);
57 if ($this->callerPHIDs !== null) {
58 $where[] = qsprintf(
59 $conn,
60 'callerPHID IN (%Ls)',
61 $this->callerPHIDs);
64 if ($this->methods !== null) {
65 $where[] = qsprintf(
66 $conn,
67 'method IN (%Ls)',
68 $this->methods);
71 if ($this->methodStatuses !== null) {
72 $statuses = array_fuse($this->methodStatuses);
74 $methods = id(new PhabricatorConduitMethodQuery())
75 ->setViewer($this->getViewer())
76 ->execute();
78 $method_names = array();
79 foreach ($methods as $method) {
80 $status = $method->getMethodStatus();
81 if (isset($statuses[$status])) {
82 $method_names[] = $method->getAPIMethodName();
86 if (!$method_names) {
87 throw new PhabricatorEmptyQueryException();
90 $where[] = qsprintf(
91 $conn,
92 'method IN (%Ls)',
93 $method_names);
96 if ($this->epochMin !== null) {
97 $where[] = qsprintf(
98 $conn,
99 'dateCreated >= %d',
100 $this->epochMin);
103 if ($this->epochMax !== null) {
104 $where[] = qsprintf(
105 $conn,
106 'dateCreated <= %d',
107 $this->epochMax);
110 return $where;
113 public function getQueryApplicationClass() {
114 return 'PhabricatorConduitApplication';