Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/herald/query/HeraldTranscriptQuery.php
12256 views
1
<?php
2
3
final class HeraldTranscriptQuery
4
extends PhabricatorCursorPagedPolicyAwareQuery {
5
6
private $ids;
7
private $phids;
8
private $objectPHIDs;
9
private $needPartialRecords;
10
11
public function withIDs(array $ids) {
12
$this->ids = $ids;
13
return $this;
14
}
15
16
public function withPHIDs(array $phids) {
17
$this->phids = $phids;
18
return $this;
19
}
20
21
public function withObjectPHIDs(array $phids) {
22
$this->objectPHIDs = $phids;
23
return $this;
24
}
25
26
public function needPartialRecords($need_partial) {
27
$this->needPartialRecords = $need_partial;
28
return $this;
29
}
30
31
protected function loadPage() {
32
$transcript = new HeraldTranscript();
33
$conn = $transcript->establishConnection('r');
34
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.
38
39
if ($this->needPartialRecords) {
40
$fields = array(
41
'id',
42
'phid',
43
'objectPHID',
44
'time',
45
'duration',
46
'dryRun',
47
'host',
48
);
49
$fields = qsprintf($conn, '%LC', $fields);
50
} else {
51
$fields = qsprintf($conn, '*');
52
}
53
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));
62
63
$transcripts = $transcript->loadAllFromArray($rows);
64
65
if ($this->needPartialRecords) {
66
// Make sure nothing tries to write these; they aren't complete.
67
foreach ($transcripts as $transcript) {
68
$transcript->makeEphemeral();
69
}
70
}
71
72
return $transcripts;
73
}
74
75
protected function willFilterPage(array $transcripts) {
76
$phids = mpull($transcripts, 'getObjectPHID');
77
78
$objects = id(new PhabricatorObjectQuery())
79
->setViewer($this->getViewer())
80
->withPHIDs($phids)
81
->execute();
82
83
foreach ($transcripts as $key => $transcript) {
84
$object_phid = $transcript->getObjectPHID();
85
86
if (!$object_phid) {
87
$transcript->attachObject(null);
88
continue;
89
}
90
91
$object = idx($objects, $object_phid);
92
if (!$object) {
93
$this->didRejectResult($transcript);
94
unset($transcripts[$key]);
95
}
96
97
$transcript->attachObject($object);
98
}
99
100
return $transcripts;
101
}
102
103
protected function buildWhereClause(AphrontDatabaseConnection $conn) {
104
$where = array();
105
106
if ($this->ids) {
107
$where[] = qsprintf(
108
$conn,
109
'id IN (%Ld)',
110
$this->ids);
111
}
112
113
if ($this->phids) {
114
$where[] = qsprintf(
115
$conn,
116
'phid IN (%Ls)',
117
$this->phids);
118
}
119
120
if ($this->objectPHIDs) {
121
$where[] = qsprintf(
122
$conn,
123
'objectPHID in (%Ls)',
124
$this->objectPHIDs);
125
}
126
127
$where[] = $this->buildPagingClause($conn);
128
129
return $this->formatWhereClause($conn, $where);
130
}
131
132
public function getQueryApplicationClass() {
133
return 'PhabricatorHeraldApplication';
134
}
135
136
}
137
138