[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phriction/controller/ -> PhrictionDeleteController.php (source)

   1  <?php
   2  
   3  final class PhrictionDeleteController extends PhrictionController {
   4  
   5    private $id;
   6  
   7    public function willProcessRequest(array $data) {
   8      $this->id = $data['id'];
   9    }
  10  
  11    public function processRequest() {
  12      $request = $this->getRequest();
  13      $user = $request->getUser();
  14  
  15      $document = id(new PhrictionDocumentQuery())
  16        ->setViewer($user)
  17        ->withIDs(array($this->id))
  18        ->needContent(true)
  19        ->requireCapabilities(
  20          array(
  21            PhabricatorPolicyCapability::CAN_EDIT,
  22            PhabricatorPolicyCapability::CAN_VIEW,
  23          ))
  24        ->executeOne();
  25      if (!$document) {
  26        return new Aphront404Response();
  27      }
  28  
  29      $document_uri = PhrictionDocument::getSlugURI($document->getSlug());
  30  
  31      $e_text = null;
  32      if ($request->isFormPost()) {
  33          $xactions = array();
  34          $xactions[] = id(new PhrictionTransaction())
  35            ->setTransactionType(PhrictionTransaction::TYPE_DELETE)
  36            ->setNewValue(true);
  37  
  38          $editor = id(new PhrictionTransactionEditor())
  39            ->setActor($user)
  40            ->setContentSourceFromRequest($request)
  41            ->setContinueOnNoEffect(true);
  42          try {
  43            $editor->applyTransactions($document, $xactions);
  44            return id(new AphrontRedirectResponse())->setURI($document_uri);
  45          } catch (PhabricatorApplicationTransactionValidationException $ex) {
  46            $e_text = phutil_implode_html("\n", $ex->getErrorMessages());
  47          }
  48      }
  49  
  50      if ($e_text) {
  51        $dialog = id(new AphrontDialogView())
  52          ->setUser($user)
  53          ->setTitle(pht('Can Not Delete Document!'))
  54          ->appendChild($e_text)
  55          ->addCancelButton($document_uri);
  56      } else {
  57        $dialog = id(new AphrontDialogView())
  58          ->setUser($user)
  59          ->setTitle(pht('Delete Document?'))
  60          ->appendChild(
  61            pht('Really delete this document? You can recover it later by '.
  62            'reverting to a previous version.'))
  63          ->addSubmitButton(pht('Delete'))
  64          ->addCancelButton($document_uri);
  65      }
  66  
  67      return id(new AphrontDialogResponse())->setDialog($dialog);
  68    }
  69  
  70  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1