mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-23 15:22:41 +01:00
Make Ponder status changes transaction-oriented and improve rendering of transactions
Summary: Ref T3373. Use transactions for status changes. Test Plan: {F52083} Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3373 Differential Revision: https://secure.phabricator.com/D6609
This commit is contained in:
parent
4be9ccaea8
commit
d4b24a2c07
3 changed files with 128 additions and 7 deletions
|
@ -12,7 +12,6 @@ final class PonderQuestionStatusController
|
|||
}
|
||||
|
||||
public function processRequest() {
|
||||
|
||||
$request = $this->getRequest();
|
||||
$viewer = $request->getUser();
|
||||
|
||||
|
@ -29,20 +28,27 @@ final class PonderQuestionStatusController
|
|||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
// TODO: Use transactions.
|
||||
|
||||
switch ($this->status) {
|
||||
case 'open':
|
||||
$question->setStatus(PonderQuestionStatus::STATUS_OPEN);
|
||||
$status = PonderQuestionStatus::STATUS_OPEN;
|
||||
break;
|
||||
case 'close':
|
||||
$question->setStatus(PonderQuestionStatus::STATUS_CLOSED);
|
||||
$status = PonderQuestionStatus::STATUS_CLOSED;
|
||||
break;
|
||||
default:
|
||||
return new Aphront400Response();
|
||||
}
|
||||
|
||||
$question->save();
|
||||
$xactions = array();
|
||||
$xactions[] = id(new PonderQuestionTransaction())
|
||||
->setTransactionType(PonderQuestionTransaction::TYPE_STATUS)
|
||||
->setNewValue($status);
|
||||
|
||||
$editor = id(new PonderQuestionEditor())
|
||||
->setActor($viewer)
|
||||
->setContentSourceFromRequest($request);
|
||||
|
||||
$editor->applyTransactions($question, $xactions);
|
||||
|
||||
return id(new AphrontRedirectResponse())->setURI('/Q'.$question->getID());
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ final class PonderQuestionEditor
|
|||
$types[] = PonderQuestionTransaction::TYPE_TITLE;
|
||||
$types[] = PonderQuestionTransaction::TYPE_CONTENT;
|
||||
$types[] = PonderQuestionTransaction::TYPE_ANSWERS;
|
||||
$types[] = PonderQuestionTransaction::TYPE_STATUS;
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
@ -60,6 +61,8 @@ final class PonderQuestionEditor
|
|||
return $object->getContent();
|
||||
case PonderQuestionTransaction::TYPE_ANSWERS:
|
||||
return mpull($object->getAnswers(), 'getPHID');
|
||||
case PonderQuestionTransaction::TYPE_STATUS:
|
||||
return $object->getStatus();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,6 +73,7 @@ final class PonderQuestionEditor
|
|||
switch ($xaction->getTransactionType()) {
|
||||
case PonderQuestionTransaction::TYPE_TITLE:
|
||||
case PonderQuestionTransaction::TYPE_CONTENT:
|
||||
case PonderQuestionTransaction::TYPE_STATUS:
|
||||
return $xaction->getNewValue();
|
||||
case PonderQuestionTransaction::TYPE_ANSWERS:
|
||||
$raw_new_value = $xaction->getNewValue();
|
||||
|
@ -101,6 +105,9 @@ final class PonderQuestionEditor
|
|||
case PonderQuestionTransaction::TYPE_CONTENT:
|
||||
$object->setContent($xaction->getNewValue());
|
||||
break;
|
||||
case PonderQuestionTransaction::TYPE_STATUS:
|
||||
$object->setStatus($xaction->getNewValue());
|
||||
break;
|
||||
case PonderQuestionTransaction::TYPE_ANSWERS:
|
||||
$old = $xaction->getOldValue();
|
||||
$new = $xaction->getNewValue();
|
||||
|
@ -131,6 +138,7 @@ final class PonderQuestionEditor
|
|||
switch ($type) {
|
||||
case PonderQuestionTransaction::TYPE_TITLE:
|
||||
case PonderQuestionTransaction::TYPE_CONTENT:
|
||||
case PonderQuestionTransaction::TYPE_STATUS:
|
||||
return $v;
|
||||
}
|
||||
|
||||
|
@ -139,6 +147,5 @@ final class PonderQuestionEditor
|
|||
|
||||
// TODO: Feed support
|
||||
// TODO: Mail support
|
||||
// TODO: Add/remove answers
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ final class PonderQuestionTransaction
|
|||
const TYPE_TITLE = 'ponder.question:question';
|
||||
const TYPE_CONTENT = 'ponder.question:content';
|
||||
const TYPE_ANSWERS = 'ponder.question:answer';
|
||||
const TYPE_STATUS = 'ponder.question:status';
|
||||
|
||||
public function getApplicationName() {
|
||||
return 'ponder';
|
||||
|
@ -27,6 +28,113 @@ final class PonderQuestionTransaction
|
|||
return pht('question');
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
$author_phid = $this->getAuthorPHID();
|
||||
|
||||
$old = $this->getOldValue();
|
||||
$new = $this->getNewValue();
|
||||
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_TITLE:
|
||||
if ($old === null) {
|
||||
return pht(
|
||||
'%s created this question.',
|
||||
$this->renderHandleLink($author_phid));
|
||||
} else {
|
||||
return pht(
|
||||
'%s edited the question title from "%s" to "%s".',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$old,
|
||||
$new);
|
||||
}
|
||||
case self::TYPE_CONTENT:
|
||||
return pht(
|
||||
'%s edited the question description.',
|
||||
$this->renderHandleLink($author_phid));
|
||||
case self::TYPE_ANSWERS:
|
||||
// TODO: This could be richer.
|
||||
return pht(
|
||||
'%s added an answer.',
|
||||
$this->renderHandleLink($author_phid));
|
||||
case self::TYPE_STATUS:
|
||||
switch ($new) {
|
||||
case PonderQuestionStatus::STATUS_OPEN:
|
||||
return pht(
|
||||
'%s reopened this question.',
|
||||
$this->renderHandleLink($author_phid));
|
||||
case PonderQuestionStatus::STATUS_CLOSED:
|
||||
return pht(
|
||||
'%s closed this question.',
|
||||
$this->renderHandleLink($author_phid));
|
||||
}
|
||||
}
|
||||
|
||||
return parent::getTitle();
|
||||
}
|
||||
|
||||
public function getIcon() {
|
||||
$old = $this->getOldValue();
|
||||
$new = $this->getNewValue();
|
||||
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_TITLE:
|
||||
case self::TYPE_CONTENT:
|
||||
return 'edit';
|
||||
case self::TYPE_STATUS:
|
||||
switch ($new) {
|
||||
case PonderQuestionStatus::STATUS_OPEN:
|
||||
return 'enable';
|
||||
case PonderQuestionStatus::STATUS_CLOSED:
|
||||
return 'disable';
|
||||
}
|
||||
case self::TYPE_ANSWERS:
|
||||
return 'new';
|
||||
}
|
||||
|
||||
return parent::getIcon();
|
||||
}
|
||||
|
||||
public function getColor() {
|
||||
$old = $this->getOldValue();
|
||||
$new = $this->getNewValue();
|
||||
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_TITLE:
|
||||
case self::TYPE_CONTENT:
|
||||
return PhabricatorTransactions::COLOR_BLUE;
|
||||
case self::TYPE_ANSWERS:
|
||||
return PhabricatorTransactions::COLOR_GREEN;
|
||||
case self::TYPE_STATUS:
|
||||
switch ($new) {
|
||||
case PonderQuestionStatus::STATUS_OPEN:
|
||||
return PhabricatorTransactions::COLOR_GREEN;
|
||||
case PonderQuestionStatus::STATUS_CLOSED:
|
||||
return PhabricatorTransactions::COLOR_BLACK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function hasChangeDetails() {
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_CONTENT:
|
||||
return true;
|
||||
}
|
||||
return parent::hasChangeDetails();
|
||||
}
|
||||
|
||||
public function renderChangeDetails(PhabricatorUser $viewer) {
|
||||
$old = $this->getOldValue();
|
||||
$new = $this->getNewValue();
|
||||
|
||||
$view = id(new PhabricatorApplicationTransactionTextDiffDetailView())
|
||||
->setUser($viewer)
|
||||
->setOldText($old)
|
||||
->setNewText($new);
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue