Path: blob/master/src/applications/herald/query/HeraldWebhookRequestQuery.php
12256 views
<?php12final class HeraldWebhookRequestQuery3extends PhabricatorCursorPagedPolicyAwareQuery {45private $ids;6private $phids;7private $webhookPHIDs;8private $lastRequestEpochMin;9private $lastRequestEpochMax;10private $lastRequestResults;1112public function withIDs(array $ids) {13$this->ids = $ids;14return $this;15}1617public function withPHIDs(array $phids) {18$this->phids = $phids;19return $this;20}2122public function withWebhookPHIDs(array $phids) {23$this->webhookPHIDs = $phids;24return $this;25}2627public function newResultObject() {28return new HeraldWebhookRequest();29}3031public function withLastRequestEpochBetween($epoch_min, $epoch_max) {32$this->lastRequestEpochMin = $epoch_min;33$this->lastRequestEpochMax = $epoch_max;34return $this;35}3637public function withLastRequestResults(array $results) {38$this->lastRequestResults = $results;39return $this;40}4142protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {43$where = parent::buildWhereClauseParts($conn);4445if ($this->ids !== null) {46$where[] = qsprintf(47$conn,48'id IN (%Ld)',49$this->ids);50}5152if ($this->phids !== null) {53$where[] = qsprintf(54$conn,55'phid IN (%Ls)',56$this->phids);57}5859if ($this->webhookPHIDs !== null) {60$where[] = qsprintf(61$conn,62'webhookPHID IN (%Ls)',63$this->webhookPHIDs);64}6566if ($this->lastRequestEpochMin !== null) {67$where[] = qsprintf(68$conn,69'lastRequestEpoch >= %d',70$this->lastRequestEpochMin);71}7273if ($this->lastRequestEpochMax !== null) {74$where[] = qsprintf(75$conn,76'lastRequestEpoch <= %d',77$this->lastRequestEpochMax);78}7980if ($this->lastRequestResults !== null) {81$where[] = qsprintf(82$conn,83'lastRequestResult IN (%Ls)',84$this->lastRequestResults);85}8687return $where;88}8990protected function willFilterPage(array $requests) {91$hook_phids = mpull($requests, 'getWebhookPHID');9293$hooks = id(new HeraldWebhookQuery())94->setViewer($this->getViewer())95->setParentQuery($this)96->withPHIDs($hook_phids)97->execute();98$hooks = mpull($hooks, null, 'getPHID');99100foreach ($requests as $key => $request) {101$hook_phid = $request->getWebhookPHID();102$hook = idx($hooks, $hook_phid);103104if (!$hook) {105unset($requests[$key]);106$this->didRejectResult($request);107continue;108}109110$request->attachWebhook($hook);111}112113return $requests;114}115116117public function getQueryApplicationClass() {118return 'PhabricatorHeraldApplication';119}120121}122123124