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

Update Phriction Delete to modular transactions

Summary: Ref T12625. Updates to modular transactions

Test Plan: Delete a document, restore a document, see feed story.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T12625

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

+95 -63
+2
src/__phutil_library_map__.php
··· 4635 4635 'PhrictionDocumentAuthorHeraldField' => 'applications/phriction/herald/PhrictionDocumentAuthorHeraldField.php', 4636 4636 'PhrictionDocumentContentHeraldField' => 'applications/phriction/herald/PhrictionDocumentContentHeraldField.php', 4637 4637 'PhrictionDocumentController' => 'applications/phriction/controller/PhrictionDocumentController.php', 4638 + 'PhrictionDocumentDeleteTransaction' => 'applications/phriction/xaction/PhrictionDocumentDeleteTransaction.php', 4638 4639 'PhrictionDocumentFulltextEngine' => 'applications/phriction/search/PhrictionDocumentFulltextEngine.php', 4639 4640 'PhrictionDocumentHeraldAdapter' => 'applications/phriction/herald/PhrictionDocumentHeraldAdapter.php', 4640 4641 'PhrictionDocumentHeraldField' => 'applications/phriction/herald/PhrictionDocumentHeraldField.php', ··· 10297 10298 'PhrictionDocumentAuthorHeraldField' => 'PhrictionDocumentHeraldField', 10298 10299 'PhrictionDocumentContentHeraldField' => 'PhrictionDocumentHeraldField', 10299 10300 'PhrictionDocumentController' => 'PhrictionController', 10301 + 'PhrictionDocumentDeleteTransaction' => 'PhrictionDocumentTransactionType', 10300 10302 'PhrictionDocumentFulltextEngine' => 'PhabricatorFulltextEngine', 10301 10303 'PhrictionDocumentHeraldAdapter' => 'HeraldAdapter', 10302 10304 'PhrictionDocumentHeraldField' => 'HeraldField',
+2 -1
src/applications/phriction/controller/PhrictionDeleteController.php
··· 26 26 if ($request->isFormPost()) { 27 27 $xactions = array(); 28 28 $xactions[] = id(new PhrictionTransaction()) 29 - ->setTransactionType(PhrictionTransaction::TYPE_DELETE) 29 + ->setTransactionType( 30 + PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE) 30 31 ->setNewValue(true); 31 32 32 33 $editor = id(new PhrictionTransactionEditor())
+4 -43
src/applications/phriction/editor/PhrictionTransactionEditor.php
··· 86 86 $types = parent::getTransactionTypes(); 87 87 88 88 $types[] = PhrictionTransaction::TYPE_CONTENT; 89 - $types[] = PhrictionTransaction::TYPE_DELETE; 90 89 $types[] = PhrictionTransaction::TYPE_MOVE_AWAY; 91 90 92 91 $types[] = PhabricatorTransactions::TYPE_EDGE; ··· 107 106 return null; 108 107 } 109 108 return $this->getOldContent()->getContent(); 110 - case PhrictionTransaction::TYPE_DELETE: 111 109 case PhrictionTransaction::TYPE_MOVE_AWAY: 112 110 return null; 113 111 } ··· 119 117 120 118 switch ($xaction->getTransactionType()) { 121 119 case PhrictionTransaction::TYPE_CONTENT: 122 - case PhrictionTransaction::TYPE_DELETE: 123 120 return $xaction->getNewValue(); 124 121 case PhrictionTransaction::TYPE_MOVE_AWAY: 125 122 $document = $xaction->getNewValue(); ··· 141 138 switch ($xaction->getTransactionType()) { 142 139 case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE: 143 140 case PhrictionTransaction::TYPE_CONTENT: 144 - case PhrictionTransaction::TYPE_DELETE: 141 + case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE: 145 142 case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: 146 143 case PhrictionTransaction::TYPE_MOVE_AWAY: 147 144 return true; ··· 169 166 case PhrictionTransaction::TYPE_MOVE_AWAY: 170 167 $object->setStatus(PhrictionDocumentStatus::STATUS_MOVED); 171 168 return; 172 - case PhrictionTransaction::TYPE_DELETE: 173 - $object->setStatus(PhrictionDocumentStatus::STATUS_DELETED); 174 - return; 175 169 } 176 170 } 177 171 ··· 188 182 $content = $xaction->getNewValue(); 189 183 if ($content === '') { 190 184 $xactions[] = id(new PhrictionTransaction()) 191 - ->setTransactionType(PhrictionTransaction::TYPE_DELETE) 185 + ->setTransactionType( 186 + PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE) 192 187 ->setNewValue(true) 193 188 ->setMetadataValue('contentDelete', true); 194 189 } ··· 218 213 case PhrictionTransaction::TYPE_CONTENT: 219 214 $this->getNewContent()->setContent($xaction->getNewValue()); 220 215 break; 221 - case PhrictionTransaction::TYPE_DELETE: 222 - $this->getNewContent()->setContent(''); 223 - $this->getNewContent()->setChangeType( 224 - PhrictionChangeType::CHANGE_DELETE); 225 - break; 226 216 case PhrictionTransaction::TYPE_MOVE_AWAY: 227 217 $dict = $xaction->getNewValue(); 228 218 $this->getNewContent()->setContent(''); ··· 245 235 case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE: 246 236 case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: 247 237 case PhrictionTransaction::TYPE_CONTENT: 248 - case PhrictionTransaction::TYPE_DELETE: 238 + case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE: 249 239 case PhrictionTransaction::TYPE_MOVE_AWAY: 250 240 $save_content = true; 251 241 break; ··· 536 526 } 537 527 break; 538 528 539 - case PhrictionTransaction::TYPE_DELETE: 540 - switch ($object->getStatus()) { 541 - case PhrictionDocumentStatus::STATUS_DELETED: 542 - if ($xaction->getMetadataValue('contentDelete')) { 543 - $e_text = pht( 544 - 'This document is already deleted. You must specify '. 545 - 'content to re-create the document and make further edits.'); 546 - } else { 547 - $e_text = pht( 548 - 'An already deleted document can not be deleted.'); 549 - } 550 - break; 551 - case PhrictionDocumentStatus::STATUS_MOVED: 552 - $e_text = pht('A moved document can not be deleted.'); 553 - break; 554 - case PhrictionDocumentStatus::STATUS_STUB: 555 - $e_text = pht('A stub document can not be deleted.'); 556 - break; 557 - default: 558 - break 2; 559 - } 560 - 561 - $error = new PhabricatorApplicationTransactionValidationError( 562 - $type, 563 - pht('Can not delete document.'), 564 - $e_text, 565 - $xaction); 566 - $errors[] = $error; 567 - break; 568 529 } 569 530 } 570 531
+1 -19
src/applications/phriction/storage/PhrictionTransaction.php
··· 4 4 extends PhabricatorModularTransaction { 5 5 6 6 const TYPE_CONTENT = 'content'; 7 - const TYPE_DELETE = 'delete'; 8 7 const TYPE_MOVE_AWAY = 'move-away'; 9 8 10 9 const MAILTAG_TITLE = 'phriction-title'; ··· 99 98 switch ($this->getTransactionType()) { 100 99 case self::TYPE_CONTENT: 101 100 return 1.3; 102 - case self::TYPE_DELETE: 103 - return 1.5; 104 101 case self::TYPE_MOVE_AWAY: 105 102 return 1.0; 106 103 } ··· 115 112 switch ($this->getTransactionType()) { 116 113 case self::TYPE_CONTENT: 117 114 return pht('Edited'); 118 - case self::TYPE_DELETE: 119 - return pht('Deleted'); 120 115 case self::TYPE_MOVE_AWAY: 121 116 return pht('Moved Away'); 122 117 } ··· 131 126 switch ($this->getTransactionType()) { 132 127 case self::TYPE_CONTENT: 133 128 return 'fa-pencil'; 134 - case self::TYPE_DELETE: 135 - return 'fa-times'; 136 129 case self::TYPE_MOVE_AWAY: 137 130 return 'fa-arrows'; 138 131 } ··· 153 146 '%s edited the document content.', 154 147 $this->renderHandleLink($author_phid)); 155 148 156 - case self::TYPE_DELETE: 157 - return pht( 158 - '%s deleted this document.', 159 - $this->renderHandleLink($author_phid)); 160 - 161 149 case self::TYPE_MOVE_AWAY: 162 150 return pht( 163 151 '%s moved this document to %s', ··· 184 172 $this->renderHandleLink($author_phid), 185 173 $this->renderHandleLink($object_phid)); 186 174 187 - case self::TYPE_DELETE: 188 - return pht( 189 - '%s deleted %s.', 190 - $this->renderHandleLink($author_phid), 191 - $this->renderHandleLink($object_phid)); 192 - 193 175 } 194 176 return parent::getTitleForFeed(); 195 177 } ··· 218 200 case self::TYPE_CONTENT: 219 201 $tags[] = self::MAILTAG_CONTENT; 220 202 break; 221 - case self::TYPE_DELETE: 203 + case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE: 222 204 $tags[] = self::MAILTAG_DELETE; 223 205 break; 224 206 case PhabricatorTransactions::TYPE_SUBSCRIBERS:
+86
src/applications/phriction/xaction/PhrictionDocumentDeleteTransaction.php
··· 1 + <?php 2 + 3 + final class PhrictionDocumentDeleteTransaction 4 + extends PhrictionDocumentTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'delete'; 7 + 8 + public function generateOldValue($object) { 9 + return null; 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setStatus(PhrictionDocumentStatus::STATUS_DELETED); 14 + } 15 + 16 + public function applyExternalEffects($object, $value) { 17 + $this->getEditor()->getNewContent()->setContent(''); 18 + $this->getEditor()->getNewContent()->setChangeType( 19 + PhrictionChangeType::CHANGE_DELETE); 20 + } 21 + 22 + public function getActionStrength() { 23 + return 1.5; 24 + } 25 + 26 + public function getActionName() { 27 + return pht('Deleted'); 28 + } 29 + 30 + public function getTitle() { 31 + return pht( 32 + '%s deleted this document.', 33 + $this->renderAuthor()); 34 + } 35 + 36 + public function getTitleForFeed() { 37 + return pht( 38 + '%s deleted %s.', 39 + $this->renderAuthor(), 40 + $this->renderObject()); 41 + } 42 + 43 + public function validateTransactions($object, array $xactions) { 44 + $errors = array(); 45 + 46 + $e_text = null; 47 + foreach ($xactions as $xaction) { 48 + switch ($object->getStatus()) { 49 + case PhrictionDocumentStatus::STATUS_DELETED: 50 + if ($xaction->getMetadataValue('contentDelete')) { 51 + $e_text = pht( 52 + 'This document is already deleted. You must specify '. 53 + 'content to re-create the document and make further edits.'); 54 + } else { 55 + $e_text = pht( 56 + 'An already deleted document can not be deleted.'); 57 + } 58 + break; 59 + case PhrictionDocumentStatus::STATUS_MOVED: 60 + $e_text = pht('A moved document can not be deleted.'); 61 + break; 62 + case PhrictionDocumentStatus::STATUS_STUB: 63 + $e_text = pht('A stub document can not be deleted.'); 64 + break; 65 + default: 66 + break; 67 + } 68 + 69 + if ($e_text !== null) { 70 + $errors[] = $this->newInvalidError($e_text); 71 + } 72 + 73 + } 74 + 75 + return $errors; 76 + } 77 + 78 + public function getIcon() { 79 + return 'fa-trash-o'; 80 + } 81 + 82 + public function getColor() { 83 + return 'red'; 84 + } 85 + 86 + }