Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/diffusion/query/DiffusionPullLogSearchEngine.php
12242 views
1
<?php
2
3
final class DiffusionPullLogSearchEngine
4
extends PhabricatorApplicationSearchEngine {
5
6
public function getResultTypeDescription() {
7
return pht('Pull Logs');
8
}
9
10
public function getApplicationClassName() {
11
return 'PhabricatorDiffusionApplication';
12
}
13
14
public function newQuery() {
15
return new PhabricatorRepositoryPullEventQuery();
16
}
17
18
protected function buildQueryFromParameters(array $map) {
19
$query = $this->newQuery();
20
21
if ($map['repositoryPHIDs']) {
22
$query->withRepositoryPHIDs($map['repositoryPHIDs']);
23
}
24
25
if ($map['pullerPHIDs']) {
26
$query->withPullerPHIDs($map['pullerPHIDs']);
27
}
28
29
if ($map['createdStart'] || $map['createdEnd']) {
30
$query->withEpochBetween(
31
$map['createdStart'],
32
$map['createdEnd']);
33
}
34
35
return $query;
36
}
37
38
protected function buildCustomSearchFields() {
39
return array(
40
id(new PhabricatorSearchDatasourceField())
41
->setDatasource(new DiffusionRepositoryDatasource())
42
->setKey('repositoryPHIDs')
43
->setAliases(array('repository', 'repositories', 'repositoryPHID'))
44
->setLabel(pht('Repositories'))
45
->setDescription(
46
pht('Search for pull logs for specific repositories.')),
47
id(new PhabricatorUsersSearchField())
48
->setKey('pullerPHIDs')
49
->setAliases(array('puller', 'pullers', 'pullerPHID'))
50
->setLabel(pht('Pullers'))
51
->setDescription(
52
pht('Search for pull logs by specific users.')),
53
id(new PhabricatorSearchDateField())
54
->setLabel(pht('Created After'))
55
->setKey('createdStart'),
56
id(new PhabricatorSearchDateField())
57
->setLabel(pht('Created Before'))
58
->setKey('createdEnd'),
59
);
60
}
61
62
protected function newExportFields() {
63
$viewer = $this->requireViewer();
64
65
$fields = array(
66
id(new PhabricatorPHIDExportField())
67
->setKey('repositoryPHID')
68
->setLabel(pht('Repository PHID')),
69
id(new PhabricatorStringExportField())
70
->setKey('repository')
71
->setLabel(pht('Repository')),
72
id(new PhabricatorPHIDExportField())
73
->setKey('pullerPHID')
74
->setLabel(pht('Puller PHID')),
75
id(new PhabricatorStringExportField())
76
->setKey('puller')
77
->setLabel(pht('Puller')),
78
id(new PhabricatorStringExportField())
79
->setKey('protocol')
80
->setLabel(pht('Protocol')),
81
id(new PhabricatorStringExportField())
82
->setKey('result')
83
->setLabel(pht('Result')),
84
id(new PhabricatorIntExportField())
85
->setKey('code')
86
->setLabel(pht('Code')),
87
id(new PhabricatorEpochExportField())
88
->setKey('date')
89
->setLabel(pht('Date')),
90
);
91
92
if ($viewer->getIsAdmin()) {
93
$fields[] = id(new PhabricatorStringExportField())
94
->setKey('remoteAddress')
95
->setLabel(pht('Remote Address'));
96
}
97
98
return $fields;
99
}
100
101
protected function newExportData(array $events) {
102
$viewer = $this->requireViewer();
103
104
$phids = array();
105
foreach ($events as $event) {
106
if ($event->getPullerPHID()) {
107
$phids[] = $event->getPullerPHID();
108
}
109
}
110
$handles = $viewer->loadHandles($phids);
111
112
$export = array();
113
foreach ($events as $event) {
114
$repository = $event->getRepository();
115
if ($repository) {
116
$repository_phid = $repository->getPHID();
117
$repository_name = $repository->getDisplayName();
118
} else {
119
$repository_phid = null;
120
$repository_name = null;
121
}
122
123
$puller_phid = $event->getPullerPHID();
124
if ($puller_phid) {
125
$puller_name = $handles[$puller_phid]->getName();
126
} else {
127
$puller_name = null;
128
}
129
130
$map = array(
131
'repositoryPHID' => $repository_phid,
132
'repository' => $repository_name,
133
'pullerPHID' => $puller_phid,
134
'puller' => $puller_name,
135
'protocol' => $event->getRemoteProtocol(),
136
'result' => $event->getResultType(),
137
'code' => $event->getResultCode(),
138
'date' => $event->getEpoch(),
139
);
140
141
if ($viewer->getIsAdmin()) {
142
$map['remoteAddress'] = $event->getRemoteAddress();
143
}
144
145
$export[] = $map;
146
}
147
148
return $export;
149
}
150
151
protected function getURI($path) {
152
return '/diffusion/pulllog/'.$path;
153
}
154
155
protected function getBuiltinQueryNames() {
156
return array(
157
'all' => pht('All Pull Logs'),
158
);
159
}
160
161
public function buildSavedQueryFromBuiltin($query_key) {
162
$query = $this->newSavedQuery();
163
$query->setQueryKey($query_key);
164
165
switch ($query_key) {
166
case 'all':
167
return $query;
168
}
169
170
return parent::buildSavedQueryFromBuiltin($query_key);
171
}
172
173
protected function renderResultList(
174
array $logs,
175
PhabricatorSavedQuery $query,
176
array $handles) {
177
178
$table = id(new DiffusionPullLogListView())
179
->setViewer($this->requireViewer())
180
->setLogs($logs);
181
182
return id(new PhabricatorApplicationSearchResultView())
183
->setTable($table);
184
}
185
186
}
187
188