2011-01-24 18:00:29 +01:00
|
|
|
<?php
|
|
|
|
|
2011-07-04 21:03:36 +02:00
|
|
|
/**
|
|
|
|
* @group conduit
|
|
|
|
*/
|
2012-03-10 00:46:25 +01:00
|
|
|
final class PhabricatorConduitLogController
|
|
|
|
extends PhabricatorConduitController {
|
2011-01-24 18:00:29 +01:00
|
|
|
|
|
|
|
public function processRequest() {
|
2011-12-01 00:17:37 +01:00
|
|
|
$request = $this->getRequest();
|
2013-07-01 21:37:34 +02:00
|
|
|
$viewer = $request->getUser();
|
2011-12-01 00:17:37 +01:00
|
|
|
|
|
|
|
$conn_table = new PhabricatorConduitConnectionLog();
|
|
|
|
$call_table = new PhabricatorConduitMethodCallLog();
|
|
|
|
|
|
|
|
$conn_r = $call_table->establishConnection('r');
|
|
|
|
|
2013-07-01 21:37:34 +02:00
|
|
|
$pager = new AphrontCursorPagerView();
|
|
|
|
$pager->readFromRequest($request);
|
|
|
|
$pager->setPageSize(500);
|
2011-01-24 18:00:29 +01:00
|
|
|
|
2013-07-01 21:37:34 +02:00
|
|
|
$query = id(new PhabricatorConduitLogQuery())
|
|
|
|
->setViewer($viewer);
|
|
|
|
|
|
|
|
$methods = $request->getStrList('methods');
|
|
|
|
if ($methods) {
|
|
|
|
$query->withMethods($methods);
|
|
|
|
}
|
|
|
|
|
|
|
|
$calls = $query->executeWithCursorPager($pager);
|
2011-12-01 00:17:37 +01:00
|
|
|
|
|
|
|
$conn_ids = array_filter(mpull($calls, 'getConnectionID'));
|
|
|
|
$conns = array();
|
|
|
|
if ($conn_ids) {
|
|
|
|
$conns = $conn_table->loadAllWhere(
|
|
|
|
'id IN (%Ld)',
|
|
|
|
$conn_ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
$table = $this->renderCallTable($calls, $conns);
|
2012-01-26 21:47:23 +01:00
|
|
|
|
2013-07-01 21:36:34 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
->setName(pht('Call Logs')));
|
2011-12-01 00:17:37 +01:00
|
|
|
|
2013-07-01 21:36:34 +02:00
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
2013-07-01 21:37:34 +02:00
|
|
|
$table,
|
|
|
|
$pager,
|
2013-07-01 21:36:34 +02:00
|
|
|
),
|
2011-12-01 00:17:37 +01:00
|
|
|
array(
|
|
|
|
'title' => 'Conduit Logs',
|
2013-07-01 21:37:34 +02:00
|
|
|
'device' => true,
|
2011-01-24 18:00:29 +01:00
|
|
|
));
|
|
|
|
}
|
2011-12-01 00:17:37 +01:00
|
|
|
|
|
|
|
private function renderCallTable(array $calls, array $conns) {
|
2012-04-03 21:10:45 +02:00
|
|
|
assert_instances_of($calls, 'PhabricatorConduitMethodCallLog');
|
|
|
|
assert_instances_of($conns, 'PhabricatorConduitConnectionLog');
|
|
|
|
|
2013-07-01 21:37:34 +02:00
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
|
|
|
$methods = id(new PhabricatorConduitMethodQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->execute();
|
|
|
|
$methods = mpull($methods, null, 'getAPIMethodName');
|
2011-12-01 00:17:37 +01:00
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
foreach ($calls as $call) {
|
|
|
|
$conn = idx($conns, $call->getConnectionID());
|
2013-07-01 21:37:34 +02:00
|
|
|
if ($conn) {
|
|
|
|
$name = $conn->getUserName();
|
|
|
|
$client = ' (via '.$conn->getClient().')';
|
|
|
|
} else {
|
|
|
|
$name = null;
|
|
|
|
$client = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$method = idx($methods, $call->getMethod());
|
|
|
|
if ($method) {
|
|
|
|
switch ($method->getMethodStatus()) {
|
|
|
|
case ConduitAPIMethod::METHOD_STATUS_STABLE:
|
|
|
|
$status = null;
|
|
|
|
break;
|
|
|
|
case ConduitAPIMethod::METHOD_STATUS_UNSTABLE:
|
|
|
|
$status = pht('Unstable');
|
|
|
|
break;
|
|
|
|
case ConduitAPIMethod::METHOD_STATUS_DEPRECATED:
|
|
|
|
$status = pht('Deprecated');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$status = pht('Unknown');
|
2011-12-01 00:17:37 +01:00
|
|
|
}
|
2013-07-01 21:37:34 +02:00
|
|
|
|
2011-12-01 00:17:37 +01:00
|
|
|
$rows[] = array(
|
|
|
|
$call->getConnectionID(),
|
2013-07-01 21:37:34 +02:00
|
|
|
$name,
|
|
|
|
array($call->getMethod(), $client),
|
|
|
|
$status,
|
2013-02-13 23:50:15 +01:00
|
|
|
$call->getError(),
|
2011-12-01 00:17:37 +01:00
|
|
|
number_format($call->getDuration()).' us',
|
2013-07-01 21:37:34 +02:00
|
|
|
phabricator_datetime($call->getDateCreated(), $viewer),
|
2011-12-01 00:17:37 +01:00
|
|
|
);
|
|
|
|
}
|
2013-07-01 21:37:34 +02:00
|
|
|
|
|
|
|
$table = id(new AphrontTableView($rows))
|
|
|
|
->setDeviceReadyTable(true);
|
|
|
|
|
2011-12-01 00:17:37 +01:00
|
|
|
$table->setHeaders(
|
|
|
|
array(
|
|
|
|
'Connection',
|
|
|
|
'User',
|
|
|
|
'Method',
|
2013-07-01 21:37:34 +02:00
|
|
|
'Status',
|
2011-12-01 00:17:37 +01:00
|
|
|
'Error',
|
|
|
|
'Duration',
|
|
|
|
'Date',
|
|
|
|
));
|
|
|
|
$table->setColumnClasses(
|
|
|
|
array(
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'wide',
|
|
|
|
'',
|
2013-07-01 21:37:34 +02:00
|
|
|
'',
|
2011-12-01 00:17:37 +01:00
|
|
|
'n',
|
|
|
|
'right',
|
|
|
|
));
|
|
|
|
return $table;
|
|
|
|
}
|
|
|
|
|
2011-01-24 18:00:29 +01:00
|
|
|
}
|