@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<?php
2
3final 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}