Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / diffusion / query / DiffusionSyncLogSearchEngine.php
blob6b321189f4e5dad701b90ac986d036c34f258692
1 <?php
3 final class DiffusionSyncLogSearchEngine
4 extends PhabricatorApplicationSearchEngine {
6 public function getResultTypeDescription() {
7 return pht('Sync Logs');
10 public function getApplicationClassName() {
11 return 'PhabricatorDiffusionApplication';
14 public function newQuery() {
15 return new PhabricatorRepositorySyncEventQuery();
18 protected function buildQueryFromParameters(array $map) {
19 $query = $this->newQuery();
21 if ($map['repositoryPHIDs']) {
22 $query->withRepositoryPHIDs($map['repositoryPHIDs']);
25 if ($map['createdStart'] || $map['createdEnd']) {
26 $query->withEpochBetween(
27 $map['createdStart'],
28 $map['createdEnd']);
31 return $query;
34 protected function buildCustomSearchFields() {
35 return array(
36 id(new PhabricatorSearchDatasourceField())
37 ->setDatasource(new DiffusionRepositoryDatasource())
38 ->setKey('repositoryPHIDs')
39 ->setAliases(array('repository', 'repositories', 'repositoryPHID'))
40 ->setLabel(pht('Repositories'))
41 ->setDescription(
42 pht('Search for sync logs for specific repositories.')),
43 id(new PhabricatorSearchDateField())
44 ->setLabel(pht('Created After'))
45 ->setKey('createdStart'),
46 id(new PhabricatorSearchDateField())
47 ->setLabel(pht('Created Before'))
48 ->setKey('createdEnd'),
52 protected function newExportFields() {
53 $viewer = $this->requireViewer();
55 $fields = array(
56 id(new PhabricatorPHIDExportField())
57 ->setKey('repositoryPHID')
58 ->setLabel(pht('Repository PHID')),
59 id(new PhabricatorStringExportField())
60 ->setKey('repository')
61 ->setLabel(pht('Repository')),
62 id(new PhabricatorPHIDExportField())
63 ->setKey('devicePHID')
64 ->setLabel(pht('Device PHID')),
65 id(new PhabricatorPHIDExportField())
66 ->setKey('fromDevicePHID')
67 ->setLabel(pht('From Device PHID')),
68 id(new PhabricatorIntExportField())
69 ->setKey('deviceVersion')
70 ->setLabel(pht('Device Version')),
71 id(new PhabricatorIntExportField())
72 ->setKey('fromDeviceVersion')
73 ->setLabel(pht('From Device Version')),
74 id(new PhabricatorStringExportField())
75 ->setKey('result')
76 ->setLabel(pht('Result')),
77 id(new PhabricatorIntExportField())
78 ->setKey('code')
79 ->setLabel(pht('Code')),
80 id(new PhabricatorEpochExportField())
81 ->setKey('date')
82 ->setLabel(pht('Date')),
83 id(new PhabricatorIntExportField())
84 ->setKey('syncWait')
85 ->setLabel(pht('Sync Wait')),
88 return $fields;
91 protected function newExportData(array $events) {
92 $viewer = $this->requireViewer();
94 $export = array();
95 foreach ($events as $event) {
96 $repository = $event->getRepository();
97 $repository_phid = $repository->getPHID();
98 $repository_name = $repository->getDisplayName();
100 $map = array(
101 'repositoryPHID' => $repository_phid,
102 'repository' => $repository_name,
103 'devicePHID' => $event->getDevicePHID(),
104 'fromDevicePHID' => $event->getFromDevicePHID(),
105 'deviceVersion' => $event->getDeviceVersion(),
106 'fromDeviceVersion' => $event->getFromDeviceVersion(),
107 'result' => $event->getResultType(),
108 'code' => $event->getResultCode(),
109 'date' => $event->getEpoch(),
110 'syncWait' => $event->getSyncWait(),
113 $export[] = $map;
116 return $export;
119 protected function getURI($path) {
120 return '/diffusion/synclog/'.$path;
123 protected function getBuiltinQueryNames() {
124 return array(
125 'all' => pht('All Sync Logs'),
129 public function buildSavedQueryFromBuiltin($query_key) {
130 $query = $this->newSavedQuery();
131 $query->setQueryKey($query_key);
133 switch ($query_key) {
134 case 'all':
135 return $query;
138 return parent::buildSavedQueryFromBuiltin($query_key);
141 protected function renderResultList(
142 array $logs,
143 PhabricatorSavedQuery $query,
144 array $handles) {
146 $table = id(new DiffusionSyncLogListView())
147 ->setViewer($this->requireViewer())
148 ->setLogs($logs);
150 return id(new PhabricatorApplicationSearchResultView())
151 ->setTable($table);