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

Convert PonderAnswer to modular transactions

Summary: Fixes T12624. Converts PonderAnswer over to modular transactions.

Test Plan:
- Add an answer
- Edit an answer
- Hide an answer
- Comment on an answer

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T12624

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

+154 -212
+9 -1
src/__phutil_library_map__.php
··· 4551 4551 'PonderAddAnswerView' => 'applications/ponder/view/PonderAddAnswerView.php', 4552 4552 'PonderAnswer' => 'applications/ponder/storage/PonderAnswer.php', 4553 4553 'PonderAnswerCommentController' => 'applications/ponder/controller/PonderAnswerCommentController.php', 4554 + 'PonderAnswerContentTransaction' => 'applications/ponder/xaction/PonderAnswerContentTransaction.php', 4554 4555 'PonderAnswerEditController' => 'applications/ponder/controller/PonderAnswerEditController.php', 4555 4556 'PonderAnswerEditor' => 'applications/ponder/editor/PonderAnswerEditor.php', 4556 4557 'PonderAnswerHistoryController' => 'applications/ponder/controller/PonderAnswerHistoryController.php', 4557 4558 'PonderAnswerMailReceiver' => 'applications/ponder/mail/PonderAnswerMailReceiver.php', 4558 4559 'PonderAnswerPHIDType' => 'applications/ponder/phid/PonderAnswerPHIDType.php', 4559 4560 'PonderAnswerQuery' => 'applications/ponder/query/PonderAnswerQuery.php', 4561 + 'PonderAnswerQuestionIDTransaction' => 'applications/ponder/xaction/PonderAnswerQuestionIDTransaction.php', 4560 4562 'PonderAnswerReplyHandler' => 'applications/ponder/mail/PonderAnswerReplyHandler.php', 4561 4563 'PonderAnswerSaveController' => 'applications/ponder/controller/PonderAnswerSaveController.php', 4562 4564 'PonderAnswerStatus' => 'applications/ponder/constants/PonderAnswerStatus.php', 4565 + 'PonderAnswerStatusTransaction' => 'applications/ponder/xaction/PonderAnswerStatusTransaction.php', 4563 4566 'PonderAnswerTransaction' => 'applications/ponder/storage/PonderAnswerTransaction.php', 4564 4567 'PonderAnswerTransactionComment' => 'applications/ponder/storage/PonderAnswerTransactionComment.php', 4565 4568 'PonderAnswerTransactionQuery' => 'applications/ponder/query/PonderAnswerTransactionQuery.php', 4569 + 'PonderAnswerTransactionType' => 'applications/ponder/xaction/PonderAnswerTransactionType.php', 4566 4570 'PonderAnswerView' => 'applications/ponder/view/PonderAnswerView.php', 4567 4571 'PonderConstants' => 'applications/ponder/constants/PonderConstants.php', 4568 4572 'PonderController' => 'applications/ponder/controller/PonderController.php', ··· 10099 10103 'PhabricatorDestructibleInterface', 10100 10104 ), 10101 10105 'PonderAnswerCommentController' => 'PonderController', 10106 + 'PonderAnswerContentTransaction' => 'PonderAnswerTransactionType', 10102 10107 'PonderAnswerEditController' => 'PonderController', 10103 10108 'PonderAnswerEditor' => 'PonderEditor', 10104 10109 'PonderAnswerHistoryController' => 'PonderController', 10105 10110 'PonderAnswerMailReceiver' => 'PhabricatorObjectMailReceiver', 10106 10111 'PonderAnswerPHIDType' => 'PhabricatorPHIDType', 10107 10112 'PonderAnswerQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 10113 + 'PonderAnswerQuestionIDTransaction' => 'PonderAnswerTransactionType', 10108 10114 'PonderAnswerReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 10109 10115 'PonderAnswerSaveController' => 'PonderController', 10110 10116 'PonderAnswerStatus' => 'PonderConstants', 10111 - 'PonderAnswerTransaction' => 'PhabricatorApplicationTransaction', 10117 + 'PonderAnswerStatusTransaction' => 'PonderAnswerTransactionType', 10118 + 'PonderAnswerTransaction' => 'PhabricatorModularTransaction', 10112 10119 'PonderAnswerTransactionComment' => 'PhabricatorApplicationTransactionComment', 10113 10120 'PonderAnswerTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 10121 + 'PonderAnswerTransactionType' => 'PhabricatorModularTransactionType', 10114 10122 'PonderAnswerView' => 'AphrontTagView', 10115 10123 'PonderConstants' => 'Phobject', 10116 10124 'PonderController' => 'PhabricatorController',
+2 -2
src/applications/ponder/controller/PonderAnswerEditController.php
··· 42 42 if (!$errors) { 43 43 $xactions = array(); 44 44 $xactions[] = id(new PonderAnswerTransaction()) 45 - ->setTransactionType(PonderAnswerTransaction::TYPE_CONTENT) 45 + ->setTransactionType(PonderAnswerContentTransaction::TRANSACTIONTYPE) 46 46 ->setNewValue($v_content); 47 47 48 48 $xactions[] = id(new PonderAnswerTransaction()) 49 - ->setTransactionType(PonderAnswerTransaction::TYPE_STATUS) 49 + ->setTransactionType(PonderAnswerStatusTransaction::TRANSACTIONTYPE) 50 50 ->setNewValue($v_status); 51 51 52 52 $editor = id(new PonderAnswerEditor())
+2 -2
src/applications/ponder/controller/PonderAnswerSaveController.php
··· 58 58 $xactions = array(); 59 59 60 60 $xactions[] = id(clone $template) 61 - ->setTransactionType(PonderAnswerTransaction::TYPE_QUESTION_ID) 61 + ->setTransactionType(PonderAnswerQuestionIDTransaction::TRANSACTIONTYPE) 62 62 ->setNewValue($question->getID()); 63 63 64 64 $xactions[] = id(clone $template) 65 - ->setTransactionType(PonderAnswerTransaction::TYPE_CONTENT) 65 + ->setTransactionType(PonderAnswerContentTransaction::TRANSACTIONTYPE) 66 66 ->setNewValue($content); 67 67 68 68 $editor = id(new PonderAnswerEditor())
-67
src/applications/ponder/editor/PonderAnswerEditor.php
··· 8 8 9 9 public function getTransactionTypes() { 10 10 $types = parent::getTransactionTypes(); 11 - 12 11 $types[] = PhabricatorTransactions::TYPE_COMMENT; 13 - $types[] = PhabricatorTransactions::TYPE_EDGE; 14 - 15 - $types[] = PonderAnswerTransaction::TYPE_CONTENT; 16 - $types[] = PonderAnswerTransaction::TYPE_STATUS; 17 - $types[] = PonderAnswerTransaction::TYPE_QUESTION_ID; 18 12 19 13 return $types; 20 - } 21 - 22 - protected function getCustomTransactionOldValue( 23 - PhabricatorLiskDAO $object, 24 - PhabricatorApplicationTransaction $xaction) { 25 - 26 - switch ($xaction->getTransactionType()) { 27 - case PonderAnswerTransaction::TYPE_CONTENT: 28 - case PonderAnswerTransaction::TYPE_STATUS: 29 - return $object->getContent(); 30 - case PonderAnswerTransaction::TYPE_QUESTION_ID: 31 - return $object->getQuestionID(); 32 - } 33 - } 34 - 35 - protected function getCustomTransactionNewValue( 36 - PhabricatorLiskDAO $object, 37 - PhabricatorApplicationTransaction $xaction) { 38 - 39 - switch ($xaction->getTransactionType()) { 40 - case PonderAnswerTransaction::TYPE_CONTENT: 41 - case PonderAnswerTransaction::TYPE_STATUS: 42 - case PonderAnswerTransaction::TYPE_QUESTION_ID: 43 - return $xaction->getNewValue(); 44 - } 45 - } 46 - 47 - protected function applyCustomInternalTransaction( 48 - PhabricatorLiskDAO $object, 49 - PhabricatorApplicationTransaction $xaction) { 50 - 51 - switch ($xaction->getTransactionType()) { 52 - case PonderAnswerTransaction::TYPE_CONTENT: 53 - $object->setContent($xaction->getNewValue()); 54 - break; 55 - case PonderAnswerTransaction::TYPE_STATUS: 56 - $object->setStatus($xaction->getNewValue()); 57 - break; 58 - case PonderAnswerTransaction::TYPE_QUESTION_ID: 59 - $object->setQuestionID($xaction->getNewValue()); 60 - break; 61 - } 62 - } 63 - 64 - protected function applyCustomExternalTransaction( 65 - PhabricatorLiskDAO $object, 66 - PhabricatorApplicationTransaction $xaction) { 67 - return; 68 - } 69 - 70 - protected function mergeTransactions( 71 - PhabricatorApplicationTransaction $u, 72 - PhabricatorApplicationTransaction $v) { 73 - 74 - $type = $u->getTransactionType(); 75 - switch ($type) { 76 - case PonderAnswerTransaction::TYPE_CONTENT: 77 - return $v; 78 - } 79 - 80 - return parent::mergeTransactions($u, $v); 81 14 } 82 15 83 16 protected function shouldSendMail(
+3 -140
src/applications/ponder/storage/PonderAnswerTransaction.php
··· 1 1 <?php 2 2 3 3 final class PonderAnswerTransaction 4 - extends PhabricatorApplicationTransaction { 5 - 6 - const TYPE_CONTENT = 'ponder.answer:content'; 7 - const TYPE_STATUS = 'ponder.answer:status'; 8 - const TYPE_QUESTION_ID = 'ponder.answer:question-id'; 4 + extends PhabricatorModularTransaction { 9 5 10 6 public function getApplicationName() { 11 7 return 'ponder'; ··· 23 19 return new PonderAnswerTransactionComment(); 24 20 } 25 21 26 - public function getRequiredHandlePHIDs() { 27 - $phids = parent::getRequiredHandlePHIDs(); 28 - 29 - switch ($this->getTransactionType()) { 30 - case self::TYPE_CONTENT: 31 - case self::TYPE_STATUS: 32 - $phids[] = $this->getObjectPHID(); 33 - break; 34 - } 35 - 36 - return $phids; 37 - } 38 - 39 - public function getRemarkupBlocks() { 40 - $blocks = parent::getRemarkupBlocks(); 41 - switch ($this->getTransactionType()) { 42 - case self::TYPE_CONTENT: 43 - $blocks[] = $this->getNewValue(); 44 - break; 45 - } 46 - return $blocks; 47 - } 48 - 49 - public function shouldHide() { 50 - switch ($this->getTransactionType()) { 51 - case self::TYPE_QUESTION_ID: 52 - return true; 53 - } 54 - return parent::shouldHide(); 55 - } 56 - 57 - public function getTitle() { 58 - $author_phid = $this->getAuthorPHID(); 59 - $object_phid = $this->getObjectPHID(); 60 - 61 - $old = $this->getOldValue(); 62 - $new = $this->getNewValue(); 63 - 64 - switch ($this->getTransactionType()) { 65 - case self::TYPE_CONTENT: 66 - if ($old === '') { 67 - return pht( 68 - '%s added %s.', 69 - $this->renderHandleLink($author_phid), 70 - $this->renderHandleLink($object_phid)); 71 - } else { 72 - return pht( 73 - '%s edited %s.', 74 - $this->renderHandleLink($author_phid), 75 - $this->renderHandleLink($object_phid)); 76 - } 77 - break; 78 - case self::TYPE_STATUS: 79 - if ($new == PonderAnswerStatus::ANSWER_STATUS_VISIBLE) { 80 - return pht( 81 - '%s marked %s as visible.', 82 - $this->renderHandleLink($author_phid), 83 - $this->renderHandleLink($object_phid)); 84 - } else if ($new == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) { 85 - return pht( 86 - '%s marked %s as hidden.', 87 - $this->renderHandleLink($author_phid), 88 - $this->renderHandleLink($object_phid)); 89 - } 90 - break; 91 - } 92 - 93 - return parent::getTitle(); 94 - } 95 - 96 - public function getTitleForFeed() { 97 - $author_phid = $this->getAuthorPHID(); 98 - $object_phid = $this->getObjectPHID(); 99 - 100 - $old = $this->getOldValue(); 101 - $new = $this->getNewValue(); 102 - 103 - switch ($this->getTransactionType()) { 104 - case self::TYPE_CONTENT: 105 - if ($old === '') { 106 - return pht( 107 - '%s added %s.', 108 - $this->renderHandleLink($author_phid), 109 - $this->renderHandleLink($object_phid)); 110 - } else { 111 - return pht( 112 - '%s updated %s.', 113 - $this->renderHandleLink($author_phid), 114 - $this->renderHandleLink($object_phid)); 115 - } 116 - break; 117 - case self::TYPE_STATUS: 118 - if ($new == PonderAnswerStatus::ANSWER_STATUS_VISIBLE) { 119 - return pht( 120 - '%s marked %s as visible.', 121 - $this->renderHandleLink($author_phid), 122 - $this->renderHandleLink($object_phid)); 123 - } else if ($new == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) { 124 - return pht( 125 - '%s marked %s as hidden.', 126 - $this->renderHandleLink($author_phid), 127 - $this->renderHandleLink($object_phid)); 128 - } 129 - break; 130 - } 131 - 132 - return parent::getTitleForFeed(); 133 - } 134 - 135 - public function getRemarkupBodyForFeed(PhabricatorFeedStory $story) { 136 - $text = null; 137 - switch ($this->getTransactionType()) { 138 - case self::TYPE_CONTENT: 139 - $text = $this->getNewValue(); 140 - break; 141 - } 142 - return $text; 143 - } 144 - 145 - 146 - public function hasChangeDetails() { 147 - $old = $this->getOldValue(); 148 - 149 - switch ($this->getTransactionType()) { 150 - case self::TYPE_CONTENT: 151 - return $old !== null; 152 - } 153 - return parent::hasChangeDetails(); 154 - } 155 - 156 - public function renderChangeDetails(PhabricatorUser $viewer) { 157 - return $this->renderTextCorpusChangeDetails( 158 - $viewer, 159 - $this->getOldValue(), 160 - $this->getNewValue()); 22 + public function getBaseTransactionClass() { 23 + return 'PonderAnswerTransactionType'; 161 24 } 162 25 163 26 }
+56
src/applications/ponder/xaction/PonderAnswerContentTransaction.php
··· 1 + <?php 2 + 3 + final class PonderAnswerContentTransaction 4 + extends PonderAnswerTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'ponder.answer:content'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getContent(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setContent($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s updated the answer details.', 19 + $this->renderAuthor()); 20 + } 21 + 22 + public function getTitleForFeed() { 23 + return pht( 24 + '%s updated the answer details for %s.', 25 + $this->renderAuthor(), 26 + $this->renderObject()); 27 + } 28 + 29 + public function hasChangeDetailView() { 30 + return true; 31 + } 32 + 33 + public function getMailDiffSectionHeader() { 34 + return pht('CHANGES TO ANSWER DETAILS'); 35 + } 36 + 37 + public function newChangeDetailView() { 38 + $viewer = $this->getViewer(); 39 + 40 + return id(new PhabricatorApplicationTransactionTextDiffDetailView()) 41 + ->setViewer($viewer) 42 + ->setOldText($this->getOldValue()) 43 + ->setNewText($this->getNewValue()); 44 + } 45 + 46 + public function newRemarkupChanges() { 47 + $changes = array(); 48 + 49 + $changes[] = $this->newRemarkupChange() 50 + ->setOldValue($this->getOldValue()) 51 + ->setNewValue($this->getNewValue()); 52 + 53 + return $changes; 54 + } 55 + 56 + }
+16
src/applications/ponder/xaction/PonderAnswerQuestionIDTransaction.php
··· 1 + <?php 2 + 3 + final class PonderAnswerQuestionIDTransaction 4 + extends PonderAnswerTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'ponder.answer:question-id'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getQuestionID(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setQuestionID($value); 14 + } 15 + 16 + }
+62
src/applications/ponder/xaction/PonderAnswerStatusTransaction.php
··· 1 + <?php 2 + 3 + final class PonderAnswerStatusTransaction 4 + extends PonderAnswerTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'ponder.answer:status'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getStatus(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setStatus($value); 14 + } 15 + 16 + public function getTitle() { 17 + $new = $this->getNewValue(); 18 + if ($new == PonderAnswerStatus::ANSWER_STATUS_VISIBLE) { 19 + return pht( 20 + '%s marked this answer as visible.', 21 + $this->renderAuthor()); 22 + } else if ($new == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) { 23 + return pht( 24 + '%s marked this answer as hidden.', 25 + $this->renderAuthor()); 26 + } 27 + } 28 + 29 + public function getTitleForFeed() { 30 + $new = $this->getNewValue(); 31 + if ($new == PonderAnswerStatus::ANSWER_STATUS_VISIBLE) { 32 + return pht( 33 + '%s marked %s as visible.', 34 + $this->renderAuthor(), 35 + $this->renderObject()); 36 + } else if ($new == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) { 37 + return pht( 38 + '%s marked %s as hidden.', 39 + $this->renderAuthor(), 40 + $this->renderObject()); 41 + } 42 + } 43 + 44 + public function getIcon() { 45 + $new = $this->getNewValue(); 46 + if ($new == PonderAnswerStatus::ANSWER_STATUS_VISIBLE) { 47 + return 'fa-ban'; 48 + } else if ($new == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) { 49 + return 'fa-check'; 50 + } 51 + } 52 + 53 + public function getColor() { 54 + $new = $this->getNewValue(); 55 + if ($new == PonderAnswerStatus::ANSWER_STATUS_VISIBLE) { 56 + return 'green'; 57 + } else if ($new == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) { 58 + return 'indigo'; 59 + } 60 + } 61 + 62 + }
+4
src/applications/ponder/xaction/PonderAnswerTransactionType.php
··· 1 + <?php 2 + 3 + abstract class PonderAnswerTransactionType 4 + extends PhabricatorModularTransactionType {}