@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Phriction - move "move" business logic to the editor

Summary: Ref T4029. Even more code consolidation and cleanup for the long term benefits!

Test Plan: moved a page successfully. tried to move a page to an existing page and got an error. did the two tab trick to try to move a deleted page and got an error.

Reviewers: chad, epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T4029

Differential Revision: https://secure.phabricator.com/D10812

+68 -60
+21 -59
src/applications/phriction/controller/PhrictionMoveController.php
··· 56 56 $submit_uri = $request->getRequestURI()->getPath(); 57 57 $cancel_uri = PhrictionDocument::getSlugURI($slug); 58 58 59 - $errors = array(); 60 - $error_view = null; 61 - $e_url = null; 62 - 63 - $disallowed_statuses = array( 64 - PhrictionDocumentStatus::STATUS_DELETED => true, // Silly 65 - PhrictionDocumentStatus::STATUS_MOVED => true, // Plain silly 66 - PhrictionDocumentStatus::STATUS_STUB => true, // Utterly silly 67 - ); 68 - if (isset($disallowed_statuses[$document->getStatus()])) { 69 - $error_dialog = id(new AphrontDialogView()) 70 - ->setUser($user) 71 - ->setTitle('Can not move page!') 72 - ->appendChild(pht('An already moved or deleted document '. 73 - 'can not be moved again.')) 74 - ->addCancelButton($cancel_uri); 75 - 76 - return id(new AphrontDialogResponse())->setDialog($error_dialog); 77 - } 78 - 59 + $e_url = true; 60 + $validation_exception = null; 79 61 $content = $document->getContent(); 80 62 81 - if ($request->isFormPost() && !count($errors)) { 82 - 83 - // NOTE: We use the ominpotent user because we can't let users overwrite 84 - // documents even if they can't see them. 85 - $target_document = id(new PhrictionDocumentQuery()) 86 - ->setViewer(PhabricatorUser::getOmnipotentUser()) 87 - ->withSlugs(array($target_slug)) 88 - ->needContent(true) 89 - ->executeOne(); 90 - 91 - // Considering to overwrite existing docs? Nuke this! 92 - $exists = PhrictionDocumentStatus::STATUS_EXISTS; 93 - if ($target_document && $target_document->getStatus() == $exists) { 94 - $errors[] = pht('Can not overwrite existing target document.'); 95 - $e_url = pht('Already exists.'); 96 - } 97 - 98 - if (!count($errors)) { 63 + if ($request->isFormPost()) { 99 64 100 - $editor = id(new PhrictionTransactionEditor()) 101 - ->setActor($user) 102 - ->setContentSourceFromRequest($request) 103 - ->setContinueOnNoEffect(true) 104 - ->setDescription($request->getStr('description')); 65 + $editor = id(new PhrictionTransactionEditor()) 66 + ->setActor($user) 67 + ->setContentSourceFromRequest($request) 68 + ->setContinueOnNoEffect(true) 69 + ->setDescription($request->getStr('description')); 105 70 106 - $xactions = array(); 107 - $xactions[] = id(new PhrictionTransaction()) 108 - ->setTransactionType(PhrictionTransaction::TYPE_MOVE_TO) 109 - ->setNewValue($document); 110 - if (!$target_document) { 111 - $target_document = PhrictionDocument::initializeNewDocument( 112 - $user, 113 - $target_slug); 114 - } 71 + $xactions = array(); 72 + $xactions[] = id(new PhrictionTransaction()) 73 + ->setTransactionType(PhrictionTransaction::TYPE_MOVE_TO) 74 + ->setNewValue($document); 75 + $target_document = PhrictionDocument::initializeNewDocument( 76 + $user, 77 + $target_slug); 78 + try { 115 79 $editor->applyTransactions($target_document, $xactions); 116 - 117 80 $redir_uri = PhrictionDocument::getSlugURI( 118 81 $target_document->getSlug()); 119 82 return id(new AphrontRedirectResponse())->setURI($redir_uri); 83 + } catch (PhabricatorApplicationTransactionValidationException $ex) { 84 + $validation_exception = $ex; 85 + $e_url = $ex->getShortMessage(PhrictionTransaction::TYPE_MOVE_TO); 120 86 } 121 - } 122 - 123 - if ($errors) { 124 - $error_view = id(new AphrontErrorView()) 125 - ->setErrors($errors); 126 87 } 127 88 128 89 $form = id(new PHUIFormLayoutView()) ··· 141 102 ->appendChild( 142 103 id(new AphrontFormTextControl()) 143 104 ->setLabel(pht('Edit Notes')) 144 - ->setValue($content->getDescription()) 105 + ->setValue(pht('Moving document to a new location.')) 145 106 ->setError(null) 146 107 ->setName('description')); 147 108 148 109 $dialog = id(new AphrontDialogView()) 149 110 ->setUser($user) 111 + ->setValidationException($validation_exception) 150 112 ->setTitle(pht('Move Document')) 151 113 ->appendChild($form) 152 114 ->setSubmitURI($submit_uri)
+47 -1
src/applications/phriction/editor/PhrictionTransactionEditor.php
··· 477 477 } 478 478 } 479 479 break; 480 + 481 + case PhrictionTransaction::TYPE_MOVE_TO: 482 + $source_document = $xaction->getNewValue(); 483 + switch ($source_document->getStatus()) { 484 + case PhrictionDocumentStatus::STATUS_DELETED: 485 + $e_text = pht('A deleted document can not be moved.'); 486 + break; 487 + case PhrictionDocumentStatus::STATUS_MOVED: 488 + $e_text = pht('A moved document can not be moved again.'); 489 + break; 490 + case PhrictionDocumentStatus::STATUS_STUB: 491 + $e_text = pht('A stub document can not be moved.'); 492 + break; 493 + default: 494 + $e_text = null; 495 + break; 496 + } 497 + 498 + if ($e_text) { 499 + $error = new PhabricatorApplicationTransactionValidationError( 500 + $type, 501 + pht('Can not move document.'), 502 + $e_text, 503 + $xaction); 504 + $errors[] = $error; 505 + } 506 + 507 + // NOTE: We use the ominpotent user because we can't let users 508 + // overwrite documents even if they can't see them. 509 + $target_document = id(new PhrictionDocumentQuery()) 510 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 511 + ->withSlugs(array($object->getSlug())) 512 + ->needContent(true) 513 + ->executeOne(); 514 + 515 + // Considering to overwrite existing docs? Nuke this! 516 + $exists = PhrictionDocumentStatus::STATUS_EXISTS; 517 + if ($target_document && $target_document->getStatus() == $exists) { 518 + $error = new PhabricatorApplicationTransactionValidationError( 519 + $type, 520 + pht('Can not move document.'), 521 + pht('Can not overwrite existing target document.'), 522 + $xaction); 523 + $errors[] = $error; 524 + } 525 + break; 526 + 480 527 case PhrictionTransaction::TYPE_DELETE: 481 528 switch ($object->getStatus()) { 482 529 case PhrictionDocumentStatus::STATUS_DELETED: ··· 498 545 $e_text, 499 546 $xaction); 500 547 $errors[] = $error; 501 - 502 548 break; 503 549 } 504 550 }