Differential D14630 Diff 35407 src/applications/subscriptions/controller/PhabricatorSubscriptionsTransactionController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/subscriptions/controller/PhabricatorSubscriptionsTransactionController.php
| <?php | <?php | ||||
| final class PhabricatorSubscriptionsTransactionController | final class PhabricatorSubscriptionsTransactionController | ||||
| extends PhabricatorController { | extends PhabricatorController { | ||||
| private $phid; | public function handleRequest(AphrontRequest $request) { | ||||
| private $changeType; | $viewer = $request->getViewer(); | ||||
| $phid = $request->getURIData('phid'); | |||||
| public function willProcessRequest(array $data) { | $type = $request->getURIData('type'); | ||||
| $this->phid = idx($data, 'phid'); | |||||
| $this->changeType = idx($data, 'type'); | |||||
| } | |||||
| public function processRequest() { | |||||
| $request = $this->getRequest(); | |||||
| $viewer = $request->getUser(); | |||||
| $xaction_phid = $this->phid; | |||||
| $xaction = id(new PhabricatorObjectQuery()) | $xaction = id(new PhabricatorObjectQuery()) | ||||
| ->withPHIDs(array($xaction_phid)) | ->withPHIDs(array($phid)) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| if (!$xaction) { | if (!$xaction) { | ||||
| return new Aphront404Response(); | return new Aphront404Response(); | ||||
| } | } | ||||
| $old = $xaction->getOldValue(); | $old = $xaction->getOldValue(); | ||||
| $new = $xaction->getNewValue(); | $new = $xaction->getNewValue(); | ||||
| switch ($this->changeType) { | switch ($type) { | ||||
| case 'add': | case 'add': | ||||
| $subscriber_phids = array_diff($new, $old); | $subscriber_phids = array_diff($new, $old); | ||||
| break; | break; | ||||
| case 'rem': | case 'rem': | ||||
| $subscriber_phids = array_diff($old, $new); | $subscriber_phids = array_diff($old, $new); | ||||
| break; | break; | ||||
| default: | default: | ||||
| return id(new Aphront404Response()); | return id(new Aphront404Response()); | ||||
| Show All 9 Lines | $handles = id(new PhabricatorHandleQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withPHIDs($handle_phids) | ->withPHIDs($handle_phids) | ||||
| ->execute(); | ->execute(); | ||||
| $author_handle = $handles[$author_phid]; | $author_handle = $handles[$author_phid]; | ||||
| if (!in_array($author_phid, $subscriber_phids)) { | if (!in_array($author_phid, $subscriber_phids)) { | ||||
| unset($handles[$author_phid]); | unset($handles[$author_phid]); | ||||
| } | } | ||||
| switch ($this->changeType) { | switch ($type) { | ||||
| case 'add': | case 'add': | ||||
| $title = pht( | $title = pht( | ||||
| 'All %d subscribers added by %s', | 'All %d subscribers added by %s', | ||||
| count($subscriber_phids), | count($subscriber_phids), | ||||
| $author_handle->renderLink()); | $author_handle->renderLink()); | ||||
| break; | break; | ||||
| case 'rem': | case 'rem': | ||||
| $title = pht( | $title = pht( | ||||
| Show All 17 Lines | |||||