@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 154 lines 4.3 kB view raw
1<?php 2 3final class DiffusionSyncLogSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 public function getResultTypeDescription() { 7 return pht('Sync Logs'); 8 } 9 10 public function getApplicationClassName() { 11 return PhabricatorDiffusionApplication::class; 12 } 13 14 public function newQuery() { 15 return new PhabricatorRepositorySyncEventQuery(); 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['createdStart'] || $map['createdEnd']) { 26 $query->withEpochBetween( 27 $map['createdStart'], 28 $map['createdEnd']); 29 } 30 31 return $query; 32 } 33 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'), 49 ); 50 } 51 52 protected function newExportFields() { 53 $viewer = $this->requireViewer(); 54 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')), 86 ); 87 88 return $fields; 89 } 90 91 protected function newExportData(array $events) { 92 $viewer = $this->requireViewer(); 93 94 $export = array(); 95 foreach ($events as $event) { 96 $repository = $event->getRepository(); 97 $repository_phid = $repository->getPHID(); 98 $repository_name = $repository->getDisplayName(); 99 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(), 111 ); 112 113 $export[] = $map; 114 } 115 116 return $export; 117 } 118 119 protected function getURI($path) { 120 return '/diffusion/synclog/'.$path; 121 } 122 123 protected function getBuiltinQueryNames() { 124 return array( 125 'all' => pht('All Sync Logs'), 126 ); 127 } 128 129 public function buildSavedQueryFromBuiltin($query_key) { 130 $query = $this->newSavedQuery(); 131 $query->setQueryKey($query_key); 132 133 switch ($query_key) { 134 case 'all': 135 return $query; 136 } 137 138 return parent::buildSavedQueryFromBuiltin($query_key); 139 } 140 141 protected function renderResultList( 142 array $logs, 143 PhabricatorSavedQuery $query, 144 array $handles) { 145 146 $table = id(new DiffusionSyncLogListView()) 147 ->setViewer($this->requireViewer()) 148 ->setLogs($logs); 149 150 return id(new PhabricatorApplicationSearchResultView()) 151 ->setTable($table); 152 } 153 154}