[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class PhrictionMoveController extends PhrictionController {
   4  
   5    public function handleRequest(AphrontRequest $request) {
   6      $viewer = $this->getViewer();
   7  
   8      $document = id(new PhrictionDocumentQuery())
   9        ->setViewer($viewer)
  10        ->withIDs(array($request->getURIData('id')))
  11        ->needContent(true)
  12        ->requireCapabilities(
  13          array(
  14            PhabricatorPolicyCapability::CAN_VIEW,
  15            PhabricatorPolicyCapability::CAN_EDIT,
  16          ))
  17        ->executeOne();
  18      if (!$document) {
  19        return new Aphront404Response();
  20      }
  21  
  22      $slug = $document->getSlug();
  23      $cancel_uri = PhrictionDocument::getSlugURI($slug);
  24  
  25      $v_slug = $slug;
  26      $e_slug = null;
  27  
  28      $v_note = '';
  29  
  30      $validation_exception = null;
  31      if ($request->isFormPost()) {
  32        $v_note = $request->getStr('description');
  33        $v_slug = $request->getStr('slug');
  34  
  35        // If what the user typed isn't what we're actually using, warn them
  36        // about it.
  37        if (strlen($v_slug)) {
  38          $normal_slug = PhabricatorSlug::normalize($v_slug);
  39          if ($normal_slug !== $v_slug) {
  40            return $this->newDialog()
  41              ->setTitle(pht('Adjust Path'))
  42              ->appendParagraph(
  43                pht(
  44                  'The path you entered (%s) is not a valid wiki document '.
  45                  'path. Paths may not contain special characters.',
  46                  phutil_tag('strong', array(), $v_slug)))
  47              ->appendParagraph(
  48                pht(
  49                  'Would you like to use the path %s instead?',
  50                  phutil_tag('strong', array(), $normal_slug)))
  51              ->addHiddenInput('slug', $normal_slug)
  52              ->addHiddenInput('description', $v_note)
  53              ->addCancelButton($cancel_uri)
  54              ->addSubmitButton(pht('Accept Path'));
  55          }
  56        }
  57  
  58        $editor = id(new PhrictionTransactionEditor())
  59          ->setActor($viewer)
  60          ->setContentSourceFromRequest($request)
  61          ->setContinueOnNoEffect(true)
  62          ->setDescription($v_note);
  63  
  64        $xactions = array();
  65        $xactions[] = id(new PhrictionTransaction())
  66          ->setTransactionType(PhrictionTransaction::TYPE_MOVE_TO)
  67          ->setNewValue($document);
  68        $target_document = PhrictionDocument::initializeNewDocument(
  69          $viewer,
  70          $v_slug);
  71        try {
  72          $editor->applyTransactions($target_document, $xactions);
  73          $redir_uri = PhrictionDocument::getSlugURI(
  74            $target_document->getSlug());
  75          return id(new AphrontRedirectResponse())->setURI($redir_uri);
  76        } catch (PhabricatorApplicationTransactionValidationException $ex) {
  77          $validation_exception = $ex;
  78          $e_slug = $ex->getShortMessage(PhrictionTransaction::TYPE_MOVE_TO);
  79        }
  80      }
  81  
  82  
  83      $form = id(new AphrontFormView())
  84        ->setUser($viewer)
  85        ->appendChild(
  86          id(new AphrontFormStaticControl())
  87            ->setLabel(pht('Title'))
  88            ->setValue($document->getContent()->getTitle()))
  89        ->appendChild(
  90          id(new AphrontFormTextControl())
  91            ->setLabel(pht('Current Path'))
  92            ->setDisabled(true)
  93            ->setValue($slug))
  94        ->appendChild(
  95          id(new AphrontFormTextControl())
  96            ->setLabel(pht('New Path'))
  97            ->setValue($v_slug)
  98            ->setError($e_slug)
  99            ->setName('slug'))
 100        ->appendChild(
 101          id(new AphrontFormTextControl())
 102            ->setLabel(pht('Edit Notes'))
 103            ->setValue($v_note)
 104            ->setName('description'));
 105  
 106      return $this->newDialog()
 107        ->setTitle(pht('Move Document'))
 108        ->setValidationException($validation_exception)
 109        ->appendForm($form)
 110        ->addSubmitButton(pht('Move Document'))
 111        ->addCancelButton($cancel_uri);
 112    }
 113  
 114  }


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