Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / query / PhabricatorRepositoryPushLogSearchEngine.php
blob271d8a9c14749516a2294c10604b66240c1ac0ed
1 <?php
3 final class PhabricatorRepositoryPushLogSearchEngine
4 extends PhabricatorApplicationSearchEngine {
6 public function getResultTypeDescription() {
7 return pht('Push Logs');
10 public function getApplicationClassName() {
11 return 'PhabricatorDiffusionApplication';
14 public function newQuery() {
15 return new PhabricatorRepositoryPushLogQuery();
18 protected function buildQueryFromParameters(array $map) {
19 $query = $this->newQuery();
21 if ($map['repositoryPHIDs']) {
22 $query->withRepositoryPHIDs($map['repositoryPHIDs']);
25 if ($map['pusherPHIDs']) {
26 $query->withPusherPHIDs($map['pusherPHIDs']);
29 if ($map['createdStart'] || $map['createdEnd']) {
30 $query->withEpochBetween(
31 $map['createdStart'],
32 $map['createdEnd']);
35 if ($map['blockingHeraldRulePHIDs']) {
36 $query->withBlockingHeraldRulePHIDs($map['blockingHeraldRulePHIDs']);
39 return $query;
42 protected function buildCustomSearchFields() {
43 return array(
44 id(new PhabricatorSearchDatasourceField())
45 ->setDatasource(new DiffusionRepositoryDatasource())
46 ->setKey('repositoryPHIDs')
47 ->setAliases(array('repository', 'repositories', 'repositoryPHID'))
48 ->setLabel(pht('Repositories'))
49 ->setDescription(
50 pht('Search for push logs for specific repositories.')),
51 id(new PhabricatorUsersSearchField())
52 ->setKey('pusherPHIDs')
53 ->setAliases(array('pusher', 'pushers', 'pusherPHID'))
54 ->setLabel(pht('Pushers'))
55 ->setDescription(
56 pht('Search for push logs by specific users.')),
57 id(new PhabricatorSearchDatasourceField())
58 ->setDatasource(new HeraldRuleDatasource())
59 ->setKey('blockingHeraldRulePHIDs')
60 ->setLabel(pht('Blocked By'))
61 ->setDescription(
62 pht('Search for pushes blocked by particular Herald rules.')),
63 id(new PhabricatorSearchDateField())
64 ->setLabel(pht('Created After'))
65 ->setKey('createdStart'),
66 id(new PhabricatorSearchDateField())
67 ->setLabel(pht('Created Before'))
68 ->setKey('createdEnd'),
72 protected function getURI($path) {
73 return '/diffusion/pushlog/'.$path;
76 protected function getBuiltinQueryNames() {
77 return array(
78 'all' => pht('All Push Logs'),
82 public function buildSavedQueryFromBuiltin($query_key) {
83 $query = $this->newSavedQuery();
84 $query->setQueryKey($query_key);
86 switch ($query_key) {
87 case 'all':
88 return $query;
91 return parent::buildSavedQueryFromBuiltin($query_key);
94 protected function renderResultList(
95 array $logs,
96 PhabricatorSavedQuery $query,
97 array $handles) {
99 $table = id(new DiffusionPushLogListView())
100 ->setViewer($this->requireViewer())
101 ->setLogs($logs);
103 return id(new PhabricatorApplicationSearchResultView())
104 ->setTable($table);
107 protected function newExportFields() {
108 $viewer = $this->requireViewer();
110 $fields = array(
111 id(new PhabricatorIDExportField())
112 ->setKey('pushID')
113 ->setLabel(pht('Push ID')),
114 id(new PhabricatorStringExportField())
115 ->setKey('unique')
116 ->setLabel(pht('Unique')),
117 id(new PhabricatorStringExportField())
118 ->setKey('protocol')
119 ->setLabel(pht('Protocol')),
120 id(new PhabricatorPHIDExportField())
121 ->setKey('repositoryPHID')
122 ->setLabel(pht('Repository PHID')),
123 id(new PhabricatorStringExportField())
124 ->setKey('repository')
125 ->setLabel(pht('Repository')),
126 id(new PhabricatorPHIDExportField())
127 ->setKey('pusherPHID')
128 ->setLabel(pht('Pusher PHID')),
129 id(new PhabricatorStringExportField())
130 ->setKey('pusher')
131 ->setLabel(pht('Pusher')),
132 id(new PhabricatorPHIDExportField())
133 ->setKey('devicePHID')
134 ->setLabel(pht('Device PHID')),
135 id(new PhabricatorStringExportField())
136 ->setKey('device')
137 ->setLabel(pht('Device')),
138 id(new PhabricatorStringExportField())
139 ->setKey('type')
140 ->setLabel(pht('Ref Type')),
141 id(new PhabricatorStringExportField())
142 ->setKey('name')
143 ->setLabel(pht('Ref Name')),
144 id(new PhabricatorStringExportField())
145 ->setKey('old')
146 ->setLabel(pht('Ref Old')),
147 id(new PhabricatorStringExportField())
148 ->setKey('new')
149 ->setLabel(pht('Ref New')),
150 id(new PhabricatorIntExportField())
151 ->setKey('flags')
152 ->setLabel(pht('Flags')),
153 id(new PhabricatorStringListExportField())
154 ->setKey('flagNames')
155 ->setLabel(pht('Flag Names')),
156 id(new PhabricatorIntExportField())
157 ->setKey('result')
158 ->setLabel(pht('Result')),
159 id(new PhabricatorStringExportField())
160 ->setKey('resultName')
161 ->setLabel(pht('Result Name')),
162 id(new PhabricatorStringExportField())
163 ->setKey('resultDetails')
164 ->setLabel(pht('Result Details')),
165 id(new PhabricatorIntExportField())
166 ->setKey('hostWait')
167 ->setLabel(pht('Host Wait (us)')),
168 id(new PhabricatorIntExportField())
169 ->setKey('writeWait')
170 ->setLabel(pht('Write Wait (us)')),
171 id(new PhabricatorIntExportField())
172 ->setKey('readWait')
173 ->setLabel(pht('Read Wait (us)')),
174 id(new PhabricatorIntExportField())
175 ->setKey('hookWait')
176 ->setLabel(pht('Hook Wait (us)')),
179 if ($viewer->getIsAdmin()) {
180 $fields[] = id(new PhabricatorStringExportField())
181 ->setKey('remoteAddress')
182 ->setLabel(pht('Remote Address'));
185 return $fields;
188 protected function newExportData(array $logs) {
189 $viewer = $this->requireViewer();
191 $phids = array();
192 foreach ($logs as $log) {
193 $phids[] = $log->getPusherPHID();
194 $phids[] = $log->getDevicePHID();
195 $phids[] = $log->getPushEvent()->getRepositoryPHID();
197 $handles = $viewer->loadHandles($phids);
199 $flag_map = PhabricatorRepositoryPushLog::getFlagDisplayNames();
200 $reject_map = PhabricatorRepositoryPushLog::getRejectCodeDisplayNames();
202 $export = array();
203 foreach ($logs as $log) {
204 $event = $log->getPushEvent();
206 $repository_phid = $event->getRepositoryPHID();
207 if ($repository_phid) {
208 $repository_name = $handles[$repository_phid]->getName();
209 } else {
210 $repository_name = null;
213 $pusher_phid = $log->getPusherPHID();
214 if ($pusher_phid) {
215 $pusher_name = $handles[$pusher_phid]->getName();
216 } else {
217 $pusher_name = null;
220 $device_phid = $log->getDevicePHID();
221 if ($device_phid) {
222 $device_name = $handles[$device_phid]->getName();
223 } else {
224 $device_name = null;
227 $flags = $log->getChangeFlags();
228 $flag_names = array();
229 foreach ($flag_map as $flag_key => $flag_name) {
230 if (($flags & $flag_key) === $flag_key) {
231 $flag_names[] = $flag_name;
235 $result = $event->getRejectCode();
236 $result_name = idx($reject_map, $result, pht('Unknown ("%s")', $result));
238 $map = array(
239 'pushID' => $event->getID(),
240 'unique' => $event->getRequestIdentifier(),
241 'protocol' => $event->getRemoteProtocol(),
242 'repositoryPHID' => $repository_phid,
243 'repository' => $repository_name,
244 'pusherPHID' => $pusher_phid,
245 'pusher' => $pusher_name,
246 'devicePHID' => $device_phid,
247 'device' => $device_name,
248 'type' => $log->getRefType(),
249 'name' => $log->getRefName(),
250 'old' => $log->getRefOld(),
251 'new' => $log->getRefNew(),
252 'flags' => $flags,
253 'flagNames' => $flag_names,
254 'result' => $result,
255 'resultName' => $result_name,
256 'resultDetails' => $event->getRejectDetails(),
257 'hostWait' => $event->getHostWait(),
258 'writeWait' => $event->getWriteWait(),
259 'readWait' => $event->getReadWait(),
260 'hookWait' => $event->getHookWait(),
263 if ($viewer->getIsAdmin()) {
264 $map['remoteAddress'] = $event->getRemoteAddress();
267 $export[] = $map;
270 return $export;