@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 PonderQuestion for Modular Transactions

Summary: Ref T12624, this moves PonderQuestion over to modular transactions.

Test Plan:
- Create a question
- Edit a question
- Comment on question
- Answer question
- Edit Answer
- Close Question
- Verify answer count in list views
- Check Question History
- Check Answer History

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T12624

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

+309 -392
+13 -1
src/__phutil_library_map__.php
··· 4572 4572 'PonderFooterView' => 'applications/ponder/view/PonderFooterView.php', 4573 4573 'PonderModerateCapability' => 'applications/ponder/capability/PonderModerateCapability.php', 4574 4574 'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php', 4575 + 'PonderQuestionAnswerTransaction' => 'applications/ponder/xaction/PonderQuestionAnswerTransaction.php', 4576 + 'PonderQuestionAnswerWikiTransaction' => 'applications/ponder/xaction/PonderQuestionAnswerWikiTransaction.php', 4575 4577 'PonderQuestionCommentController' => 'applications/ponder/controller/PonderQuestionCommentController.php', 4578 + 'PonderQuestionContentTransaction' => 'applications/ponder/xaction/PonderQuestionContentTransaction.php', 4576 4579 'PonderQuestionCreateMailReceiver' => 'applications/ponder/mail/PonderQuestionCreateMailReceiver.php', 4577 4580 'PonderQuestionEditController' => 'applications/ponder/controller/PonderQuestionEditController.php', 4578 4581 'PonderQuestionEditor' => 'applications/ponder/editor/PonderQuestionEditor.php', ··· 4586 4589 'PonderQuestionSearchEngine' => 'applications/ponder/query/PonderQuestionSearchEngine.php', 4587 4590 'PonderQuestionStatus' => 'applications/ponder/constants/PonderQuestionStatus.php', 4588 4591 'PonderQuestionStatusController' => 'applications/ponder/controller/PonderQuestionStatusController.php', 4592 + 'PonderQuestionStatusTransaction' => 'applications/ponder/xaction/PonderQuestionStatusTransaction.php', 4593 + 'PonderQuestionTitleTransaction' => 'applications/ponder/xaction/PonderQuestionTitleTransaction.php', 4589 4594 'PonderQuestionTransaction' => 'applications/ponder/storage/PonderQuestionTransaction.php', 4590 4595 'PonderQuestionTransactionComment' => 'applications/ponder/storage/PonderQuestionTransactionComment.php', 4591 4596 'PonderQuestionTransactionQuery' => 'applications/ponder/query/PonderQuestionTransactionQuery.php', 4597 + 'PonderQuestionTransactionType' => 'applications/ponder/xaction/PonderQuestionTransactionType.php', 4592 4598 'PonderQuestionViewController' => 'applications/ponder/controller/PonderQuestionViewController.php', 4593 4599 'PonderRemarkupRule' => 'applications/ponder/remarkup/PonderRemarkupRule.php', 4594 4600 'PonderSchemaSpec' => 'applications/ponder/storage/PonderSchemaSpec.php', ··· 10126 10132 'PhabricatorSpacesInterface', 10127 10133 'PhabricatorFulltextInterface', 10128 10134 ), 10135 + 'PonderQuestionAnswerTransaction' => 'PonderQuestionTransactionType', 10136 + 'PonderQuestionAnswerWikiTransaction' => 'PonderQuestionTransactionType', 10129 10137 'PonderQuestionCommentController' => 'PonderController', 10138 + 'PonderQuestionContentTransaction' => 'PonderQuestionTransactionType', 10130 10139 'PonderQuestionCreateMailReceiver' => 'PhabricatorMailReceiver', 10131 10140 'PonderQuestionEditController' => 'PonderController', 10132 10141 'PonderQuestionEditor' => 'PonderEditor', ··· 10140 10149 'PonderQuestionSearchEngine' => 'PhabricatorApplicationSearchEngine', 10141 10150 'PonderQuestionStatus' => 'PonderConstants', 10142 10151 'PonderQuestionStatusController' => 'PonderController', 10143 - 'PonderQuestionTransaction' => 'PhabricatorApplicationTransaction', 10152 + 'PonderQuestionStatusTransaction' => 'PonderQuestionTransactionType', 10153 + 'PonderQuestionTitleTransaction' => 'PonderQuestionTransactionType', 10154 + 'PonderQuestionTransaction' => 'PhabricatorModularTransaction', 10144 10155 'PonderQuestionTransactionComment' => 'PhabricatorApplicationTransactionComment', 10145 10156 'PonderQuestionTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 10157 + 'PonderQuestionTransactionType' => 'PhabricatorModularTransactionType', 10146 10158 'PonderQuestionViewController' => 'PonderController', 10147 10159 'PonderRemarkupRule' => 'PhabricatorObjectRemarkupRule', 10148 10160 'PonderSchemaSpec' => 'PhabricatorConfigSchemaSpec',
+1 -1
src/applications/ponder/controller/PonderAnswerSaveController.php
··· 38 38 39 39 $xactions = array(); 40 40 $xactions[] = id(new PonderQuestionTransaction()) 41 - ->setTransactionType(PonderQuestionTransaction::TYPE_ANSWERS) 41 + ->setTransactionType(PonderQuestionAnswerTransaction::TRANSACTIONTYPE) 42 42 ->setNewValue( 43 43 array( 44 44 '+' => array(
+7 -4
src/applications/ponder/controller/PonderQuestionEditController.php
··· 63 63 $xactions = array(); 64 64 65 65 $xactions[] = id(clone $template) 66 - ->setTransactionType(PonderQuestionTransaction::TYPE_TITLE) 66 + ->setTransactionType(PonderQuestionTitleTransaction::TRANSACTIONTYPE) 67 67 ->setNewValue($v_title); 68 68 69 69 $xactions[] = id(clone $template) 70 - ->setTransactionType(PonderQuestionTransaction::TYPE_CONTENT) 70 + ->setTransactionType( 71 + PonderQuestionContentTransaction::TRANSACTIONTYPE) 71 72 ->setNewValue($v_content); 72 73 73 74 $xactions[] = id(clone $template) 74 - ->setTransactionType(PonderQuestionTransaction::TYPE_ANSWERWIKI) 75 + ->setTransactionType( 76 + PonderQuestionAnswerWikiTransaction::TRANSACTIONTYPE) 75 77 ->setNewValue($v_wiki); 76 78 77 79 if (!$is_new) { 78 80 $xactions[] = id(clone $template) 79 - ->setTransactionType(PonderQuestionTransaction::TYPE_STATUS) 81 + ->setTransactionType( 82 + PonderQuestionStatusTransaction::TRANSACTIONTYPE) 80 83 ->setNewValue($v_status); 81 84 } 82 85
+1 -1
src/applications/ponder/controller/PonderQuestionStatusController.php
··· 28 28 29 29 $xactions = array(); 30 30 $xactions[] = id(new PonderQuestionTransaction()) 31 - ->setTransactionType(PonderQuestionTransaction::TYPE_STATUS) 31 + ->setTransactionType(PonderQuestionStatusTransaction::TRANSACTIONTYPE) 32 32 ->setNewValue($v_status); 33 33 34 34 $editor = id(new PonderQuestionEditor())
+6 -114
src/applications/ponder/editor/PonderQuestionEditor.php
··· 32 32 33 33 foreach ($xactions as $xaction) { 34 34 switch ($xaction->getTransactionType()) { 35 - case PonderQuestionTransaction::TYPE_ANSWERS: 35 + case PonderQuestionAnswerTransaction::TRANSACTIONTYPE: 36 36 return true; 37 37 } 38 38 } ··· 46 46 47 47 foreach ($xactions as $xaction) { 48 48 switch ($xaction->getTransactionType()) { 49 - case PonderQuestionTransaction::TYPE_ANSWERS: 49 + case PonderQuestionAnswerTransaction::TRANSACTIONTYPE: 50 50 $new_value = $xaction->getNewValue(); 51 51 $new = idx($new_value, '+', array()); 52 52 foreach ($new as $new_answer) { ··· 70 70 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; 71 71 $types[] = PhabricatorTransactions::TYPE_SPACE; 72 72 73 - $types[] = PonderQuestionTransaction::TYPE_TITLE; 74 - $types[] = PonderQuestionTransaction::TYPE_CONTENT; 75 - $types[] = PonderQuestionTransaction::TYPE_ANSWERS; 76 - $types[] = PonderQuestionTransaction::TYPE_STATUS; 77 - $types[] = PonderQuestionTransaction::TYPE_ANSWERWIKI; 78 - 79 73 return $types; 80 74 } 81 75 82 - protected function getCustomTransactionOldValue( 83 - PhabricatorLiskDAO $object, 84 - PhabricatorApplicationTransaction $xaction) { 85 - 86 - switch ($xaction->getTransactionType()) { 87 - case PonderQuestionTransaction::TYPE_TITLE: 88 - return $object->getTitle(); 89 - case PonderQuestionTransaction::TYPE_CONTENT: 90 - return $object->getContent(); 91 - case PonderQuestionTransaction::TYPE_ANSWERS: 92 - return mpull($object->getAnswers(), 'getPHID'); 93 - case PonderQuestionTransaction::TYPE_STATUS: 94 - return $object->getStatus(); 95 - case PonderQuestionTransaction::TYPE_ANSWERWIKI: 96 - return $object->getAnswerWiki(); 97 - } 98 - } 99 - 100 - protected function getCustomTransactionNewValue( 101 - PhabricatorLiskDAO $object, 102 - PhabricatorApplicationTransaction $xaction) { 103 - 104 - switch ($xaction->getTransactionType()) { 105 - case PonderQuestionTransaction::TYPE_TITLE: 106 - case PonderQuestionTransaction::TYPE_CONTENT: 107 - case PonderQuestionTransaction::TYPE_STATUS: 108 - case PonderQuestionTransaction::TYPE_ANSWERWIKI: 109 - return $xaction->getNewValue(); 110 - case PonderQuestionTransaction::TYPE_ANSWERS: 111 - $raw_new_value = $xaction->getNewValue(); 112 - $new_value = array(); 113 - foreach ($raw_new_value as $key => $answers) { 114 - $phids = array(); 115 - foreach ($answers as $answer) { 116 - $obj = idx($answer, 'answer'); 117 - if (!$answer) { 118 - continue; 119 - } 120 - $phids[] = $obj->getPHID(); 121 - } 122 - $new_value[$key] = $phids; 123 - } 124 - $xaction->setNewValue($new_value); 125 - return $this->getPHIDTransactionNewValue($xaction); 126 - } 127 - } 128 - 129 - protected function applyCustomInternalTransaction( 130 - PhabricatorLiskDAO $object, 131 - PhabricatorApplicationTransaction $xaction) { 132 - 133 - switch ($xaction->getTransactionType()) { 134 - case PonderQuestionTransaction::TYPE_TITLE: 135 - $object->setTitle($xaction->getNewValue()); 136 - break; 137 - case PonderQuestionTransaction::TYPE_CONTENT: 138 - $object->setContent($xaction->getNewValue()); 139 - break; 140 - case PonderQuestionTransaction::TYPE_STATUS: 141 - $object->setStatus($xaction->getNewValue()); 142 - break; 143 - case PonderQuestionTransaction::TYPE_ANSWERWIKI: 144 - $object->setAnswerWiki($xaction->getNewValue()); 145 - break; 146 - case PonderQuestionTransaction::TYPE_ANSWERS: 147 - $old = $xaction->getOldValue(); 148 - $new = $xaction->getNewValue(); 149 - 150 - $add = array_diff_key($new, $old); 151 - $rem = array_diff_key($old, $new); 152 - 153 - $count = $object->getAnswerCount(); 154 - $count += count($add); 155 - $count -= count($rem); 156 - 157 - $object->setAnswerCount($count); 158 - break; 159 - } 160 - } 161 - 162 - protected function applyCustomExternalTransaction( 163 - PhabricatorLiskDAO $object, 164 - PhabricatorApplicationTransaction $xaction) { 165 - return; 166 - } 167 - 168 - protected function mergeTransactions( 169 - PhabricatorApplicationTransaction $u, 170 - PhabricatorApplicationTransaction $v) { 171 - 172 - $type = $u->getTransactionType(); 173 - switch ($type) { 174 - case PonderQuestionTransaction::TYPE_TITLE: 175 - case PonderQuestionTransaction::TYPE_CONTENT: 176 - case PonderQuestionTransaction::TYPE_STATUS: 177 - case PonderQuestionTransaction::TYPE_ANSWERWIKI: 178 - return $v; 179 - } 180 - 181 - return parent::mergeTransactions($u, $v); 182 - } 183 - 184 76 protected function supportsSearch() { 185 77 return true; 186 78 } ··· 190 82 PhabricatorApplicationTransaction $xaction) { 191 83 192 84 switch ($xaction->getTransactionType()) { 193 - case PonderQuestionTransaction::TYPE_ANSWERS: 85 + case PonderQuestionAnswerTransaction::TRANSACTIONTYPE: 194 86 return false; 195 87 } 196 88 ··· 202 94 array $xactions) { 203 95 foreach ($xactions as $xaction) { 204 96 switch ($xaction->getTransactionType()) { 205 - case PonderQuestionTransaction::TYPE_ANSWERS: 97 + case PonderQuestionAnswerTransaction::TRANSACTIONTYPE: 206 98 return false; 207 99 } 208 100 } ··· 221 113 array $xactions) { 222 114 foreach ($xactions as $xaction) { 223 115 switch ($xaction->getTransactionType()) { 224 - case PonderQuestionTransaction::TYPE_ANSWERS: 116 + case PonderQuestionAnswerTransaction::TRANSACTIONTYPE: 225 117 return false; 226 118 } 227 119 } ··· 269 161 $old = $xaction->getOldValue(); 270 162 $new = $xaction->getNewValue(); 271 163 // If the user just asked the question, add the question text. 272 - if ($type == PonderQuestionTransaction::TYPE_CONTENT) { 164 + if ($type == PonderQuestionContentTransaction::TRANSACTIONTYPE) { 273 165 if ($old === null) { 274 166 $body->addRawSection($new); 275 167 }
+8 -271
src/applications/ponder/storage/PonderQuestionTransaction.php
··· 1 1 <?php 2 2 3 3 final class PonderQuestionTransaction 4 - extends PhabricatorApplicationTransaction { 5 - 6 - const TYPE_TITLE = 'ponder.question:question'; 7 - const TYPE_CONTENT = 'ponder.question:content'; 8 - const TYPE_ANSWERS = 'ponder.question:answer'; 9 - const TYPE_STATUS = 'ponder.question:status'; 10 - const TYPE_ANSWERWIKI = 'ponder.question:wiki'; 4 + extends PhabricatorModularTransaction { 11 5 12 6 const MAILTAG_DETAILS = 'question:details'; 13 7 const MAILTAG_COMMENT = 'question:comment'; ··· 30 24 return new PonderQuestionTransactionComment(); 31 25 } 32 26 33 - public function getRequiredHandlePHIDs() { 34 - $phids = parent::getRequiredHandlePHIDs(); 35 - 36 - switch ($this->getTransactionType()) { 37 - case self::TYPE_ANSWERS: 38 - $phids[] = $this->getNewAnswerPHID(); 39 - $phids[] = $this->getObjectPHID(); 40 - break; 41 - } 42 - 43 - return $phids; 44 - } 45 - 46 - public function getRemarkupBlocks() { 47 - $blocks = parent::getRemarkupBlocks(); 48 - switch ($this->getTransactionType()) { 49 - case self::TYPE_CONTENT: 50 - $blocks[] = $this->getNewValue(); 51 - break; 52 - } 53 - return $blocks; 54 - } 55 - 56 - public function getTitle() { 57 - $author_phid = $this->getAuthorPHID(); 58 - $object_phid = $this->getObjectPHID(); 59 - 60 - $old = $this->getOldValue(); 61 - $new = $this->getNewValue(); 62 - 63 - switch ($this->getTransactionType()) { 64 - case self::TYPE_TITLE: 65 - if ($old === null) { 66 - return pht( 67 - '%s asked this question.', 68 - $this->renderHandleLink($author_phid)); 69 - } else { 70 - return pht( 71 - '%s edited the question title from "%s" to "%s".', 72 - $this->renderHandleLink($author_phid), 73 - $old, 74 - $new); 75 - } 76 - case self::TYPE_CONTENT: 77 - return pht( 78 - '%s edited the question description.', 79 - $this->renderHandleLink($author_phid)); 80 - case self::TYPE_ANSWERWIKI: 81 - return pht( 82 - '%s edited the question answer wiki.', 83 - $this->renderHandleLink($author_phid)); 84 - case self::TYPE_ANSWERS: 85 - $answer_handle = $this->getHandle($this->getNewAnswerPHID()); 86 - $question_handle = $this->getHandle($object_phid); 87 - 88 - return pht( 89 - '%s answered %s', 90 - $this->renderHandleLink($author_phid), 91 - $this->renderHandleLink($object_phid)); 92 - case self::TYPE_STATUS: 93 - switch ($new) { 94 - case PonderQuestionStatus::STATUS_OPEN: 95 - return pht( 96 - '%s reopened this question.', 97 - $this->renderHandleLink($author_phid)); 98 - case PonderQuestionStatus::STATUS_CLOSED_RESOLVED: 99 - return pht( 100 - '%s closed this question as resolved.', 101 - $this->renderHandleLink($author_phid)); 102 - case PonderQuestionStatus::STATUS_CLOSED_OBSOLETE: 103 - return pht( 104 - '%s closed this question as obsolete.', 105 - $this->renderHandleLink($author_phid)); 106 - case PonderQuestionStatus::STATUS_CLOSED_INVALID: 107 - return pht( 108 - '%s closed this question as invalid.', 109 - $this->renderHandleLink($author_phid)); 110 - } 111 - } 112 - 113 - return parent::getTitle(); 27 + public function getBaseTransactionClass() { 28 + return 'PonderQuestionTransactionType'; 114 29 } 115 30 116 31 public function getMailTags() { ··· 120 35 case PhabricatorTransactions::TYPE_COMMENT: 121 36 $tags[] = self::MAILTAG_COMMENT; 122 37 break; 123 - case self::TYPE_TITLE: 124 - case self::TYPE_CONTENT: 125 - case self::TYPE_STATUS: 126 - case self::TYPE_ANSWERWIKI: 38 + case PonderQuestionTitleTransaction::TRANSACTIONTYPE: 39 + case PonderQuestionContentTransaction::TRANSACTIONTYPE: 40 + case PonderQuestionStatusTransaction::TRANSACTIONTYPE: 41 + case PonderQuestionAnswerWikiTransaction::TRANSACTIONTYPE: 127 42 $tags[] = self::MAILTAG_DETAILS; 128 43 break; 129 - case self::TYPE_ANSWERS: 44 + case PonderQuestionAnswerTransaction::TRANSACTIONTYPE: 130 45 $tags[] = self::MAILTAG_ANSWERS; 131 46 break; 132 47 default: ··· 134 49 break; 135 50 } 136 51 return $tags; 137 - } 138 - 139 - public function getIcon() { 140 - $old = $this->getOldValue(); 141 - $new = $this->getNewValue(); 142 - 143 - switch ($this->getTransactionType()) { 144 - case self::TYPE_TITLE: 145 - case self::TYPE_CONTENT: 146 - case self::TYPE_ANSWERWIKI: 147 - return 'fa-pencil'; 148 - case self::TYPE_STATUS: 149 - return PonderQuestionStatus::getQuestionStatusIcon($new); 150 - case self::TYPE_ANSWERS: 151 - return 'fa-plus'; 152 - } 153 - 154 - return parent::getIcon(); 155 - } 156 - 157 - public function getColor() { 158 - $old = $this->getOldValue(); 159 - $new = $this->getNewValue(); 160 - 161 - switch ($this->getTransactionType()) { 162 - case self::TYPE_TITLE: 163 - case self::TYPE_CONTENT: 164 - case self::TYPE_ANSWERWIKI: 165 - return PhabricatorTransactions::COLOR_BLUE; 166 - case self::TYPE_ANSWERS: 167 - return PhabricatorTransactions::COLOR_GREEN; 168 - case self::TYPE_STATUS: 169 - return PonderQuestionStatus::getQuestionStatusTagColor($new); 170 - } 171 - } 172 - 173 - public function hasChangeDetails() { 174 - switch ($this->getTransactionType()) { 175 - case self::TYPE_CONTENT: 176 - case self::TYPE_ANSWERWIKI: 177 - return true; 178 - } 179 - return parent::hasChangeDetails(); 180 - } 181 - 182 - public function renderChangeDetails(PhabricatorUser $viewer) { 183 - return $this->renderTextCorpusChangeDetails( 184 - $viewer, 185 - $this->getOldValue(), 186 - $this->getNewValue()); 187 - } 188 - 189 - public function getActionStrength() { 190 - $old = $this->getOldValue(); 191 - $new = $this->getNewValue(); 192 - 193 - switch ($this->getTransactionType()) { 194 - case self::TYPE_TITLE: 195 - if ($old === null) { 196 - return 3; 197 - } 198 - break; 199 - case self::TYPE_ANSWERS: 200 - return 2; 201 - } 202 - 203 - return parent::getActionStrength(); 204 - } 205 - 206 - public function getActionName() { 207 - $old = $this->getOldValue(); 208 - $new = $this->getNewValue(); 209 - 210 - switch ($this->getTransactionType()) { 211 - case self::TYPE_TITLE: 212 - if ($old === null) { 213 - return pht('Asked'); 214 - } 215 - break; 216 - case self::TYPE_ANSWERS: 217 - return pht('Answered'); 218 - } 219 - 220 - return parent::getActionName(); 221 - } 222 - 223 - public function getTitleForFeed() { 224 - $author_phid = $this->getAuthorPHID(); 225 - $object_phid = $this->getObjectPHID(); 226 - 227 - $old = $this->getOldValue(); 228 - $new = $this->getNewValue(); 229 - 230 - switch ($this->getTransactionType()) { 231 - case self::TYPE_TITLE: 232 - if ($old === null) { 233 - return pht( 234 - '%s asked a question: %s', 235 - $this->renderHandleLink($author_phid), 236 - $this->renderHandleLink($object_phid)); 237 - } else { 238 - return pht( 239 - '%s edited the title of %s (was "%s")', 240 - $this->renderHandleLink($author_phid), 241 - $this->renderHandleLink($object_phid), 242 - $old); 243 - } 244 - case self::TYPE_CONTENT: 245 - return pht( 246 - '%s edited the description of %s', 247 - $this->renderHandleLink($author_phid), 248 - $this->renderHandleLink($object_phid)); 249 - case self::TYPE_ANSWERWIKI: 250 - return pht( 251 - '%s edited the answer wiki for %s', 252 - $this->renderHandleLink($author_phid), 253 - $this->renderHandleLink($object_phid)); 254 - case self::TYPE_ANSWERS: 255 - $answer_handle = $this->getHandle($this->getNewAnswerPHID()); 256 - $question_handle = $this->getHandle($object_phid); 257 - return pht( 258 - '%s answered %s', 259 - $this->renderHandleLink($author_phid), 260 - $answer_handle->renderLink($question_handle->getFullName())); 261 - case self::TYPE_STATUS: 262 - switch ($new) { 263 - case PonderQuestionStatus::STATUS_OPEN: 264 - return pht( 265 - '%s reopened %s.', 266 - $this->renderHandleLink($author_phid), 267 - $this->renderHandleLink($object_phid)); 268 - case PonderQuestionStatus::STATUS_CLOSED_RESOLVED: 269 - return pht( 270 - '%s closed %s as resolved.', 271 - $this->renderHandleLink($author_phid), 272 - $this->renderHandleLink($object_phid)); 273 - case PonderQuestionStatus::STATUS_CLOSED_INVALID: 274 - return pht( 275 - '%s closed %s as invalid.', 276 - $this->renderHandleLink($author_phid), 277 - $this->renderHandleLink($object_phid)); 278 - case PonderQuestionStatus::STATUS_CLOSED_OBSOLETE: 279 - return pht( 280 - '%s closed %s as obsolete.', 281 - $this->renderHandleLink($author_phid), 282 - $this->renderHandleLink($object_phid)); 283 - } 284 - } 285 - 286 - return parent::getTitleForFeed(); 287 - } 288 - 289 - public function getRemarkupBodyForFeed(PhabricatorFeedStory $story) { 290 - $text = null; 291 - switch ($this->getTransactionType()) { 292 - case self::TYPE_CONTENT: 293 - $text = $this->getNewValue(); 294 - break; 295 - } 296 - return $text; 297 - } 298 - 299 - /** 300 - * Currently the application only supports adding answers one at a time. 301 - * This data is stored as a list of phids. Use this function to get the 302 - * new phid. 303 - */ 304 - private function getNewAnswerPHID() { 305 - $new = $this->getNewValue(); 306 - $old = $this->getOldValue(); 307 - $add = array_diff($new, $old); 308 - 309 - if (count($add) != 1) { 310 - throw new Exception( 311 - pht('There should be only one answer added at a time.')); 312 - } 313 - 314 - return reset($add); 315 52 } 316 53 317 54 }
+28
src/applications/ponder/xaction/PonderQuestionAnswerTransaction.php
··· 1 + <?php 2 + 3 + final class PonderQuestionAnswerTransaction 4 + extends PonderQuestionTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'ponder.question:answer'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getAnswers(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $count = $object->getAnswerCount(); 14 + $count++; 15 + $object->setAnswerCount($count); 16 + } 17 + 18 + public function getTitle() { 19 + return pht( 20 + '%s added an answer.', 21 + $this->renderAuthor()); 22 + } 23 + 24 + public function getIcon() { 25 + return 'fa-plus'; 26 + } 27 + 28 + }
+56
src/applications/ponder/xaction/PonderQuestionAnswerWikiTransaction.php
··· 1 + <?php 2 + 3 + final class PonderQuestionAnswerWikiTransaction 4 + extends PonderQuestionTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'ponder.question:wiki'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getAnswerWiki(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setAnswerWiki($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s updated the answer wiki.', 19 + $this->renderAuthor()); 20 + } 21 + 22 + public function getTitleForFeed() { 23 + return pht( 24 + '%s updated the answer wiki 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 WIKI'); 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 + }
+56
src/applications/ponder/xaction/PonderQuestionContentTransaction.php
··· 1 + <?php 2 + 3 + final class PonderQuestionContentTransaction 4 + extends PonderQuestionTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'ponder.question: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 question details.', 19 + $this->renderAuthor()); 20 + } 21 + 22 + public function getTitleForFeed() { 23 + return pht( 24 + '%s updated the question 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 QUESTION 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 + }
+74
src/applications/ponder/xaction/PonderQuestionStatusTransaction.php
··· 1 + <?php 2 + 3 + final class PonderQuestionStatusTransaction 4 + extends PonderQuestionTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'ponder.question: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 + switch ($new) { 19 + case PonderQuestionStatus::STATUS_OPEN: 20 + return pht( 21 + '%s reopened this question.', 22 + $this->renderAuthor()); 23 + case PonderQuestionStatus::STATUS_CLOSED_RESOLVED: 24 + return pht( 25 + '%s closed this question as resolved.', 26 + $this->renderAuthor()); 27 + case PonderQuestionStatus::STATUS_CLOSED_OBSOLETE: 28 + return pht( 29 + '%s closed this question as obsolete.', 30 + $this->renderAuthor()); 31 + case PonderQuestionStatus::STATUS_CLOSED_INVALID: 32 + return pht( 33 + '%s closed this question as invalid.', 34 + $this->renderAuthor()); 35 + } 36 + } 37 + 38 + public function getTitleForFeed() { 39 + $new = $this->getNewValue(); 40 + switch ($new) { 41 + case PonderQuestionStatus::STATUS_OPEN: 42 + return pht( 43 + '%s reopened %s.', 44 + $this->renderAuthor(), 45 + $this->renderObject()); 46 + case PonderQuestionStatus::STATUS_CLOSED_RESOLVED: 47 + return pht( 48 + '%s closed %s as resolved.', 49 + $this->renderAuthor(), 50 + $this->renderObject()); 51 + case PonderQuestionStatus::STATUS_CLOSED_INVALID: 52 + return pht( 53 + '%s closed %s as invalid.', 54 + $this->renderAuthor(), 55 + $this->renderObject()); 56 + case PonderQuestionStatus::STATUS_CLOSED_OBSOLETE: 57 + return pht( 58 + '%s closed %s as obsolete.', 59 + $this->renderAuthor(), 60 + $this->renderObject()); 61 + } 62 + } 63 + 64 + public function getIcon() { 65 + $new = $this->getNewValue(); 66 + return PonderQuestionStatus::getQuestionStatusIcon($new); 67 + } 68 + 69 + public function getColor() { 70 + $new = $this->getNewValue(); 71 + return PonderQuestionStatus::getQuestionStatusTagColor($new); 72 + } 73 + 74 + }
+55
src/applications/ponder/xaction/PonderQuestionTitleTransaction.php
··· 1 + <?php 2 + 3 + final class PonderQuestionTitleTransaction 4 + extends PonderQuestionTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'ponder.question:question'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getTitle(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setTitle($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s updated the question from %s to %s.', 19 + $this->renderAuthor(), 20 + $this->renderOldValue(), 21 + $this->renderNewValue()); 22 + } 23 + 24 + public function getTitleForFeed() { 25 + return pht( 26 + '%s updated %s from %s to %s.', 27 + $this->renderAuthor(), 28 + $this->renderObject(), 29 + $this->renderOldValue(), 30 + $this->renderNewValue()); 31 + } 32 + 33 + public function validateTransactions($object, array $xactions) { 34 + $errors = array(); 35 + 36 + if ($this->isEmptyTextTransaction($object->getTitle(), $xactions)) { 37 + $errors[] = $this->newRequiredError( 38 + pht('Questions must have a title.')); 39 + } 40 + 41 + $max_length = $object->getColumnMaximumByteLength('title'); 42 + foreach ($xactions as $xaction) { 43 + $new_value = $xaction->getNewValue(); 44 + $new_length = strlen($new_value); 45 + if ($new_length > $max_length) { 46 + $errors[] = $this->newInvalidError( 47 + pht('The title can be no longer than %s characters.', 48 + new PhutilNumber($max_length))); 49 + } 50 + } 51 + 52 + return $errors; 53 + } 54 + 55 + }
+4
src/applications/ponder/xaction/PonderQuestionTransactionType.php
··· 1 + <?php 2 + 3 + abstract class PonderQuestionTransactionType 4 + extends PhabricatorModularTransactionType {}