[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phragment/controller/ -> PhragmentRevertController.php (source)

   1  <?php
   2  
   3  final class PhragmentRevertController extends PhragmentController {
   4  
   5    private $dblob;
   6    private $id;
   7  
   8    public function willProcessRequest(array $data) {
   9      $this->dblob = $data['dblob'];
  10      $this->id = $data['id'];
  11    }
  12  
  13    public function processRequest() {
  14      $request = $this->getRequest();
  15      $viewer = $request->getUser();
  16  
  17      $fragment = id(new PhragmentFragmentQuery())
  18        ->setViewer($viewer)
  19        ->withPaths(array($this->dblob))
  20        ->requireCapabilities(
  21          array(
  22            PhabricatorPolicyCapability::CAN_VIEW,
  23            PhabricatorPolicyCapability::CAN_EDIT,
  24          ))
  25        ->executeOne();
  26      if ($fragment === null) {
  27        return new Aphront404Response();
  28      }
  29  
  30      $version = id(new PhragmentFragmentVersionQuery())
  31        ->setViewer($viewer)
  32        ->withFragmentPHIDs(array($fragment->getPHID()))
  33        ->withIDs(array($this->id))
  34        ->executeOne();
  35      if ($version === null) {
  36        return new Aphront404Response();
  37      }
  38  
  39      if ($request->isDialogFormPost()) {
  40        $file_phid = $version->getFilePHID();
  41  
  42        $file = null;
  43        if ($file_phid !== null) {
  44          $file = id(new PhabricatorFileQuery())
  45            ->setViewer($viewer)
  46            ->withPHIDs(array($file_phid))
  47            ->executeOne();
  48          if ($file === null) {
  49            throw new Exception(
  50              'The file associated with this version was not found.');
  51          }
  52        }
  53  
  54        if ($file === null) {
  55          $fragment->deleteFile($viewer);
  56        } else {
  57          $fragment->updateFromFile($viewer, $file);
  58        }
  59  
  60        return id(new AphrontRedirectResponse())
  61          ->setURI($this->getApplicationURI('/history/'.$this->dblob));
  62      }
  63  
  64      return $this->createDialog($fragment, $version);
  65    }
  66  
  67    function createDialog(
  68      PhragmentFragment $fragment,
  69      PhragmentFragmentVersion $version) {
  70  
  71      $request = $this->getRequest();
  72      $viewer = $request->getUser();
  73  
  74      $dialog = id(new AphrontDialogView())
  75        ->setTitle(pht('Really revert this fragment?'))
  76        ->setUser($request->getUser())
  77        ->addSubmitButton(pht('Revert'))
  78        ->addCancelButton(pht('Cancel'))
  79        ->appendParagraph(pht(
  80          'Reverting this fragment to version %d will create a new version of '.
  81          'the fragment. It will not delete any version history.',
  82          $version->getSequence(),
  83          $version->getSequence()));
  84      return id(new AphrontDialogResponse())->setDialog($dialog);
  85    }
  86  
  87  }


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