@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.

Move Phriction MOVE_TO transaction to Modular Transactions

Summary: Moves this transaction over to modular transactions.

Test Plan: Move a document, re-title a document, try to move over an existing document.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

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

+119 -66
+2
src/__phutil_library_map__.php
··· 4617 4617 'PhrictionDocumentHeraldAdapter' => 'applications/phriction/herald/PhrictionDocumentHeraldAdapter.php', 4618 4618 'PhrictionDocumentHeraldField' => 'applications/phriction/herald/PhrictionDocumentHeraldField.php', 4619 4619 'PhrictionDocumentHeraldFieldGroup' => 'applications/phriction/herald/PhrictionDocumentHeraldFieldGroup.php', 4620 + 'PhrictionDocumentMoveToTransaction' => 'applications/phriction/xaction/PhrictionDocumentMoveToTransaction.php', 4620 4621 'PhrictionDocumentPHIDType' => 'applications/phriction/phid/PhrictionDocumentPHIDType.php', 4621 4622 'PhrictionDocumentPathHeraldField' => 'applications/phriction/herald/PhrictionDocumentPathHeraldField.php', 4622 4623 'PhrictionDocumentQuery' => 'applications/phriction/query/PhrictionDocumentQuery.php', ··· 10256 10257 'PhrictionDocumentHeraldAdapter' => 'HeraldAdapter', 10257 10258 'PhrictionDocumentHeraldField' => 'HeraldField', 10258 10259 'PhrictionDocumentHeraldFieldGroup' => 'HeraldFieldGroup', 10260 + 'PhrictionDocumentMoveToTransaction' => 'PhrictionDocumentTransactionType', 10259 10261 'PhrictionDocumentPHIDType' => 'PhabricatorPHIDType', 10260 10262 'PhrictionDocumentPathHeraldField' => 'PhrictionDocumentHeraldField', 10261 10263 'PhrictionDocumentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+4 -2
src/applications/phriction/controller/PhrictionMoveController.php
··· 64 64 65 65 $xactions = array(); 66 66 $xactions[] = id(new PhrictionTransaction()) 67 - ->setTransactionType(PhrictionTransaction::TYPE_MOVE_TO) 67 + ->setTransactionType( 68 + PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE) 68 69 ->setNewValue($document); 69 70 $target_document = id(new PhrictionDocumentQuery()) 70 71 ->setViewer(PhabricatorUser::getOmnipotentUser()) ··· 88 89 return id(new AphrontRedirectResponse())->setURI($redir_uri); 89 90 } catch (PhabricatorApplicationTransactionValidationException $ex) { 90 91 $validation_exception = $ex; 91 - $e_slug = $ex->getShortMessage(PhrictionTransaction::TYPE_MOVE_TO); 92 + $e_slug = $ex->getShortMessage( 93 + PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE); 92 94 } 93 95 } 94 96
+8 -50
src/applications/phriction/editor/PhrictionTransactionEditor.php
··· 82 82 83 83 $types[] = PhrictionTransaction::TYPE_CONTENT; 84 84 $types[] = PhrictionTransaction::TYPE_DELETE; 85 - $types[] = PhrictionTransaction::TYPE_MOVE_TO; 86 85 $types[] = PhrictionTransaction::TYPE_MOVE_AWAY; 87 86 88 87 $types[] = PhabricatorTransactions::TYPE_EDGE; ··· 104 103 } 105 104 return $this->getOldContent()->getContent(); 106 105 case PhrictionTransaction::TYPE_DELETE: 107 - case PhrictionTransaction::TYPE_MOVE_TO: 108 106 case PhrictionTransaction::TYPE_MOVE_AWAY: 109 107 return null; 110 108 } ··· 118 116 case PhrictionTransaction::TYPE_CONTENT: 119 117 case PhrictionTransaction::TYPE_DELETE: 120 118 return $xaction->getNewValue(); 121 - case PhrictionTransaction::TYPE_MOVE_TO: 119 + case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: 122 120 $document = $xaction->getNewValue(); 123 121 // grab the real object now for the sub-editor to come 124 122 $this->moveAwayDocument = $document; 125 - $dict = array( 126 - 'id' => $document->getID(), 127 - 'phid' => $document->getPHID(), 128 - 'content' => $document->getContent()->getContent(), 129 - 'title' => $document->getContent()->getTitle(), 130 - ); 131 - return $dict; 123 + return; 132 124 case PhrictionTransaction::TYPE_MOVE_AWAY: 133 125 $document = $xaction->getNewValue(); 134 126 $dict = array( ··· 150 142 case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE: 151 143 case PhrictionTransaction::TYPE_CONTENT: 152 144 case PhrictionTransaction::TYPE_DELETE: 153 - case PhrictionTransaction::TYPE_MOVE_TO: 145 + case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: 154 146 case PhrictionTransaction::TYPE_MOVE_AWAY: 155 147 return true; 156 148 } ··· 172 164 173 165 switch ($xaction->getTransactionType()) { 174 166 case PhrictionTransaction::TYPE_CONTENT: 175 - case PhrictionTransaction::TYPE_MOVE_TO: 176 - $object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS); 177 - return; 178 167 case PhrictionTransaction::TYPE_MOVE_AWAY: 179 168 $object->setStatus(PhrictionDocumentStatus::STATUS_MOVED); 180 169 return; ··· 202 191 ->setMetadataValue('contentDelete', true); 203 192 } 204 193 break; 205 - case PhrictionTransaction::TYPE_MOVE_TO: 194 + case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: 206 195 $document = $xaction->getNewValue(); 207 196 $xactions[] = id(new PhrictionTransaction()) 208 197 ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) ··· 232 221 $this->getNewContent()->setChangeType( 233 222 PhrictionChangeType::CHANGE_DELETE); 234 223 break; 235 - case PhrictionTransaction::TYPE_MOVE_TO: 236 - $dict = $xaction->getNewValue(); 237 - $this->getNewContent()->setContent($dict['content']); 238 - $this->getNewContent()->setTitle($dict['title']); 239 - $this->getNewContent()->setChangeType( 240 - PhrictionChangeType::CHANGE_MOVE_HERE); 241 - $this->getNewContent()->setChangeRef($dict['id']); 242 - break; 243 224 case PhrictionTransaction::TYPE_MOVE_AWAY: 244 225 $dict = $xaction->getNewValue(); 245 226 $this->getNewContent()->setContent(''); ··· 263 244 case PhrictionTransaction::TYPE_CONTENT: 264 245 case PhrictionTransaction::TYPE_DELETE: 265 246 case PhrictionTransaction::TYPE_MOVE_AWAY: 266 - case PhrictionTransaction::TYPE_MOVE_TO: 247 + case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: 267 248 $save_content = true; 268 249 break; 269 250 default: ··· 448 429 449 430 foreach ($xactions as $xaction) { 450 431 switch ($xaction->getTransactionType()) { 451 - case PhrictionTransaction::TYPE_MOVE_TO: 432 + case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: 452 433 $dict = $xaction->getNewValue(); 453 434 $phids[] = $dict['phid']; 454 435 break; ··· 510 491 511 492 break; 512 493 513 - case PhrictionTransaction::TYPE_MOVE_TO: 494 + case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: 514 495 $source_document = $xaction->getNewValue(); 515 - switch ($source_document->getStatus()) { 516 - case PhrictionDocumentStatus::STATUS_DELETED: 517 - $e_text = pht('A deleted document can not be moved.'); 518 - break; 519 - case PhrictionDocumentStatus::STATUS_MOVED: 520 - $e_text = pht('A moved document can not be moved again.'); 521 - break; 522 - case PhrictionDocumentStatus::STATUS_STUB: 523 - $e_text = pht('A stub document can not be moved.'); 524 - break; 525 - default: 526 - $e_text = null; 527 - break; 528 - } 529 - 530 - if ($e_text) { 531 - $error = new PhabricatorApplicationTransactionValidationError( 532 - $type, 533 - pht('Can not move document.'), 534 - $e_text, 535 - $xaction); 536 - $errors[] = $error; 537 - } 538 496 539 497 $ancestry_errors = $this->validateAncestry( 540 498 $object, ··· 611 569 return $errors; 612 570 } 613 571 614 - private function validateAncestry( 572 + public function validateAncestry( 615 573 PhabricatorLiskDAO $object, 616 574 $type, 617 575 PhabricatorApplicationTransaction $xaction,
+3 -14
src/applications/phriction/storage/PhrictionTransaction.php
··· 5 5 6 6 const TYPE_CONTENT = 'content'; 7 7 const TYPE_DELETE = 'delete'; 8 - const TYPE_MOVE_TO = 'move-to'; 9 8 const TYPE_MOVE_AWAY = 'move-away'; 10 9 11 10 const MAILTAG_TITLE = 'phriction-title'; ··· 34 33 $phids = parent::getRequiredHandlePHIDs(); 35 34 $new = $this->getNewValue(); 36 35 switch ($this->getTransactionType()) { 37 - case self::TYPE_MOVE_TO: 36 + case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: 38 37 case self::TYPE_MOVE_AWAY: 39 38 $phids[] = $new['phid']; 40 39 break; ··· 76 75 77 76 public function shouldHideForMail(array $xactions) { 78 77 switch ($this->getTransactionType()) { 79 - case self::TYPE_MOVE_TO: 78 + case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: 80 79 case self::TYPE_MOVE_AWAY: 81 80 return true; 82 81 case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE: ··· 87 86 88 87 public function shouldHideForFeed() { 89 88 switch ($this->getTransactionType()) { 90 - case self::TYPE_MOVE_TO: 89 + case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: 91 90 case self::TYPE_MOVE_AWAY: 92 91 return true; 93 92 case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE: ··· 102 101 return 1.3; 103 102 case self::TYPE_DELETE: 104 103 return 1.5; 105 - case self::TYPE_MOVE_TO: 106 104 case self::TYPE_MOVE_AWAY: 107 105 return 1.0; 108 106 } ··· 119 117 return pht('Edited'); 120 118 case self::TYPE_DELETE: 121 119 return pht('Deleted'); 122 - case self::TYPE_MOVE_TO: 123 - return pht('Moved'); 124 120 case self::TYPE_MOVE_AWAY: 125 121 return pht('Moved Away'); 126 122 } ··· 137 133 return 'fa-pencil'; 138 134 case self::TYPE_DELETE: 139 135 return 'fa-times'; 140 - case self::TYPE_MOVE_TO: 141 136 case self::TYPE_MOVE_AWAY: 142 137 return 'fa-arrows'; 143 138 } ··· 162 157 return pht( 163 158 '%s deleted this document.', 164 159 $this->renderHandleLink($author_phid)); 165 - 166 - case self::TYPE_MOVE_TO: 167 - return pht( 168 - '%s moved this document from %s', 169 - $this->renderHandleLink($author_phid), 170 - $this->renderHandleLink($new['phid'])); 171 160 172 161 case self::TYPE_MOVE_AWAY: 173 162 return pht(
+102
src/applications/phriction/xaction/PhrictionDocumentMoveToTransaction.php
··· 1 + <?php 2 + 3 + final class PhrictionDocumentMoveToTransaction 4 + extends PhrictionDocumentTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'move-to'; 7 + 8 + public function generateOldValue($object) { 9 + return null; 10 + } 11 + 12 + public function generateNewValue($object, $value) { 13 + $document = $value; 14 + $dict = array( 15 + 'id' => $document->getID(), 16 + 'phid' => $document->getPHID(), 17 + 'content' => $document->getContent()->getContent(), 18 + 'title' => $document->getContent()->getTitle(), 19 + ); 20 + return $dict; 21 + } 22 + 23 + public function applyInternalEffects($object, $value) { 24 + $object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS); 25 + $this->getEditor()->getNewContent()->setTitle($value); 26 + } 27 + 28 + public function applyExternalEffects($object, $value) { 29 + $dict = $value; 30 + $this->getEditor()->getNewContent()->setContent($dict['content']); 31 + $this->getEditor()->getNewContent()->setTitle($dict['title']); 32 + $this->getEditor()->getNewContent()->setChangeType( 33 + PhrictionChangeType::CHANGE_MOVE_HERE); 34 + $this->getEditor()->getNewContent()->setChangeRef($dict['id']); 35 + } 36 + 37 + public function getActionStrength() { 38 + return 1.0; 39 + } 40 + 41 + public function getActionName() { 42 + return pht('Moved'); 43 + } 44 + 45 + public function getTitle() { 46 + $old = $this->getOldValue(); 47 + $new = $this->getNewValue(); 48 + 49 + return pht( 50 + '%s moved this document from %s', 51 + $this->renderAuthor(), 52 + $this->renderHandle($new['phid'])); 53 + } 54 + 55 + public function getTitleForFeed() { 56 + $old = $this->getOldValue(); 57 + $new = $this->getNewValue(); 58 + 59 + return pht( 60 + '%s moved %s from %s', 61 + $this->renderAuthor(), 62 + $this->renderObject(), 63 + $this->renderHandle($new['phid'])); 64 + } 65 + 66 + public function validateTransactions($object, array $xactions) { 67 + $errors = array(); 68 + 69 + $e_text = null; 70 + foreach ($xactions as $xaction) { 71 + $source_document = $xaction->getNewValue(); 72 + switch ($source_document->getStatus()) { 73 + case PhrictionDocumentStatus::STATUS_DELETED: 74 + $e_text = pht('A deleted document can not be moved.'); 75 + break; 76 + case PhrictionDocumentStatus::STATUS_MOVED: 77 + $e_text = pht('A moved document can not be moved again.'); 78 + break; 79 + case PhrictionDocumentStatus::STATUS_STUB: 80 + $e_text = pht('A stub document can not be moved.'); 81 + break; 82 + default: 83 + $e_text = null; 84 + break; 85 + } 86 + 87 + if ($e_text !== null) { 88 + $errors[] = $this->newInvalidError($e_text); 89 + } 90 + 91 + } 92 + 93 + // TODO: Move Ancestry validation here once all types are converted. 94 + 95 + return $errors; 96 + } 97 + 98 + public function getIcon() { 99 + return 'fa-arrows'; 100 + } 101 + 102 + }