Path: blob/master/src/applications/herald/query/HeraldTranscriptQuery.php
12256 views
<?php12final class HeraldTranscriptQuery3extends PhabricatorCursorPagedPolicyAwareQuery {45private $ids;6private $phids;7private $objectPHIDs;8private $needPartialRecords;910public function withIDs(array $ids) {11$this->ids = $ids;12return $this;13}1415public function withPHIDs(array $phids) {16$this->phids = $phids;17return $this;18}1920public function withObjectPHIDs(array $phids) {21$this->objectPHIDs = $phids;22return $this;23}2425public function needPartialRecords($need_partial) {26$this->needPartialRecords = $need_partial;27return $this;28}2930protected function loadPage() {31$transcript = new HeraldTranscript();32$conn = $transcript->establishConnection('r');3334// NOTE: Transcripts include a potentially enormous amount of serialized35// data, so we're loading only some of the fields here if the caller asked36// for partial records.3738if ($this->needPartialRecords) {39$fields = array(40'id',41'phid',42'objectPHID',43'time',44'duration',45'dryRun',46'host',47);48$fields = qsprintf($conn, '%LC', $fields);49} else {50$fields = qsprintf($conn, '*');51}5253$rows = queryfx_all(54$conn,55'SELECT %Q FROM %T t %Q %Q %Q',56$fields,57$transcript->getTableName(),58$this->buildWhereClause($conn),59$this->buildOrderClause($conn),60$this->buildLimitClause($conn));6162$transcripts = $transcript->loadAllFromArray($rows);6364if ($this->needPartialRecords) {65// Make sure nothing tries to write these; they aren't complete.66foreach ($transcripts as $transcript) {67$transcript->makeEphemeral();68}69}7071return $transcripts;72}7374protected function willFilterPage(array $transcripts) {75$phids = mpull($transcripts, 'getObjectPHID');7677$objects = id(new PhabricatorObjectQuery())78->setViewer($this->getViewer())79->withPHIDs($phids)80->execute();8182foreach ($transcripts as $key => $transcript) {83$object_phid = $transcript->getObjectPHID();8485if (!$object_phid) {86$transcript->attachObject(null);87continue;88}8990$object = idx($objects, $object_phid);91if (!$object) {92$this->didRejectResult($transcript);93unset($transcripts[$key]);94}9596$transcript->attachObject($object);97}9899return $transcripts;100}101102protected function buildWhereClause(AphrontDatabaseConnection $conn) {103$where = array();104105if ($this->ids) {106$where[] = qsprintf(107$conn,108'id IN (%Ld)',109$this->ids);110}111112if ($this->phids) {113$where[] = qsprintf(114$conn,115'phid IN (%Ls)',116$this->phids);117}118119if ($this->objectPHIDs) {120$where[] = qsprintf(121$conn,122'objectPHID in (%Ls)',123$this->objectPHIDs);124}125126$where[] = $this->buildPagingClause($conn);127128return $this->formatWhereClause($conn, $where);129}130131public function getQueryApplicationClass() {132return 'PhabricatorHeraldApplication';133}134135}136137138