Path: blob/master/src/applications/diffusion/query/DiffusionPullLogSearchEngine.php
12242 views
<?php12final class DiffusionPullLogSearchEngine3extends PhabricatorApplicationSearchEngine {45public function getResultTypeDescription() {6return pht('Pull Logs');7}89public function getApplicationClassName() {10return 'PhabricatorDiffusionApplication';11}1213public function newQuery() {14return new PhabricatorRepositoryPullEventQuery();15}1617protected function buildQueryFromParameters(array $map) {18$query = $this->newQuery();1920if ($map['repositoryPHIDs']) {21$query->withRepositoryPHIDs($map['repositoryPHIDs']);22}2324if ($map['pullerPHIDs']) {25$query->withPullerPHIDs($map['pullerPHIDs']);26}2728if ($map['createdStart'] || $map['createdEnd']) {29$query->withEpochBetween(30$map['createdStart'],31$map['createdEnd']);32}3334return $query;35}3637protected function buildCustomSearchFields() {38return array(39id(new PhabricatorSearchDatasourceField())40->setDatasource(new DiffusionRepositoryDatasource())41->setKey('repositoryPHIDs')42->setAliases(array('repository', 'repositories', 'repositoryPHID'))43->setLabel(pht('Repositories'))44->setDescription(45pht('Search for pull logs for specific repositories.')),46id(new PhabricatorUsersSearchField())47->setKey('pullerPHIDs')48->setAliases(array('puller', 'pullers', 'pullerPHID'))49->setLabel(pht('Pullers'))50->setDescription(51pht('Search for pull logs by specific users.')),52id(new PhabricatorSearchDateField())53->setLabel(pht('Created After'))54->setKey('createdStart'),55id(new PhabricatorSearchDateField())56->setLabel(pht('Created Before'))57->setKey('createdEnd'),58);59}6061protected function newExportFields() {62$viewer = $this->requireViewer();6364$fields = array(65id(new PhabricatorPHIDExportField())66->setKey('repositoryPHID')67->setLabel(pht('Repository PHID')),68id(new PhabricatorStringExportField())69->setKey('repository')70->setLabel(pht('Repository')),71id(new PhabricatorPHIDExportField())72->setKey('pullerPHID')73->setLabel(pht('Puller PHID')),74id(new PhabricatorStringExportField())75->setKey('puller')76->setLabel(pht('Puller')),77id(new PhabricatorStringExportField())78->setKey('protocol')79->setLabel(pht('Protocol')),80id(new PhabricatorStringExportField())81->setKey('result')82->setLabel(pht('Result')),83id(new PhabricatorIntExportField())84->setKey('code')85->setLabel(pht('Code')),86id(new PhabricatorEpochExportField())87->setKey('date')88->setLabel(pht('Date')),89);9091if ($viewer->getIsAdmin()) {92$fields[] = id(new PhabricatorStringExportField())93->setKey('remoteAddress')94->setLabel(pht('Remote Address'));95}9697return $fields;98}99100protected function newExportData(array $events) {101$viewer = $this->requireViewer();102103$phids = array();104foreach ($events as $event) {105if ($event->getPullerPHID()) {106$phids[] = $event->getPullerPHID();107}108}109$handles = $viewer->loadHandles($phids);110111$export = array();112foreach ($events as $event) {113$repository = $event->getRepository();114if ($repository) {115$repository_phid = $repository->getPHID();116$repository_name = $repository->getDisplayName();117} else {118$repository_phid = null;119$repository_name = null;120}121122$puller_phid = $event->getPullerPHID();123if ($puller_phid) {124$puller_name = $handles[$puller_phid]->getName();125} else {126$puller_name = null;127}128129$map = array(130'repositoryPHID' => $repository_phid,131'repository' => $repository_name,132'pullerPHID' => $puller_phid,133'puller' => $puller_name,134'protocol' => $event->getRemoteProtocol(),135'result' => $event->getResultType(),136'code' => $event->getResultCode(),137'date' => $event->getEpoch(),138);139140if ($viewer->getIsAdmin()) {141$map['remoteAddress'] = $event->getRemoteAddress();142}143144$export[] = $map;145}146147return $export;148}149150protected function getURI($path) {151return '/diffusion/pulllog/'.$path;152}153154protected function getBuiltinQueryNames() {155return array(156'all' => pht('All Pull Logs'),157);158}159160public function buildSavedQueryFromBuiltin($query_key) {161$query = $this->newSavedQuery();162$query->setQueryKey($query_key);163164switch ($query_key) {165case 'all':166return $query;167}168169return parent::buildSavedQueryFromBuiltin($query_key);170}171172protected function renderResultList(173array $logs,174PhabricatorSavedQuery $query,175array $handles) {176177$table = id(new DiffusionPullLogListView())178->setViewer($this->requireViewer())179->setLogs($logs);180181return id(new PhabricatorApplicationSearchResultView())182->setTable($table);183}184185}186187188