Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / subscriptions / controller / PhabricatorSubscriptionsTransactionController.php
blob777a834830b1d7d2fa132818462e176377c71478
1 <?php
3 final class PhabricatorSubscriptionsTransactionController
4 extends PhabricatorController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $request->getViewer();
8 $phid = $request->getURIData('phid');
9 $type = $request->getURIData('type');
11 $xaction = id(new PhabricatorObjectQuery())
12 ->withPHIDs(array($phid))
13 ->setViewer($viewer)
14 ->executeOne();
15 if (!$xaction) {
16 return new Aphront404Response();
19 $old = $xaction->getOldValue();
20 $new = $xaction->getNewValue();
21 switch ($type) {
22 case 'add':
23 $subscriber_phids = array_diff($new, $old);
24 break;
25 case 'rem':
26 $subscriber_phids = array_diff($old, $new);
27 break;
28 default:
29 return id(new Aphront404Response());
32 $object_phid = $xaction->getObjectPHID();
33 $author_phid = $xaction->getAuthorPHID();
34 $handle_phids = $subscriber_phids;
35 $handle_phids[] = $object_phid;
36 $handle_phids[] = $author_phid;
38 $handles = id(new PhabricatorHandleQuery())
39 ->setViewer($viewer)
40 ->withPHIDs($handle_phids)
41 ->execute();
42 $author_handle = $handles[$author_phid];
43 if (!in_array($author_phid, $subscriber_phids)) {
44 unset($handles[$author_phid]);
47 switch ($type) {
48 case 'add':
49 $title = pht(
50 'All %d subscribers added by %s',
51 count($subscriber_phids),
52 $author_handle->renderLink());
53 break;
54 case 'rem':
55 $title = pht(
56 'All %d subscribers removed by %s',
57 count($subscriber_phids),
58 $author_handle->renderLink());
59 break;
62 $dialog = id(new SubscriptionListDialogBuilder())
63 ->setViewer($viewer)
64 ->setTitle($title)
65 ->setObjectPHID($object_phid)
66 ->setHandles($handles)
67 ->buildDialog();
69 return id(new AphrontDialogResponse())->setDialog($dialog);