1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-11 15:21:03 +01:00

Allow XHProf profiles to be drag-and-dropped to upload them

Summary: Ref T12297. This could be fancier, but should make pulling profiles off `admin.phacility.com` significantly more realistic.

Test Plan: Dragged and dropped some profiles to upload them, then reviewed them via web UI.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12297

Differential Revision: https://secure.phabricator.com/D17401
This commit is contained in:
epriestley 2017-02-23 10:39:04 -08:00
parent 4254702271
commit ee2d8ce94b
5 changed files with 106 additions and 7 deletions

View file

@ -4126,6 +4126,7 @@ phutil_register_library_map(array(
'PhabricatorXHProfApplication' => 'applications/xhprof/application/PhabricatorXHProfApplication.php',
'PhabricatorXHProfController' => 'applications/xhprof/controller/PhabricatorXHProfController.php',
'PhabricatorXHProfDAO' => 'applications/xhprof/storage/PhabricatorXHProfDAO.php',
'PhabricatorXHProfDropController' => 'applications/xhprof/controller/PhabricatorXHProfDropController.php',
'PhabricatorXHProfProfileController' => 'applications/xhprof/controller/PhabricatorXHProfProfileController.php',
'PhabricatorXHProfProfileSymbolView' => 'applications/xhprof/view/PhabricatorXHProfProfileSymbolView.php',
'PhabricatorXHProfProfileTopLevelView' => 'applications/xhprof/view/PhabricatorXHProfProfileTopLevelView.php',
@ -9440,6 +9441,7 @@ phutil_register_library_map(array(
'PhabricatorXHProfApplication' => 'PhabricatorApplication',
'PhabricatorXHProfController' => 'PhabricatorController',
'PhabricatorXHProfDAO' => 'PhabricatorLiskDAO',
'PhabricatorXHProfDropController' => 'PhabricatorXHProfController',
'PhabricatorXHProfProfileController' => 'PhabricatorXHProfController',
'PhabricatorXHProfProfileSymbolView' => 'PhabricatorXHProfProfileView',
'PhabricatorXHProfProfileTopLevelView' => 'PhabricatorXHProfProfileView',

View file

@ -32,6 +32,7 @@ final class PhabricatorXHProfApplication extends PhabricatorApplication {
'' => 'PhabricatorXHProfSampleListController',
'list/(?P<view>[^/]+)/' => 'PhabricatorXHProfSampleListController',
'profile/(?P<phid>[^/]+)/' => 'PhabricatorXHProfProfileController',
'import/drop/' => 'PhabricatorXHProfDropController',
),
);
}

View file

@ -0,0 +1,54 @@
<?php
final class PhabricatorXHProfDropController
extends PhabricatorXHProfController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
if (!$request->validateCSRF()) {
return new Aphront400Response();
}
$cancel_uri = $this->getApplicationURI();
$ids = $request->getStrList('h');
if ($ids) {
$files = id(new PhabricatorFileQuery())
->setViewer($viewer)
->withIDs($ids)
->setRaisePolicyExceptions(true)
->execute();
} else {
$files = array();
}
if (!$files) {
return $this->newDialog()
->setTitle(pht('Nothing Uploaded'))
->appendParagraph(
pht('Drag and drop .xhprof files to import them.'))
->addCancelButton($cancel_uri, pht('Done'));
}
$samples = array();
foreach ($files as $file) {
$sample = PhabricatorXHProfSample::initializeNewSample()
->setFilePHID($file->getPHID())
->setUserPHID($viewer->getPHID())
->save();
$samples[] = $sample;
}
if (count($samples) == 1) {
$event = head($samples);
$next_uri = $event->getURI();
} else {
$next_uri = $this->getApplicationURI();
}
return id(new AphrontRedirectResponse())->setURI($next_uri);
}
}

View file

@ -63,10 +63,13 @@ final class PhabricatorXHProfSampleSearchEngine
$item = id(new PHUIObjectItemView())
->setObjectName($sample->getID())
->setHeader($sample->getRequestPath())
->setHref($this->getApplicationURI('profile/'.$file_phid.'/'))
->addAttribute(
number_format($sample->getUsTotal())." \xCE\xBCs");
->setHeader($sample->getDisplayName())
->setHref($sample->getURI());
$us_total = $sample->getUsTotal();
if ($us_total) {
$item->addAttribute(pht("%s \xCE\xBCs", new PhutilNumber($us_total)));
}
if ($sample->getController()) {
$item->addAttribute($sample->getController());
@ -88,10 +91,30 @@ final class PhabricatorXHProfSampleSearchEngine
$list->addItem($item);
}
$result = new PhabricatorApplicationSearchResultView();
$result->setObjectList($list);
return $this->newResultView()
->setObjectList($list);
}
return $result;
private function newResultView($content = null) {
// If we aren't rendering a dashboard panel, activate global drag-and-drop
// so you can import profiles by dropping them into the list.
if (!$this->isPanelContext()) {
$drop_upload = id(new PhabricatorGlobalUploadTargetView())
->setViewer($this->requireViewer())
->setHintText("\xE2\x87\xAA ".pht('Drop .xhprof Files to Import'))
->setSubmitURI('/xhprof/import/drop/')
->setViewPolicy(PhabricatorPolicies::POLICY_NOONE);
$content = array(
$drop_upload,
$content,
);
}
return id(new PhabricatorApplicationSearchResultView())
->setContent($content);
}
}

View file

@ -12,6 +12,12 @@ final class PhabricatorXHProfSample
protected $controller;
protected $userPHID;
public static function initializeNewSample() {
return id(new self())
->setUsTotal(0)
->setSampleRate(0);
}
protected function getConfiguration() {
return array(
self::CONFIG_COLUMN_SCHEMA => array(
@ -31,6 +37,19 @@ final class PhabricatorXHProfSample
) + parent::getConfiguration();
}
public function getURI() {
return '/xhprof/profile/'.$this->getFilePHID().'/';
}
public function getDisplayName() {
$request_path = $this->getRequestPath();
if (strlen($request_path)) {
return $request_path;
}
return pht('Unnamed Sample');
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */