Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phriction/controller/PhrictionMoveController.php
Show All 25 Lines | public function handleRequest(AphrontRequest $request) { | ||||
$e_slug = null; | $e_slug = null; | ||||
$v_note = ''; | $v_note = ''; | ||||
$validation_exception = null; | $validation_exception = null; | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$v_note = $request->getStr('description'); | $v_note = $request->getStr('description'); | ||||
$v_slug = $request->getStr('slug'); | $v_slug = $request->getStr('slug'); | ||||
$normal_slug = PhabricatorSlug::normalize($v_slug); | |||||
// If what the user typed isn't what we're actually using, warn them | // If what the user typed isn't what we're actually using, warn them | ||||
// about it. | // about it. | ||||
if (strlen($v_slug)) { | if (strlen($v_slug)) { | ||||
$normal_slug = PhabricatorSlug::normalize($v_slug); | |||||
$no_slash_slug = rtrim($normal_slug, '/'); | $no_slash_slug = rtrim($normal_slug, '/'); | ||||
if ($normal_slug !== $v_slug && $no_slash_slug !== $v_slug) { | if ($normal_slug !== $v_slug && $no_slash_slug !== $v_slug) { | ||||
return $this->newDialog() | return $this->newDialog() | ||||
->setTitle(pht('Adjust Path')) | ->setTitle(pht('Adjust Path')) | ||||
->appendParagraph( | ->appendParagraph( | ||||
pht( | pht( | ||||
'The path you entered (%s) is not a valid wiki document '. | 'The path you entered (%s) is not a valid wiki document '. | ||||
'path. Paths may not contain spaces or special characters.', | 'path. Paths may not contain spaces or special characters.', | ||||
Show All 14 Lines | if ($request->isFormPost()) { | ||||
->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true) | ||||
->setDescription($v_note); | ->setDescription($v_note); | ||||
$xactions = array(); | $xactions = array(); | ||||
$xactions[] = id(new PhrictionTransaction()) | $xactions[] = id(new PhrictionTransaction()) | ||||
->setTransactionType(PhrictionTransaction::TYPE_MOVE_TO) | ->setTransactionType(PhrictionTransaction::TYPE_MOVE_TO) | ||||
->setNewValue($document); | ->setNewValue($document); | ||||
$target_document = id(new PhrictionDocumentQuery()) | |||||
->setViewer(PhabricatorUser::getOmnipotentUser()) | |||||
->withSlugs(array($normal_slug)) | |||||
epriestley: (Do we need this `rtrim()` stuff? I think we might have fixed `PhabricatorSlug` so it mostly… | |||||
Not Done Inline ActionsYou're right, looks like this rtrim() is not needed. gd: You're right, looks like this `rtrim()` is not needed. | |||||
->needContent(true) | |||||
Done Inline Actions(Does this actually needContent()? Does getStatus() rely on it? I don't remember offhand..) epriestley: (Does this actually `needContent()`? Does `getStatus()` rely on it? I don't remember offhand..) | |||||
Not Done Inline ActionsneedContent() is needed because getContent() is called down the line. gd: `needContent()` is needed because `getContent()` is called down the line. | |||||
->requireCapabilities( | |||||
array( | |||||
PhabricatorPolicyCapability::CAN_VIEW, | |||||
PhabricatorPolicyCapability::CAN_EDIT, | |||||
)) | |||||
->executeOne(); | |||||
if (!$target_document) { | |||||
$target_document = PhrictionDocument::initializeNewDocument( | $target_document = PhrictionDocument::initializeNewDocument( | ||||
$viewer, | $viewer, | ||||
$v_slug); | $v_slug); | ||||
} | |||||
try { | try { | ||||
$editor->applyTransactions($target_document, $xactions); | $editor->applyTransactions($target_document, $xactions); | ||||
$redir_uri = PhrictionDocument::getSlugURI( | $redir_uri = PhrictionDocument::getSlugURI( | ||||
$target_document->getSlug()); | $target_document->getSlug()); | ||||
return id(new AphrontRedirectResponse())->setURI($redir_uri); | return id(new AphrontRedirectResponse())->setURI($redir_uri); | ||||
} catch (PhabricatorApplicationTransactionValidationException $ex) { | } catch (PhabricatorApplicationTransactionValidationException $ex) { | ||||
$validation_exception = $ex; | $validation_exception = $ex; | ||||
$e_slug = $ex->getShortMessage(PhrictionTransaction::TYPE_MOVE_TO); | $e_slug = $ex->getShortMessage(PhrictionTransaction::TYPE_MOVE_TO); | ||||
Show All 36 Lines |
(Do we need this rtrim() stuff? I think we might have fixed PhabricatorSlug so it mostly works correctly.)