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();
|
|
|
|
|
|
|
|
$conn_table = new PhabricatorConduitConnectionLog();
|
|
|
|
$call_table = new PhabricatorConduitMethodCallLog();
|
|
|
|
|
|
|
|
$conn_r = $call_table->establishConnection('r');
|
|
|
|
|
|
|
|
$pager = new AphrontPagerView();
|
|
|
|
$pager->setOffset($request->getInt('page'));
|
|
|
|
$calls = $call_table->loadAllWhere(
|
|
|
|
'1 = 1 ORDER BY id DESC LIMIT %d, %d',
|
|
|
|
$pager->getOffset(),
|
|
|
|
$pager->getPageSize() + 1);
|
|
|
|
$calls = $pager->sliceResults($calls);
|
2012-01-26 21:47:23 +01:00
|
|
|
$pager->setURI(new PhutilURI('/conduit/log/'), 'page');
|
2011-12-01 00:59:02 +01:00
|
|
|
$pager->setEnableKeyboardShortcuts(true);
|
2011-01-24 18:00:29 +01:00
|
|
|
|
2011-12-01 00:17:37 +01:00
|
|
|
$min = $pager->getOffset() + 1;
|
|
|
|
$max = ($min + count($calls) - 1);
|
|
|
|
|
|
|
|
$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);
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader('Conduit Method Calls ('.$min.'-'.$max.')');
|
|
|
|
$panel->appendChild($table);
|
|
|
|
$panel->appendChild($pager);
|
2012-01-26 21:47:23 +01:00
|
|
|
|
2012-04-27 07:25:05 +02:00
|
|
|
$this->setShowSideNav(false);
|
2011-12-01 00:17:37 +01:00
|
|
|
|
|
|
|
return $this->buildStandardPageResponse(
|
2012-01-26 21:47:23 +01:00
|
|
|
$panel,
|
2011-12-01 00:17:37 +01:00
|
|
|
array(
|
|
|
|
'title' => 'Conduit Logs',
|
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');
|
|
|
|
|
2011-12-01 00:17:37 +01:00
|
|
|
$user = $this->getRequest()->getUser();
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
foreach ($calls as $call) {
|
|
|
|
$conn = idx($conns, $call->getConnectionID());
|
|
|
|
if (!$conn) {
|
|
|
|
// If there's no connection, use an empty object.
|
|
|
|
$conn = new PhabricatorConduitConnectionLog();
|
|
|
|
}
|
|
|
|
$rows[] = array(
|
|
|
|
$call->getConnectionID(),
|
2013-02-13 23:08:57 +01:00
|
|
|
phutil_escape_html($conn->getUserName()),
|
|
|
|
phutil_escape_html($call->getMethod()),
|
|
|
|
phutil_escape_html($call->getError()),
|
2011-12-01 00:17:37 +01:00
|
|
|
number_format($call->getDuration()).' us',
|
|
|
|
phabricator_datetime($call->getDateCreated(), $user),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$table = new AphrontTableView($rows);
|
|
|
|
$table->setHeaders(
|
|
|
|
array(
|
|
|
|
'Connection',
|
|
|
|
'User',
|
|
|
|
'Method',
|
|
|
|
'Error',
|
|
|
|
'Duration',
|
|
|
|
'Date',
|
|
|
|
));
|
|
|
|
$table->setColumnClasses(
|
|
|
|
array(
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'wide',
|
|
|
|
'',
|
|
|
|
'n',
|
|
|
|
'right',
|
|
|
|
));
|
|
|
|
return $table;
|
|
|
|
}
|
|
|
|
|
2011-01-24 18:00:29 +01:00
|
|
|
}
|