Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2891652
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
10 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/applications/ponder/controller/PonderQuestionStatusController.php b/src/applications/ponder/controller/PonderQuestionStatusController.php
index 2b92970442..99473ce3cf 100644
--- a/src/applications/ponder/controller/PonderQuestionStatusController.php
+++ b/src/applications/ponder/controller/PonderQuestionStatusController.php
@@ -1,50 +1,56 @@
<?php
final class PonderQuestionStatusController
extends PonderController {
private $status;
private $id;
public function willProcessRequest(array $data) {
$this->status = idx($data, 'status');
$this->id = idx($data, 'id');
}
public function processRequest() {
-
$request = $this->getRequest();
$viewer = $request->getUser();
$question = id(new PonderQuestionQuery())
->setViewer($viewer)
->withIDs(array($this->id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$question) {
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());
}
}
diff --git a/src/applications/ponder/editor/PonderQuestionEditor.php b/src/applications/ponder/editor/PonderQuestionEditor.php
index b5c5078cb0..2971a8a5c5 100644
--- a/src/applications/ponder/editor/PonderQuestionEditor.php
+++ b/src/applications/ponder/editor/PonderQuestionEditor.php
@@ -1,144 +1,151 @@
<?php
final class PonderQuestionEditor
extends PhabricatorApplicationTransactionEditor {
protected function shouldApplyInitialEffects(
PhabricatorLiskDAO $object,
array $xactions) {
foreach ($xactions as $xaction) {
switch ($xaction->getTransactionType()) {
case PonderQuestionTransaction::TYPE_ANSWERS:
return true;
}
}
return false;
}
protected function applyInitialEffects(
PhabricatorLiskDAO $object,
array $xactions) {
foreach ($xactions as $xaction) {
switch ($xaction->getTransactionType()) {
case PonderQuestionTransaction::TYPE_ANSWERS:
$new_value = $xaction->getNewValue();
$new = idx($new_value, '+', array());
foreach ($new as $new_answer) {
$answer = idx($new_answer, 'answer');
if (!$answer) {
continue;
}
$answer->save();
}
break;
}
}
}
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_COMMENT;
$types[] = PonderQuestionTransaction::TYPE_TITLE;
$types[] = PonderQuestionTransaction::TYPE_CONTENT;
$types[] = PonderQuestionTransaction::TYPE_ANSWERS;
+ $types[] = PonderQuestionTransaction::TYPE_STATUS;
return $types;
}
protected function getCustomTransactionOldValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PonderQuestionTransaction::TYPE_TITLE:
return $object->getTitle();
case PonderQuestionTransaction::TYPE_CONTENT:
return $object->getContent();
case PonderQuestionTransaction::TYPE_ANSWERS:
return mpull($object->getAnswers(), 'getPHID');
+ case PonderQuestionTransaction::TYPE_STATUS:
+ return $object->getStatus();
}
}
protected function getCustomTransactionNewValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
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();
$new_value = array();
foreach ($raw_new_value as $key => $answers) {
$phids = array();
foreach ($answers as $answer) {
$obj = idx($answer, 'answer');
if (!$answer) {
continue;
}
$phids[] = $obj->getPHID();
}
$new_value[$key] = $phids;
}
$xaction->setNewValue($new_value);
return $this->getPHIDTransactionNewValue($xaction);
}
}
protected function applyCustomInternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PonderQuestionTransaction::TYPE_TITLE:
$object->setTitle($xaction->getNewValue());
break;
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();
$add = array_diff_key($new, $old);
$rem = array_diff_key($old, $new);
$count = $object->getAnswerCount();
$count += count($add);
$count -= count($rem);
$object->setAnswerCount($count);
break;
}
}
protected function applyCustomExternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
return;
}
protected function mergeTransactions(
PhabricatorApplicationTransaction $u,
PhabricatorApplicationTransaction $v) {
$type = $u->getTransactionType();
switch ($type) {
case PonderQuestionTransaction::TYPE_TITLE:
case PonderQuestionTransaction::TYPE_CONTENT:
+ case PonderQuestionTransaction::TYPE_STATUS:
return $v;
}
return parent::mergeTransactions($u, $v);
}
// TODO: Feed support
// TODO: Mail support
- // TODO: Add/remove answers
}
diff --git a/src/applications/ponder/storage/PonderQuestionTransaction.php b/src/applications/ponder/storage/PonderQuestionTransaction.php
index e63bbbed4b..4ab7d9bb49 100644
--- a/src/applications/ponder/storage/PonderQuestionTransaction.php
+++ b/src/applications/ponder/storage/PonderQuestionTransaction.php
@@ -1,32 +1,140 @@
<?php
final class PonderQuestionTransaction
extends PhabricatorApplicationTransaction {
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';
}
public function getTableName() {
return 'ponder_questiontransaction';
}
public function getApplicationTransactionType() {
return PonderPHIDTypeQuestion::TYPECONST;
}
public function getApplicationTransactionCommentObject() {
return new PonderQuestionTransactionComment();
}
public function getApplicationObjectTypeName() {
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();
+ }
+
+
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jan 19, 15:31 (3 w, 23 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1126027
Default Alt Text
(10 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment