Remove product literal strings in "pht()", part 18
[phabricator.git] / src / applications / herald / query / HeraldTranscriptQuery.php
blob00a9dffeafc8c5671450b6e22466a39a7939d57f
1 <?php
3 final class HeraldTranscriptQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $phids;
8 private $objectPHIDs;
9 private $needPartialRecords;
11 public function withIDs(array $ids) {
12 $this->ids = $ids;
13 return $this;
16 public function withPHIDs(array $phids) {
17 $this->phids = $phids;
18 return $this;
21 public function withObjectPHIDs(array $phids) {
22 $this->objectPHIDs = $phids;
23 return $this;
26 public function needPartialRecords($need_partial) {
27 $this->needPartialRecords = $need_partial;
28 return $this;
31 protected function loadPage() {
32 $transcript = new HeraldTranscript();
33 $conn = $transcript->establishConnection('r');
35 // NOTE: Transcripts include a potentially enormous amount of serialized
36 // data, so we're loading only some of the fields here if the caller asked
37 // for partial records.
39 if ($this->needPartialRecords) {
40 $fields = array(
41 'id',
42 'phid',
43 'objectPHID',
44 'time',
45 'duration',
46 'dryRun',
47 'host',
49 $fields = qsprintf($conn, '%LC', $fields);
50 } else {
51 $fields = qsprintf($conn, '*');
54 $rows = queryfx_all(
55 $conn,
56 'SELECT %Q FROM %T t %Q %Q %Q',
57 $fields,
58 $transcript->getTableName(),
59 $this->buildWhereClause($conn),
60 $this->buildOrderClause($conn),
61 $this->buildLimitClause($conn));
63 $transcripts = $transcript->loadAllFromArray($rows);
65 if ($this->needPartialRecords) {
66 // Make sure nothing tries to write these; they aren't complete.
67 foreach ($transcripts as $transcript) {
68 $transcript->makeEphemeral();
72 return $transcripts;
75 protected function willFilterPage(array $transcripts) {
76 $phids = mpull($transcripts, 'getObjectPHID');
78 $objects = id(new PhabricatorObjectQuery())
79 ->setViewer($this->getViewer())
80 ->withPHIDs($phids)
81 ->execute();
83 foreach ($transcripts as $key => $transcript) {
84 $object_phid = $transcript->getObjectPHID();
86 if (!$object_phid) {
87 $transcript->attachObject(null);
88 continue;
91 $object = idx($objects, $object_phid);
92 if (!$object) {
93 $this->didRejectResult($transcript);
94 unset($transcripts[$key]);
97 $transcript->attachObject($object);
100 return $transcripts;
103 protected function buildWhereClause(AphrontDatabaseConnection $conn) {
104 $where = array();
106 if ($this->ids) {
107 $where[] = qsprintf(
108 $conn,
109 'id IN (%Ld)',
110 $this->ids);
113 if ($this->phids) {
114 $where[] = qsprintf(
115 $conn,
116 'phid IN (%Ls)',
117 $this->phids);
120 if ($this->objectPHIDs) {
121 $where[] = qsprintf(
122 $conn,
123 'objectPHID in (%Ls)',
124 $this->objectPHIDs);
127 $where[] = $this->buildPagingClause($conn);
129 return $this->formatWhereClause($conn, $where);
132 public function getQueryApplicationClass() {
133 return 'PhabricatorHeraldApplication';