@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 PhrictionContent for modular transactions

Summary: Fixes T12625. Moves TYPE_CONTENT in Phriction over to modular transactions.

Test Plan: Edit some documents.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T12625

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

+117 -195
+2
src/__phutil_library_map__.php
··· 4637 4637 'PhrictionDocument' => 'applications/phriction/storage/PhrictionDocument.php', 4638 4638 'PhrictionDocumentAuthorHeraldField' => 'applications/phriction/herald/PhrictionDocumentAuthorHeraldField.php', 4639 4639 'PhrictionDocumentContentHeraldField' => 'applications/phriction/herald/PhrictionDocumentContentHeraldField.php', 4640 + 'PhrictionDocumentContentTransaction' => 'applications/phriction/xaction/PhrictionDocumentContentTransaction.php', 4640 4641 'PhrictionDocumentController' => 'applications/phriction/controller/PhrictionDocumentController.php', 4641 4642 'PhrictionDocumentDeleteTransaction' => 'applications/phriction/xaction/PhrictionDocumentDeleteTransaction.php', 4642 4643 'PhrictionDocumentFulltextEngine' => 'applications/phriction/search/PhrictionDocumentFulltextEngine.php', ··· 10304 10305 ), 10305 10306 'PhrictionDocumentAuthorHeraldField' => 'PhrictionDocumentHeraldField', 10306 10307 'PhrictionDocumentContentHeraldField' => 'PhrictionDocumentHeraldField', 10308 + 'PhrictionDocumentContentTransaction' => 'PhrictionDocumentTransactionType', 10307 10309 'PhrictionDocumentController' => 'PhrictionController', 10308 10310 'PhrictionDocumentDeleteTransaction' => 'PhrictionDocumentTransactionType', 10309 10311 'PhrictionDocumentFulltextEngine' => 'PhabricatorFulltextEngine',
+1 -1
src/applications/phriction/conduit/PhrictionCreateConduitAPIMethod.php
··· 50 50 ->setTransactionType(PhrictionDocumentTitleTransaction::TRANSACTIONTYPE) 51 51 ->setNewValue($request->getValue('title')); 52 52 $xactions[] = id(new PhrictionTransaction()) 53 - ->setTransactionType(PhrictionTransaction::TYPE_CONTENT) 53 + ->setTransactionType(PhrictionDocumentContentTransaction::TRANSACTIONTYPE) 54 54 ->setNewValue($request->getValue('content')); 55 55 56 56 $editor = id(new PhrictionTransactionEditor())
+1 -1
src/applications/phriction/conduit/PhrictionEditConduitAPIMethod.php
··· 45 45 ->setTransactionType(PhrictionDocumentTitleTransaction::TRANSACTIONTYPE) 46 46 ->setNewValue($request->getValue('title')); 47 47 $xactions[] = id(new PhrictionTransaction()) 48 - ->setTransactionType(PhrictionTransaction::TYPE_CONTENT) 48 + ->setTransactionType(PhrictionDocumentContentTransaction::TRANSACTIONTYPE) 49 49 ->setNewValue($request->getValue('content')); 50 50 51 51 $editor = id(new PhrictionTransactionEditor())
+4 -2
src/applications/phriction/controller/PhrictionEditController.php
··· 136 136 ->setTransactionType(PhrictionDocumentTitleTransaction::TRANSACTIONTYPE) 137 137 ->setNewValue($title); 138 138 $xactions[] = id(new PhrictionTransaction()) 139 - ->setTransactionType(PhrictionTransaction::TYPE_CONTENT) 139 + ->setTransactionType( 140 + PhrictionDocumentContentTransaction::TRANSACTIONTYPE) 140 141 ->setNewValue($content_text); 141 142 $xactions[] = id(new PhrictionTransaction()) 142 143 ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) ··· 178 179 PhrictionDocumentTitleTransaction::TRANSACTIONTYPE), 179 180 true); 180 181 $e_content = nonempty( 181 - $ex->getShortMessage(PhrictionTransaction::TYPE_CONTENT), 182 + $ex->getShortMessage( 183 + PhrictionDocumentContentTransaction::TRANSACTIONTYPE), 182 184 true); 183 185 184 186 // if we're not supposed to process the content version error, then
+13 -79
src/applications/phriction/editor/PhrictionTransactionEditor.php
··· 85 85 public function getTransactionTypes() { 86 86 $types = parent::getTransactionTypes(); 87 87 88 - $types[] = PhrictionTransaction::TYPE_CONTENT; 89 - 90 88 $types[] = PhabricatorTransactions::TYPE_EDGE; 91 89 $types[] = PhabricatorTransactions::TYPE_COMMENT; 92 90 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; ··· 95 93 return $types; 96 94 } 97 95 98 - protected function getCustomTransactionOldValue( 99 - PhabricatorLiskDAO $object, 100 - PhabricatorApplicationTransaction $xaction) { 101 - 102 - switch ($xaction->getTransactionType()) { 103 - case PhrictionTransaction::TYPE_CONTENT: 104 - if ($this->getIsNewObject()) { 105 - return null; 106 - } 107 - return $this->getOldContent()->getContent(); 108 - } 109 - } 110 - 111 - protected function getCustomTransactionNewValue( 112 - PhabricatorLiskDAO $object, 113 - PhabricatorApplicationTransaction $xaction) { 114 - 115 - switch ($xaction->getTransactionType()) { 116 - case PhrictionTransaction::TYPE_CONTENT: 117 - return $xaction->getNewValue(); 118 - } 119 - } 120 - 121 96 protected function shouldApplyInitialEffects( 122 97 PhabricatorLiskDAO $object, 123 98 array $xactions) { 124 99 125 100 foreach ($xactions as $xaction) { 126 101 switch ($xaction->getTransactionType()) { 127 - case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE: 128 - case PhrictionTransaction::TYPE_CONTENT: 129 - case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE: 130 - case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: 131 - case PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE: 132 - return true; 102 + case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE: 103 + case PhrictionDocumentContentTransaction::TRANSACTIONTYPE: 104 + case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE: 105 + case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: 106 + case PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE: 107 + return true; 133 108 } 134 109 } 135 110 return parent::shouldApplyInitialEffects($object, $xactions); ··· 143 118 $this->setNewContent($this->buildNewContentTemplate($object)); 144 119 } 145 120 146 - protected function applyCustomInternalTransaction( 147 - PhabricatorLiskDAO $object, 148 - PhabricatorApplicationTransaction $xaction) { 149 - 150 - switch ($xaction->getTransactionType()) { 151 - case PhrictionTransaction::TYPE_CONTENT: 152 - $object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS); 153 - return; 154 - } 155 - } 156 - 157 121 protected function expandTransaction( 158 122 PhabricatorLiskDAO $object, 159 123 PhabricatorApplicationTransaction $xaction) { 160 124 161 125 $xactions = parent::expandTransaction($object, $xaction); 162 126 switch ($xaction->getTransactionType()) { 163 - case PhrictionTransaction::TYPE_CONTENT: 127 + case PhrictionDocumentContentTransaction::TRANSACTIONTYPE: 164 128 if ($this->getIsNewObject()) { 165 129 break; 166 130 } ··· 190 154 return $xactions; 191 155 } 192 156 193 - protected function applyCustomExternalTransaction( 194 - PhabricatorLiskDAO $object, 195 - PhabricatorApplicationTransaction $xaction) { 196 - 197 - switch ($xaction->getTransactionType()) { 198 - case PhrictionTransaction::TYPE_CONTENT: 199 - $this->getNewContent()->setContent($xaction->getNewValue()); 200 - break; 201 - default: 202 - break; 203 - } 204 - } 205 - 206 157 protected function applyFinalEffects( 207 158 PhabricatorLiskDAO $object, 208 159 array $xactions) { ··· 214 165 case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: 215 166 case PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE: 216 167 case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE: 217 - case PhrictionTransaction::TYPE_CONTENT: 168 + case PhrictionDocumentContentTransaction::TRANSACTIONTYPE: 218 169 $save_content = true; 219 170 break; 220 171 default: ··· 257 208 ->setNewValue(PhabricatorSlug::getDefaultTitle($slug)) 258 209 ->setMetadataValue('stub:create:phid', $object->getPHID()); 259 210 $stub_xactions[] = id(new PhrictionTransaction()) 260 - ->setTransactionType(PhrictionTransaction::TYPE_CONTENT) 211 + ->setTransactionType( 212 + PhrictionDocumentContentTransaction::TRANSACTIONTYPE) 261 213 ->setNewValue('') 262 214 ->setMetadataValue('stub:create:phid', $object->getPHID()); 263 215 $stub_xactions[] = id(new PhrictionTransaction()) ··· 295 247 // Compute the content diff URI for the publishing phase. 296 248 foreach ($xactions as $xaction) { 297 249 switch ($xaction->getTransactionType()) { 298 - case PhrictionTransaction::TYPE_CONTENT: 250 + case PhrictionDocumentContentTransaction::TRANSACTIONTYPE: 299 251 $uri = id(new PhutilURI('/phriction/diff/'.$object->getID().'/')) 300 252 ->alter('l', $this->getOldContent()->getVersion()) 301 253 ->alter('r', $this->getNewContent()->getVersion()); ··· 419 371 420 372 foreach ($xactions as $xaction) { 421 373 switch ($type) { 422 - case PhrictionTransaction::TYPE_CONTENT: 374 + case PhrictionDocumentContentTransaction::TRANSACTIONTYPE: 423 375 if ($xaction->getMetadataValue('stub:create:phid')) { 424 376 continue; 425 377 } 426 378 427 - $missing = false; 428 - if ($this->getIsNewObject()) { 429 - $content = $object->getContent()->getContent(); 430 - $missing = $this->validateIsEmptyTextField( 431 - $content, 432 - $xactions); 433 - } 434 - 435 - if ($missing) { 436 - $error = new PhabricatorApplicationTransactionValidationError( 437 - $type, 438 - pht('Required'), 439 - pht('Document content is required.'), 440 - nonempty(last($xactions), null)); 441 - 442 - $error->setIsMissingFieldError(true); 443 - $errors[] = $error; 444 - } else if ($this->getProcessContentVersionError()) { 379 + if ($this->getProcessContentVersionError()) { 445 380 $error = $this->validateContentVersion($object, $type, $xaction); 446 381 if ($error) { 447 382 $this->setProcessContentVersionError(false); ··· 459 394 $errors = array_merge($errors, $ancestry_errors); 460 395 } 461 396 } 462 - 463 397 break; 464 398 465 399 case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
+1 -112
src/applications/phriction/storage/PhrictionTransaction.php
··· 3 3 final class PhrictionTransaction 4 4 extends PhabricatorModularTransaction { 5 5 6 - const TYPE_CONTENT = 'content'; 7 - 8 6 const MAILTAG_TITLE = 'phriction-title'; 9 7 const MAILTAG_CONTENT = 'phriction-content'; 10 8 const MAILTAG_DELETE = 'phriction-delete'; ··· 45 43 return $phids; 46 44 } 47 45 48 - public function getRemarkupBlocks() { 49 - $blocks = parent::getRemarkupBlocks(); 50 - 51 - switch ($this->getTransactionType()) { 52 - case self::TYPE_CONTENT: 53 - $blocks[] = $this->getNewValue(); 54 - break; 55 - } 56 - 57 - return $blocks; 58 - } 59 - 60 - public function shouldHide() { 61 - switch ($this->getTransactionType()) { 62 - case self::TYPE_CONTENT: 63 - if ($this->getOldValue() === null) { 64 - return true; 65 - } else { 66 - return false; 67 - } 68 - break; 69 - } 70 - 71 - return parent::shouldHide(); 72 - } 73 - 74 46 public function shouldHideForMail(array $xactions) { 75 47 switch ($this->getTransactionType()) { 76 48 case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: ··· 93 65 return parent::shouldHideForFeed(); 94 66 } 95 67 96 - public function getActionStrength() { 97 - switch ($this->getTransactionType()) { 98 - case self::TYPE_CONTENT: 99 - return 1.3; 100 - } 101 - 102 - return parent::getActionStrength(); 103 - } 104 - 105 - public function getActionName() { 106 - $old = $this->getOldValue(); 107 - $new = $this->getNewValue(); 108 - 109 - switch ($this->getTransactionType()) { 110 - case self::TYPE_CONTENT: 111 - return pht('Edited'); 112 - } 113 - 114 - return parent::getActionName(); 115 - } 116 - 117 - public function getIcon() { 118 - $old = $this->getOldValue(); 119 - $new = $this->getNewValue(); 120 - 121 - switch ($this->getTransactionType()) { 122 - case self::TYPE_CONTENT: 123 - return 'fa-pencil'; 124 - } 125 - 126 - return parent::getIcon(); 127 - } 128 - 129 - 130 - public function getTitle() { 131 - $author_phid = $this->getAuthorPHID(); 132 - 133 - $old = $this->getOldValue(); 134 - $new = $this->getNewValue(); 135 - 136 - switch ($this->getTransactionType()) { 137 - case self::TYPE_CONTENT: 138 - return pht( 139 - '%s edited the document content.', 140 - $this->renderHandleLink($author_phid)); 141 - } 142 - 143 - return parent::getTitle(); 144 - } 145 - 146 - public function getTitleForFeed() { 147 - $author_phid = $this->getAuthorPHID(); 148 - $object_phid = $this->getObjectPHID(); 149 - 150 - $old = $this->getOldValue(); 151 - $new = $this->getNewValue(); 152 - 153 - switch ($this->getTransactionType()) { 154 - 155 - case self::TYPE_CONTENT: 156 - return pht( 157 - '%s edited the content of %s.', 158 - $this->renderHandleLink($author_phid), 159 - $this->renderHandleLink($object_phid)); 160 - 161 - } 162 - return parent::getTitleForFeed(); 163 - } 164 - 165 - public function hasChangeDetails() { 166 - switch ($this->getTransactionType()) { 167 - case self::TYPE_CONTENT: 168 - return true; 169 - } 170 - return parent::hasChangeDetails(); 171 - } 172 - 173 - public function renderChangeDetails(PhabricatorUser $viewer) { 174 - return $this->renderTextCorpusChangeDetails( 175 - $viewer, 176 - $this->getOldValue(), 177 - $this->getNewValue()); 178 - } 179 68 180 69 public function getMailTags() { 181 70 $tags = array(); ··· 183 72 case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE: 184 73 $tags[] = self::MAILTAG_TITLE; 185 74 break; 186 - case self::TYPE_CONTENT: 75 + case PhrictionDocumentContentTransaction::TRANSACTIONTYPE: 187 76 $tags[] = self::MAILTAG_CONTENT; 188 77 break; 189 78 case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE:
+95
src/applications/phriction/xaction/PhrictionDocumentContentTransaction.php
··· 1 + <?php 2 + 3 + final class PhrictionDocumentContentTransaction 4 + extends PhrictionDocumentTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'content'; 7 + 8 + public function generateOldValue($object) { 9 + if ($this->getEditor()->getIsNewObject()) { 10 + return null; 11 + } 12 + return $object->getContent()->getContent(); 13 + } 14 + 15 + public function generateNewValue($object, $value) { 16 + return $value; 17 + } 18 + 19 + public function applyInternalEffects($object, $value) { 20 + $object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS); 21 + } 22 + 23 + public function applyExternalEffects($object, $value) { 24 + $this->getEditor()->getNewContent()->setContent($value); 25 + } 26 + 27 + public function shouldHide() { 28 + if ($this->getOldValue() === null) { 29 + return true; 30 + } else { 31 + return false; 32 + } 33 + } 34 + 35 + public function getActionStrength() { 36 + return 1.3; 37 + } 38 + 39 + public function getActionName() { 40 + return pht('Edited'); 41 + } 42 + 43 + public function getTitle() { 44 + return pht( 45 + '%s edited the content of this document.', 46 + $this->renderAuthor()); 47 + } 48 + 49 + public function getTitleForFeed() { 50 + return pht( 51 + '%s edited the content of %s.', 52 + $this->renderAuthor(), 53 + $this->renderObject()); 54 + } 55 + 56 + public function hasChangeDetailView() { 57 + return true; 58 + } 59 + 60 + public function getMailDiffSectionHeader() { 61 + return pht('CHANGES TO DOCUMENT CONTENT'); 62 + } 63 + 64 + public function newChangeDetailView() { 65 + $viewer = $this->getViewer(); 66 + 67 + return id(new PhabricatorApplicationTransactionTextDiffDetailView()) 68 + ->setViewer($viewer) 69 + ->setOldText($this->getOldValue()) 70 + ->setNewText($this->getNewValue()); 71 + } 72 + 73 + public function newRemarkupChanges() { 74 + $changes = array(); 75 + 76 + $changes[] = $this->newRemarkupChange() 77 + ->setOldValue($this->getOldValue()) 78 + ->setNewValue($this->getNewValue()); 79 + 80 + return $changes; 81 + } 82 + 83 + public function validateTransactions($object, array $xactions) { 84 + $errors = array(); 85 + 86 + $content = $object->getContent()->getContent(); 87 + if ($this->isEmptyTextTransaction($content, $xactions)) { 88 + $errors[] = $this->newRequiredError( 89 + pht('Documents must have content.')); 90 + } 91 + 92 + return $errors; 93 + } 94 + 95 + }