[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class PhragmentCreateController extends PhragmentController {
   4  
   5    private $dblob;
   6  
   7    public function willProcessRequest(array $data) {
   8      $this->dblob = idx($data, 'dblob', '');
   9    }
  10  
  11    public function processRequest() {
  12      $request = $this->getRequest();
  13      $viewer = $request->getUser();
  14  
  15      $parent = null;
  16      $parents = $this->loadParentFragments($this->dblob);
  17      if ($parents === null) {
  18        return new Aphront404Response();
  19      }
  20      if (count($parents) !== 0) {
  21        $parent = idx($parents, count($parents) - 1, null);
  22      }
  23  
  24      $parent_path = '';
  25      if ($parent !== null) {
  26        $parent_path = $parent->getPath();
  27      }
  28      $parent_path = trim($parent_path, '/');
  29  
  30      $fragment = id(new PhragmentFragment());
  31  
  32      $error_view = null;
  33  
  34      if ($request->isFormPost()) {
  35        $errors = array();
  36  
  37        $v_name = $request->getStr('name');
  38        $v_fileid = $request->getInt('fileID');
  39        $v_viewpolicy = $request->getStr('viewPolicy');
  40        $v_editpolicy = $request->getStr('editPolicy');
  41  
  42        if (strpos($v_name, '/') !== false) {
  43          $errors[] = pht('The fragment name can not contain \'/\'.');
  44        }
  45  
  46        $file = id(new PhabricatorFile())->load($v_fileid);
  47        if ($file === null) {
  48          $errors[] = pht('The specified file doesn\'t exist.');
  49        }
  50  
  51        if (!count($errors)) {
  52          $depth = 1;
  53          if ($parent !== null) {
  54            $depth = $parent->getDepth() + 1;
  55          }
  56  
  57          PhragmentFragment::createFromFile(
  58            $viewer,
  59            $file,
  60            trim($parent_path.'/'.$v_name, '/'),
  61            $v_viewpolicy,
  62            $v_editpolicy);
  63  
  64          return id(new AphrontRedirectResponse())
  65            ->setURI('/phragment/browse/'.trim($parent_path.'/'.$v_name, '/'));
  66        } else {
  67          $error_view = id(new AphrontErrorView())
  68            ->setErrors($errors)
  69            ->setTitle(pht('Errors while creating fragment'));
  70        }
  71      }
  72  
  73      $policies = id(new PhabricatorPolicyQuery())
  74        ->setViewer($viewer)
  75        ->setObject($fragment)
  76        ->execute();
  77  
  78      $form = id(new AphrontFormView())
  79        ->setUser($viewer)
  80        ->appendChild(
  81          id(new AphrontFormTextControl())
  82            ->setLabel(pht('Parent Path'))
  83            ->setDisabled(true)
  84            ->setValue('/'.trim($parent_path.'/', '/')))
  85        ->appendChild(
  86          id(new AphrontFormTextControl())
  87            ->setLabel(pht('Name'))
  88            ->setName('name'))
  89        ->appendChild(
  90          id(new AphrontFormTextControl())
  91            ->setLabel(pht('File ID'))
  92            ->setName('fileID'))
  93        ->appendChild(
  94          id(new AphrontFormPolicyControl())
  95            ->setUser($viewer)
  96            ->setName('viewPolicy')
  97            ->setPolicyObject($fragment)
  98            ->setPolicies($policies)
  99            ->setCapability(PhabricatorPolicyCapability::CAN_VIEW))
 100        ->appendChild(
 101          id(new AphrontFormPolicyControl())
 102            ->setUser($viewer)
 103            ->setName('editPolicy')
 104            ->setPolicyObject($fragment)
 105            ->setPolicies($policies)
 106            ->setCapability(PhabricatorPolicyCapability::CAN_EDIT))
 107        ->appendChild(
 108          id(new AphrontFormSubmitControl())
 109            ->setValue(pht('Create Fragment'))
 110            ->addCancelButton(
 111              $this->getApplicationURI('browse/'.$parent_path)));
 112  
 113      $crumbs = $this->buildApplicationCrumbsWithPath($parents);
 114      $crumbs->addTextCrumb(pht('Create Fragment'));
 115  
 116      $box = id(new PHUIObjectBoxView())
 117        ->setHeaderText('Create Fragment')
 118        ->setValidationException(null)
 119        ->setForm($form);
 120  
 121      return $this->buildApplicationPage(
 122        array(
 123          $crumbs,
 124          $this->renderConfigurationWarningIfRequired(),
 125          $box,
 126        ),
 127        array(
 128          'title' => pht('Create Fragment'),
 129        ));
 130    }
 131  
 132  }


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