@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+106 -7
+2
src/__phutil_library_map__.php
··· 4126 4126 'PhabricatorXHProfApplication' => 'applications/xhprof/application/PhabricatorXHProfApplication.php', 4127 4127 'PhabricatorXHProfController' => 'applications/xhprof/controller/PhabricatorXHProfController.php', 4128 4128 'PhabricatorXHProfDAO' => 'applications/xhprof/storage/PhabricatorXHProfDAO.php', 4129 + 'PhabricatorXHProfDropController' => 'applications/xhprof/controller/PhabricatorXHProfDropController.php', 4129 4130 'PhabricatorXHProfProfileController' => 'applications/xhprof/controller/PhabricatorXHProfProfileController.php', 4130 4131 'PhabricatorXHProfProfileSymbolView' => 'applications/xhprof/view/PhabricatorXHProfProfileSymbolView.php', 4131 4132 'PhabricatorXHProfProfileTopLevelView' => 'applications/xhprof/view/PhabricatorXHProfProfileTopLevelView.php', ··· 9440 9441 'PhabricatorXHProfApplication' => 'PhabricatorApplication', 9441 9442 'PhabricatorXHProfController' => 'PhabricatorController', 9442 9443 'PhabricatorXHProfDAO' => 'PhabricatorLiskDAO', 9444 + 'PhabricatorXHProfDropController' => 'PhabricatorXHProfController', 9443 9445 'PhabricatorXHProfProfileController' => 'PhabricatorXHProfController', 9444 9446 'PhabricatorXHProfProfileSymbolView' => 'PhabricatorXHProfProfileView', 9445 9447 'PhabricatorXHProfProfileTopLevelView' => 'PhabricatorXHProfProfileView',
+1
src/applications/xhprof/application/PhabricatorXHProfApplication.php
··· 32 32 '' => 'PhabricatorXHProfSampleListController', 33 33 'list/(?P<view>[^/]+)/' => 'PhabricatorXHProfSampleListController', 34 34 'profile/(?P<phid>[^/]+)/' => 'PhabricatorXHProfProfileController', 35 + 'import/drop/' => 'PhabricatorXHProfDropController', 35 36 ), 36 37 ); 37 38 }
+54
src/applications/xhprof/controller/PhabricatorXHProfDropController.php
··· 1 + <?php 2 + 3 + final class PhabricatorXHProfDropController 4 + extends PhabricatorXHProfController { 5 + 6 + public function handleRequest(AphrontRequest $request) { 7 + $viewer = $request->getViewer(); 8 + 9 + if (!$request->validateCSRF()) { 10 + return new Aphront400Response(); 11 + } 12 + 13 + $cancel_uri = $this->getApplicationURI(); 14 + 15 + $ids = $request->getStrList('h'); 16 + if ($ids) { 17 + $files = id(new PhabricatorFileQuery()) 18 + ->setViewer($viewer) 19 + ->withIDs($ids) 20 + ->setRaisePolicyExceptions(true) 21 + ->execute(); 22 + } else { 23 + $files = array(); 24 + } 25 + 26 + if (!$files) { 27 + return $this->newDialog() 28 + ->setTitle(pht('Nothing Uploaded')) 29 + ->appendParagraph( 30 + pht('Drag and drop .xhprof files to import them.')) 31 + ->addCancelButton($cancel_uri, pht('Done')); 32 + } 33 + 34 + $samples = array(); 35 + foreach ($files as $file) { 36 + $sample = PhabricatorXHProfSample::initializeNewSample() 37 + ->setFilePHID($file->getPHID()) 38 + ->setUserPHID($viewer->getPHID()) 39 + ->save(); 40 + 41 + $samples[] = $sample; 42 + } 43 + 44 + if (count($samples) == 1) { 45 + $event = head($samples); 46 + $next_uri = $event->getURI(); 47 + } else { 48 + $next_uri = $this->getApplicationURI(); 49 + } 50 + 51 + return id(new AphrontRedirectResponse())->setURI($next_uri); 52 + } 53 + 54 + }
+30 -7
src/applications/xhprof/query/PhabricatorXHProfSampleSearchEngine.php
··· 63 63 64 64 $item = id(new PHUIObjectItemView()) 65 65 ->setObjectName($sample->getID()) 66 - ->setHeader($sample->getRequestPath()) 67 - ->setHref($this->getApplicationURI('profile/'.$file_phid.'/')) 68 - ->addAttribute( 69 - number_format($sample->getUsTotal())." \xCE\xBCs"); 66 + ->setHeader($sample->getDisplayName()) 67 + ->setHref($sample->getURI()); 68 + 69 + $us_total = $sample->getUsTotal(); 70 + if ($us_total) { 71 + $item->addAttribute(pht("%s \xCE\xBCs", new PhutilNumber($us_total))); 72 + } 70 73 71 74 if ($sample->getController()) { 72 75 $item->addAttribute($sample->getController()); ··· 88 91 $list->addItem($item); 89 92 } 90 93 91 - $result = new PhabricatorApplicationSearchResultView(); 92 - $result->setObjectList($list); 94 + return $this->newResultView() 95 + ->setObjectList($list); 96 + } 97 + 98 + 99 + private function newResultView($content = null) { 100 + // If we aren't rendering a dashboard panel, activate global drag-and-drop 101 + // so you can import profiles by dropping them into the list. 93 102 94 - return $result; 103 + if (!$this->isPanelContext()) { 104 + $drop_upload = id(new PhabricatorGlobalUploadTargetView()) 105 + ->setViewer($this->requireViewer()) 106 + ->setHintText("\xE2\x87\xAA ".pht('Drop .xhprof Files to Import')) 107 + ->setSubmitURI('/xhprof/import/drop/') 108 + ->setViewPolicy(PhabricatorPolicies::POLICY_NOONE); 109 + 110 + $content = array( 111 + $drop_upload, 112 + $content, 113 + ); 114 + } 115 + 116 + return id(new PhabricatorApplicationSearchResultView()) 117 + ->setContent($content); 95 118 } 96 119 97 120 }
+19
src/applications/xhprof/storage/PhabricatorXHProfSample.php
··· 12 12 protected $controller; 13 13 protected $userPHID; 14 14 15 + public static function initializeNewSample() { 16 + return id(new self()) 17 + ->setUsTotal(0) 18 + ->setSampleRate(0); 19 + } 20 + 15 21 protected function getConfiguration() { 16 22 return array( 17 23 self::CONFIG_COLUMN_SCHEMA => array( ··· 29 35 ), 30 36 ), 31 37 ) + parent::getConfiguration(); 38 + } 39 + 40 + public function getURI() { 41 + return '/xhprof/profile/'.$this->getFilePHID().'/'; 42 + } 43 + 44 + public function getDisplayName() { 45 + $request_path = $this->getRequestPath(); 46 + if (strlen($request_path)) { 47 + return $request_path; 48 + } 49 + 50 + return pht('Unnamed Sample'); 32 51 } 33 52 34 53