Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / owners / controller / PhabricatorOwnersArchiveController.php
blob47f9d87d23393f462727f21021047019e120dd63
1 <?php
3 final class PhabricatorOwnersArchiveController
4 extends PhabricatorOwnersController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $request->getViewer();
8 $id = $request->getURIData('id');
10 $package = id(new PhabricatorOwnersPackageQuery())
11 ->setViewer($viewer)
12 ->withIDs(array($id))
13 ->requireCapabilities(
14 array(
15 PhabricatorPolicyCapability::CAN_VIEW,
16 PhabricatorPolicyCapability::CAN_EDIT,
18 ->executeOne();
19 if (!$package) {
20 return new Aphront404Response();
23 $view_uri = $this->getApplicationURI('package/'.$package->getID().'/');
25 if ($request->isFormPost()) {
26 if ($package->isArchived()) {
27 $new_status = PhabricatorOwnersPackage::STATUS_ACTIVE;
28 } else {
29 $new_status = PhabricatorOwnersPackage::STATUS_ARCHIVED;
32 $xactions = array();
34 $type = PhabricatorOwnersPackageStatusTransaction::TRANSACTIONTYPE;
35 $xactions[] = id(new PhabricatorOwnersPackageTransaction())
36 ->setTransactionType($type)
37 ->setNewValue($new_status);
39 id(new PhabricatorOwnersPackageTransactionEditor())
40 ->setActor($viewer)
41 ->setContentSourceFromRequest($request)
42 ->setContinueOnNoEffect(true)
43 ->setContinueOnMissingFields(true)
44 ->applyTransactions($package, $xactions);
46 return id(new AphrontRedirectResponse())->setURI($view_uri);
49 if ($package->isArchived()) {
50 $title = pht('Activate Package');
51 $body = pht('This package will become active again.');
52 $button = pht('Activate Package');
53 } else {
54 $title = pht('Archive Package');
55 $body = pht('This package will be marked as archived.');
56 $button = pht('Archive Package');
59 return $this->newDialog()
60 ->setTitle($title)
61 ->appendChild($body)
62 ->addCancelButton($view_uri)
63 ->addSubmitButton($button);