Path: blob/master/src/applications/conduit/query/PhabricatorConduitLogSearchEngine.php
12256 views
<?php12final class PhabricatorConduitLogSearchEngine3extends PhabricatorApplicationSearchEngine {45public function getResultTypeDescription() {6return pht('Conduit Logs');7}89public function getApplicationClassName() {10return 'PhabricatorConduitApplication';11}1213public function canUseInPanelContext() {14return false;15}1617public function newQuery() {18return new PhabricatorConduitLogQuery();19}2021protected function buildQueryFromParameters(array $map) {22$query = $this->newQuery();2324if ($map['callerPHIDs']) {25$query->withCallerPHIDs($map['callerPHIDs']);26}2728if ($map['methods']) {29$query->withMethods($map['methods']);30}3132if ($map['statuses']) {33$query->withMethodStatuses($map['statuses']);34}3536if ($map['epochMin'] || $map['epochMax']) {37$query->withEpochBetween(38$map['epochMin'],39$map['epochMax']);40}4142return $query;43}4445protected function buildCustomSearchFields() {46return array(47id(new PhabricatorUsersSearchField())48->setKey('callerPHIDs')49->setLabel(pht('Callers'))50->setAliases(array('caller', 'callers'))51->setDescription(pht('Find calls by specific users.')),52id(new PhabricatorSearchStringListField())53->setKey('methods')54->setLabel(pht('Methods'))55->setDescription(pht('Find calls to specific methods.')),56id(new PhabricatorSearchCheckboxesField())57->setKey('statuses')58->setLabel(pht('Method Status'))59->setAliases(array('status'))60->setDescription(61pht('Find calls to stable, unstable, or deprecated methods.'))62->setOptions(ConduitAPIMethod::getMethodStatusMap()),63id(new PhabricatorSearchDateField())64->setLabel(pht('Called After'))65->setKey('epochMin'),66id(new PhabricatorSearchDateField())67->setLabel(pht('Called Before'))68->setKey('epochMax'),69);70}7172protected function getURI($path) {73return '/conduit/log/'.$path;74}7576protected function getBuiltinQueryNames() {77$names = array();7879$viewer = $this->requireViewer();80if ($viewer->isLoggedIn()) {81$names['viewer'] = pht('My Calls');82$names['viewerdeprecated'] = pht('My Deprecated Calls');83}8485$names['all'] = pht('All Call Logs');86$names['deprecated'] = pht('Deprecated Call Logs');8788return $names;89}9091public function buildSavedQueryFromBuiltin($query_key) {92$query = $this->newSavedQuery();93$query->setQueryKey($query_key);9495$viewer = $this->requireViewer();96$viewer_phid = $viewer->getPHID();9798$deprecated = array(99ConduitAPIMethod::METHOD_STATUS_DEPRECATED,100);101102switch ($query_key) {103case 'viewer':104return $query105->setParameter('callerPHIDs', array($viewer_phid));106case 'viewerdeprecated':107return $query108->setParameter('callerPHIDs', array($viewer_phid))109->setParameter('statuses', $deprecated);110case 'deprecated':111return $query112->setParameter('statuses', $deprecated);113case 'all':114return $query;115}116117return parent::buildSavedQueryFromBuiltin($query_key);118}119120protected function newExportFields() {121$viewer = $this->requireViewer();122123return array(124id(new PhabricatorPHIDExportField())125->setKey('callerPHID')126->setLabel(pht('Caller PHID')),127id(new PhabricatorStringExportField())128->setKey('caller')129->setLabel(pht('Caller')),130id(new PhabricatorStringExportField())131->setKey('method')132->setLabel(pht('Method')),133id(new PhabricatorIntExportField())134->setKey('duration')135->setLabel(pht('Call Duration (us)')),136id(new PhabricatorStringExportField())137->setKey('error')138->setLabel(pht('Error')),139);140}141142protected function newExportData(array $logs) {143$viewer = $this->requireViewer();144145$phids = array();146foreach ($logs as $log) {147if ($log->getCallerPHID()) {148$phids[] = $log->getCallerPHID();149}150}151$handles = $viewer->loadHandles($phids);152153$export = array();154foreach ($logs as $log) {155$caller_phid = $log->getCallerPHID();156if ($caller_phid) {157$caller_name = $handles[$caller_phid]->getName();158} else {159$caller_name = null;160}161162$map = array(163'callerPHID' => $caller_phid,164'caller' => $caller_name,165'method' => $log->getMethod(),166'duration' => (int)$log->getDuration(),167'error' => $log->getError(),168);169170$export[] = $map;171}172173return $export;174}175176protected function renderResultList(177array $logs,178PhabricatorSavedQuery $query,179array $handles) {180assert_instances_of($logs, 'PhabricatorConduitMethodCallLog');181$viewer = $this->requireViewer();182183$methods = id(new PhabricatorConduitMethodQuery())184->setViewer($viewer)185->execute();186$methods = mpull($methods, null, 'getAPIMethodName');187188Javelin::initBehavior('phabricator-tooltips');189190$viewer = $this->requireViewer();191$rows = array();192foreach ($logs as $log) {193$caller_phid = $log->getCallerPHID();194195if ($caller_phid) {196$caller = $viewer->renderHandle($caller_phid);197} else {198$caller = null;199}200201$method = idx($methods, $log->getMethod());202if ($method) {203$method_status = $method->getMethodStatus();204} else {205$method_status = null;206}207208switch ($method_status) {209case ConduitAPIMethod::METHOD_STATUS_STABLE:210$status = null;211break;212case ConduitAPIMethod::METHOD_STATUS_UNSTABLE:213$status = id(new PHUIIconView())214->setIcon('fa-exclamation-triangle yellow')215->addSigil('has-tooltip')216->setMetadata(217array(218'tip' => pht('Unstable'),219));220break;221case ConduitAPIMethod::METHOD_STATUS_DEPRECATED:222$status = id(new PHUIIconView())223->setIcon('fa-exclamation-triangle red')224->addSigil('has-tooltip')225->setMetadata(226array(227'tip' => pht('Deprecated'),228));229break;230default:231$status = id(new PHUIIconView())232->setIcon('fa-question-circle')233->addSigil('has-tooltip')234->setMetadata(235array(236'tip' => pht('Unknown ("%s")', $method_status),237));238break;239}240241$rows[] = array(242$status,243$log->getMethod(),244$caller,245$log->getError(),246pht('%s us', new PhutilNumber($log->getDuration())),247phabricator_datetime($log->getDateCreated(), $viewer),248);249}250251$table = id(new AphrontTableView($rows))252->setHeaders(253array(254null,255pht('Method'),256pht('Caller'),257pht('Error'),258pht('Duration'),259pht('Date'),260))261->setColumnClasses(262array(263null,264'pri',265null,266'wide right',267null,268null,269));270271return id(new PhabricatorApplicationSearchResultView())272->setTable($table)273->setNoDataString(pht('No matching calls in log.'));274}275}276277278