mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
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
This commit is contained in:
parent
dff028c490
commit
eaaba278a9
9 changed files with 154 additions and 212 deletions
|
@ -4551,18 +4551,22 @@ phutil_register_library_map(array(
|
|||
'PonderAddAnswerView' => 'applications/ponder/view/PonderAddAnswerView.php',
|
||||
'PonderAnswer' => 'applications/ponder/storage/PonderAnswer.php',
|
||||
'PonderAnswerCommentController' => 'applications/ponder/controller/PonderAnswerCommentController.php',
|
||||
'PonderAnswerContentTransaction' => 'applications/ponder/xaction/PonderAnswerContentTransaction.php',
|
||||
'PonderAnswerEditController' => 'applications/ponder/controller/PonderAnswerEditController.php',
|
||||
'PonderAnswerEditor' => 'applications/ponder/editor/PonderAnswerEditor.php',
|
||||
'PonderAnswerHistoryController' => 'applications/ponder/controller/PonderAnswerHistoryController.php',
|
||||
'PonderAnswerMailReceiver' => 'applications/ponder/mail/PonderAnswerMailReceiver.php',
|
||||
'PonderAnswerPHIDType' => 'applications/ponder/phid/PonderAnswerPHIDType.php',
|
||||
'PonderAnswerQuery' => 'applications/ponder/query/PonderAnswerQuery.php',
|
||||
'PonderAnswerQuestionIDTransaction' => 'applications/ponder/xaction/PonderAnswerQuestionIDTransaction.php',
|
||||
'PonderAnswerReplyHandler' => 'applications/ponder/mail/PonderAnswerReplyHandler.php',
|
||||
'PonderAnswerSaveController' => 'applications/ponder/controller/PonderAnswerSaveController.php',
|
||||
'PonderAnswerStatus' => 'applications/ponder/constants/PonderAnswerStatus.php',
|
||||
'PonderAnswerStatusTransaction' => 'applications/ponder/xaction/PonderAnswerStatusTransaction.php',
|
||||
'PonderAnswerTransaction' => 'applications/ponder/storage/PonderAnswerTransaction.php',
|
||||
'PonderAnswerTransactionComment' => 'applications/ponder/storage/PonderAnswerTransactionComment.php',
|
||||
'PonderAnswerTransactionQuery' => 'applications/ponder/query/PonderAnswerTransactionQuery.php',
|
||||
'PonderAnswerTransactionType' => 'applications/ponder/xaction/PonderAnswerTransactionType.php',
|
||||
'PonderAnswerView' => 'applications/ponder/view/PonderAnswerView.php',
|
||||
'PonderConstants' => 'applications/ponder/constants/PonderConstants.php',
|
||||
'PonderController' => 'applications/ponder/controller/PonderController.php',
|
||||
|
@ -10099,18 +10103,22 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDestructibleInterface',
|
||||
),
|
||||
'PonderAnswerCommentController' => 'PonderController',
|
||||
'PonderAnswerContentTransaction' => 'PonderAnswerTransactionType',
|
||||
'PonderAnswerEditController' => 'PonderController',
|
||||
'PonderAnswerEditor' => 'PonderEditor',
|
||||
'PonderAnswerHistoryController' => 'PonderController',
|
||||
'PonderAnswerMailReceiver' => 'PhabricatorObjectMailReceiver',
|
||||
'PonderAnswerPHIDType' => 'PhabricatorPHIDType',
|
||||
'PonderAnswerQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PonderAnswerQuestionIDTransaction' => 'PonderAnswerTransactionType',
|
||||
'PonderAnswerReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
|
||||
'PonderAnswerSaveController' => 'PonderController',
|
||||
'PonderAnswerStatus' => 'PonderConstants',
|
||||
'PonderAnswerTransaction' => 'PhabricatorApplicationTransaction',
|
||||
'PonderAnswerStatusTransaction' => 'PonderAnswerTransactionType',
|
||||
'PonderAnswerTransaction' => 'PhabricatorModularTransaction',
|
||||
'PonderAnswerTransactionComment' => 'PhabricatorApplicationTransactionComment',
|
||||
'PonderAnswerTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
'PonderAnswerTransactionType' => 'PhabricatorModularTransactionType',
|
||||
'PonderAnswerView' => 'AphrontTagView',
|
||||
'PonderConstants' => 'Phobject',
|
||||
'PonderController' => 'PhabricatorController',
|
||||
|
|
|
@ -42,11 +42,11 @@ final class PonderAnswerEditController extends PonderController {
|
|||
if (!$errors) {
|
||||
$xactions = array();
|
||||
$xactions[] = id(new PonderAnswerTransaction())
|
||||
->setTransactionType(PonderAnswerTransaction::TYPE_CONTENT)
|
||||
->setTransactionType(PonderAnswerContentTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue($v_content);
|
||||
|
||||
$xactions[] = id(new PonderAnswerTransaction())
|
||||
->setTransactionType(PonderAnswerTransaction::TYPE_STATUS)
|
||||
->setTransactionType(PonderAnswerStatusTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue($v_status);
|
||||
|
||||
$editor = id(new PonderAnswerEditor())
|
||||
|
|
|
@ -58,11 +58,11 @@ final class PonderAnswerSaveController extends PonderController {
|
|||
$xactions = array();
|
||||
|
||||
$xactions[] = id(clone $template)
|
||||
->setTransactionType(PonderAnswerTransaction::TYPE_QUESTION_ID)
|
||||
->setTransactionType(PonderAnswerQuestionIDTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue($question->getID());
|
||||
|
||||
$xactions[] = id(clone $template)
|
||||
->setTransactionType(PonderAnswerTransaction::TYPE_CONTENT)
|
||||
->setTransactionType(PonderAnswerContentTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue($content);
|
||||
|
||||
$editor = id(new PonderAnswerEditor())
|
||||
|
|
|
@ -8,78 +8,11 @@ final class PonderAnswerEditor extends PonderEditor {
|
|||
|
||||
public function getTransactionTypes() {
|
||||
$types = parent::getTransactionTypes();
|
||||
|
||||
$types[] = PhabricatorTransactions::TYPE_COMMENT;
|
||||
$types[] = PhabricatorTransactions::TYPE_EDGE;
|
||||
|
||||
$types[] = PonderAnswerTransaction::TYPE_CONTENT;
|
||||
$types[] = PonderAnswerTransaction::TYPE_STATUS;
|
||||
$types[] = PonderAnswerTransaction::TYPE_QUESTION_ID;
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
protected function getCustomTransactionOldValue(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case PonderAnswerTransaction::TYPE_CONTENT:
|
||||
case PonderAnswerTransaction::TYPE_STATUS:
|
||||
return $object->getContent();
|
||||
case PonderAnswerTransaction::TYPE_QUESTION_ID:
|
||||
return $object->getQuestionID();
|
||||
}
|
||||
}
|
||||
|
||||
protected function getCustomTransactionNewValue(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case PonderAnswerTransaction::TYPE_CONTENT:
|
||||
case PonderAnswerTransaction::TYPE_STATUS:
|
||||
case PonderAnswerTransaction::TYPE_QUESTION_ID:
|
||||
return $xaction->getNewValue();
|
||||
}
|
||||
}
|
||||
|
||||
protected function applyCustomInternalTransaction(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case PonderAnswerTransaction::TYPE_CONTENT:
|
||||
$object->setContent($xaction->getNewValue());
|
||||
break;
|
||||
case PonderAnswerTransaction::TYPE_STATUS:
|
||||
$object->setStatus($xaction->getNewValue());
|
||||
break;
|
||||
case PonderAnswerTransaction::TYPE_QUESTION_ID:
|
||||
$object->setQuestionID($xaction->getNewValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function applyCustomExternalTransaction(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
return;
|
||||
}
|
||||
|
||||
protected function mergeTransactions(
|
||||
PhabricatorApplicationTransaction $u,
|
||||
PhabricatorApplicationTransaction $v) {
|
||||
|
||||
$type = $u->getTransactionType();
|
||||
switch ($type) {
|
||||
case PonderAnswerTransaction::TYPE_CONTENT:
|
||||
return $v;
|
||||
}
|
||||
|
||||
return parent::mergeTransactions($u, $v);
|
||||
}
|
||||
|
||||
protected function shouldSendMail(
|
||||
PhabricatorLiskDAO $object,
|
||||
array $xactions) {
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class PonderAnswerTransaction
|
||||
extends PhabricatorApplicationTransaction {
|
||||
|
||||
const TYPE_CONTENT = 'ponder.answer:content';
|
||||
const TYPE_STATUS = 'ponder.answer:status';
|
||||
const TYPE_QUESTION_ID = 'ponder.answer:question-id';
|
||||
extends PhabricatorModularTransaction {
|
||||
|
||||
public function getApplicationName() {
|
||||
return 'ponder';
|
||||
|
@ -23,141 +19,8 @@ final class PonderAnswerTransaction
|
|||
return new PonderAnswerTransactionComment();
|
||||
}
|
||||
|
||||
public function getRequiredHandlePHIDs() {
|
||||
$phids = parent::getRequiredHandlePHIDs();
|
||||
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_CONTENT:
|
||||
case self::TYPE_STATUS:
|
||||
$phids[] = $this->getObjectPHID();
|
||||
break;
|
||||
}
|
||||
|
||||
return $phids;
|
||||
}
|
||||
|
||||
public function getRemarkupBlocks() {
|
||||
$blocks = parent::getRemarkupBlocks();
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_CONTENT:
|
||||
$blocks[] = $this->getNewValue();
|
||||
break;
|
||||
}
|
||||
return $blocks;
|
||||
}
|
||||
|
||||
public function shouldHide() {
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_QUESTION_ID:
|
||||
return true;
|
||||
}
|
||||
return parent::shouldHide();
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
$author_phid = $this->getAuthorPHID();
|
||||
$object_phid = $this->getObjectPHID();
|
||||
|
||||
$old = $this->getOldValue();
|
||||
$new = $this->getNewValue();
|
||||
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_CONTENT:
|
||||
if ($old === '') {
|
||||
return pht(
|
||||
'%s added %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
} else {
|
||||
return pht(
|
||||
'%s edited %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
}
|
||||
break;
|
||||
case self::TYPE_STATUS:
|
||||
if ($new == PonderAnswerStatus::ANSWER_STATUS_VISIBLE) {
|
||||
return pht(
|
||||
'%s marked %s as visible.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
} else if ($new == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) {
|
||||
return pht(
|
||||
'%s marked %s as hidden.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return parent::getTitle();
|
||||
}
|
||||
|
||||
public function getTitleForFeed() {
|
||||
$author_phid = $this->getAuthorPHID();
|
||||
$object_phid = $this->getObjectPHID();
|
||||
|
||||
$old = $this->getOldValue();
|
||||
$new = $this->getNewValue();
|
||||
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_CONTENT:
|
||||
if ($old === '') {
|
||||
return pht(
|
||||
'%s added %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
} else {
|
||||
return pht(
|
||||
'%s updated %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
}
|
||||
break;
|
||||
case self::TYPE_STATUS:
|
||||
if ($new == PonderAnswerStatus::ANSWER_STATUS_VISIBLE) {
|
||||
return pht(
|
||||
'%s marked %s as visible.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
} else if ($new == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) {
|
||||
return pht(
|
||||
'%s marked %s as hidden.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return parent::getTitleForFeed();
|
||||
}
|
||||
|
||||
public function getRemarkupBodyForFeed(PhabricatorFeedStory $story) {
|
||||
$text = null;
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_CONTENT:
|
||||
$text = $this->getNewValue();
|
||||
break;
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
|
||||
public function hasChangeDetails() {
|
||||
$old = $this->getOldValue();
|
||||
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_CONTENT:
|
||||
return $old !== null;
|
||||
}
|
||||
return parent::hasChangeDetails();
|
||||
}
|
||||
|
||||
public function renderChangeDetails(PhabricatorUser $viewer) {
|
||||
return $this->renderTextCorpusChangeDetails(
|
||||
$viewer,
|
||||
$this->getOldValue(),
|
||||
$this->getNewValue());
|
||||
public function getBaseTransactionClass() {
|
||||
return 'PonderAnswerTransactionType';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
final class PonderAnswerContentTransaction
|
||||
extends PonderAnswerTransactionType {
|
||||
|
||||
const TRANSACTIONTYPE = 'ponder.answer:content';
|
||||
|
||||
public function generateOldValue($object) {
|
||||
return $object->getContent();
|
||||
}
|
||||
|
||||
public function applyInternalEffects($object, $value) {
|
||||
$object->setContent($value);
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
return pht(
|
||||
'%s updated the answer details.',
|
||||
$this->renderAuthor());
|
||||
}
|
||||
|
||||
public function getTitleForFeed() {
|
||||
return pht(
|
||||
'%s updated the answer details for %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject());
|
||||
}
|
||||
|
||||
public function hasChangeDetailView() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getMailDiffSectionHeader() {
|
||||
return pht('CHANGES TO ANSWER DETAILS');
|
||||
}
|
||||
|
||||
public function newChangeDetailView() {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
return id(new PhabricatorApplicationTransactionTextDiffDetailView())
|
||||
->setViewer($viewer)
|
||||
->setOldText($this->getOldValue())
|
||||
->setNewText($this->getNewValue());
|
||||
}
|
||||
|
||||
public function newRemarkupChanges() {
|
||||
$changes = array();
|
||||
|
||||
$changes[] = $this->newRemarkupChange()
|
||||
->setOldValue($this->getOldValue())
|
||||
->setNewValue($this->getNewValue());
|
||||
|
||||
return $changes;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
final class PonderAnswerQuestionIDTransaction
|
||||
extends PonderAnswerTransactionType {
|
||||
|
||||
const TRANSACTIONTYPE = 'ponder.answer:question-id';
|
||||
|
||||
public function generateOldValue($object) {
|
||||
return $object->getQuestionID();
|
||||
}
|
||||
|
||||
public function applyInternalEffects($object, $value) {
|
||||
$object->setQuestionID($value);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
final class PonderAnswerStatusTransaction
|
||||
extends PonderAnswerTransactionType {
|
||||
|
||||
const TRANSACTIONTYPE = 'ponder.answer:status';
|
||||
|
||||
public function generateOldValue($object) {
|
||||
return $object->getStatus();
|
||||
}
|
||||
|
||||
public function applyInternalEffects($object, $value) {
|
||||
$object->setStatus($value);
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
$new = $this->getNewValue();
|
||||
if ($new == PonderAnswerStatus::ANSWER_STATUS_VISIBLE) {
|
||||
return pht(
|
||||
'%s marked this answer as visible.',
|
||||
$this->renderAuthor());
|
||||
} else if ($new == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) {
|
||||
return pht(
|
||||
'%s marked this answer as hidden.',
|
||||
$this->renderAuthor());
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitleForFeed() {
|
||||
$new = $this->getNewValue();
|
||||
if ($new == PonderAnswerStatus::ANSWER_STATUS_VISIBLE) {
|
||||
return pht(
|
||||
'%s marked %s as visible.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject());
|
||||
} else if ($new == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) {
|
||||
return pht(
|
||||
'%s marked %s as hidden.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject());
|
||||
}
|
||||
}
|
||||
|
||||
public function getIcon() {
|
||||
$new = $this->getNewValue();
|
||||
if ($new == PonderAnswerStatus::ANSWER_STATUS_VISIBLE) {
|
||||
return 'fa-ban';
|
||||
} else if ($new == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) {
|
||||
return 'fa-check';
|
||||
}
|
||||
}
|
||||
|
||||
public function getColor() {
|
||||
$new = $this->getNewValue();
|
||||
if ($new == PonderAnswerStatus::ANSWER_STATUS_VISIBLE) {
|
||||
return 'green';
|
||||
} else if ($new == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) {
|
||||
return 'indigo';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
<?php
|
||||
|
||||
abstract class PonderAnswerTransactionType
|
||||
extends PhabricatorModularTransactionType {}
|
Loading…
Reference in a new issue