@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
at recaptime-dev/main 66 lines 1.8 kB view raw
1<?php 2 3final class PhabricatorSlowvoteCloseController 4 extends PhabricatorSlowvoteController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $viewer = $request->getViewer(); 8 $id = $request->getURIData('id'); 9 10 $poll = id(new PhabricatorSlowvoteQuery()) 11 ->setViewer($viewer) 12 ->withIDs(array($id)) 13 ->requireCapabilities( 14 array( 15 PhabricatorPolicyCapability::CAN_VIEW, 16 PhabricatorPolicyCapability::CAN_EDIT, 17 )) 18 ->executeOne(); 19 if (!$poll) { 20 return new Aphront404Response(); 21 } 22 23 $close_uri = $poll->getURI(); 24 25 if ($request->isFormPost()) { 26 if ($poll->isClosed()) { 27 $new_status = SlowvotePollStatus::STATUS_OPEN; 28 } else { 29 $new_status = SlowvotePollStatus::STATUS_CLOSED; 30 } 31 32 $xactions = array(); 33 34 $xactions[] = id(new PhabricatorSlowvoteTransaction()) 35 ->setTransactionType( 36 PhabricatorSlowvoteStatusTransaction::TRANSACTIONTYPE) 37 ->setNewValue($new_status); 38 39 id(new PhabricatorSlowvoteEditor()) 40 ->setActor($viewer) 41 ->setContentSourceFromRequest($request) 42 ->setContinueOnNoEffect(true) 43 ->setContinueOnMissingFields(true) 44 ->applyTransactions($poll, $xactions); 45 46 return id(new AphrontRedirectResponse())->setURI($close_uri); 47 } 48 49 if ($poll->isClosed()) { 50 $title = pht('Reopen Poll'); 51 $content = pht('Are you sure you want to reopen the poll?'); 52 $submit = pht('Reopen'); 53 } else { 54 $title = pht('Close Poll'); 55 $content = pht('Are you sure you want to close the poll?'); 56 $submit = pht('Close'); 57 } 58 59 return $this->newDialog() 60 ->setTitle($title) 61 ->appendChild($content) 62 ->addSubmitButton($submit) 63 ->addCancelButton($close_uri); 64 } 65 66}