2011-05-10 17:29:28 +02:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class ManiphestTransactionPreviewController extends ManiphestController {
|
2011-05-10 17:29:28 +02:00
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$comments = $request->getStr('comments');
|
|
|
|
|
2013-09-25 22:44:14 +02:00
|
|
|
$task = id(new ManiphestTaskQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->executeOne();
|
2011-05-11 01:18:47 +02:00
|
|
|
if (!$task) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2012-10-02 00:50:47 +02:00
|
|
|
id(new PhabricatorDraft())
|
|
|
|
->setAuthorPHID($user->getPHID())
|
|
|
|
->setDraftKey($task->getPHID())
|
|
|
|
->setDraft($comments)
|
|
|
|
->replaceOrDelete();
|
2011-05-11 13:17:48 +02:00
|
|
|
|
|
|
|
$action = $request->getStr('action');
|
2011-05-10 17:29:28 +02:00
|
|
|
|
2013-09-24 19:49:06 +02:00
|
|
|
$transaction = new ManiphestTransaction();
|
2011-05-10 17:29:28 +02:00
|
|
|
$transaction->setAuthorPHID($user->getPHID());
|
2011-05-11 13:17:48 +02:00
|
|
|
$transaction->setTransactionType($action);
|
|
|
|
|
2013-09-23 23:29:59 +02:00
|
|
|
// This should really be split into a separate transaction, but it should
|
|
|
|
// all come out in the wash once we fully move to modern stuff.
|
2013-09-24 19:48:58 +02:00
|
|
|
$transaction->attachComment(
|
2013-09-23 23:29:59 +02:00
|
|
|
id(new ManiphestTransactionComment())
|
|
|
|
->setContent($comments));
|
|
|
|
|
2011-05-11 13:17:48 +02:00
|
|
|
$value = $request->getStr('value');
|
2012-04-14 16:05:58 +02:00
|
|
|
// grab phids for handles and set transaction values based on action and
|
|
|
|
// value (empty or control-specific format) coming in from the wire
|
2011-05-11 13:17:48 +02:00
|
|
|
switch ($action) {
|
2013-09-25 20:16:43 +02:00
|
|
|
case ManiphestTransaction::TYPE_PRIORITY:
|
2012-04-14 16:05:58 +02:00
|
|
|
$transaction->setOldValue($task->getPriority());
|
|
|
|
$transaction->setNewValue($value);
|
|
|
|
break;
|
2013-09-25 20:16:43 +02:00
|
|
|
case ManiphestTransaction::TYPE_OWNER:
|
2012-04-14 16:05:58 +02:00
|
|
|
if ($value) {
|
|
|
|
$value = current(json_decode($value));
|
|
|
|
$phids = array($value);
|
|
|
|
} else {
|
|
|
|
$phids = array();
|
2011-05-11 13:17:48 +02:00
|
|
|
}
|
2012-04-14 16:05:58 +02:00
|
|
|
$transaction->setNewValue($value);
|
2011-05-11 13:17:48 +02:00
|
|
|
break;
|
2014-12-11 01:27:30 +01:00
|
|
|
case PhabricatorTransactions::TYPE_SUBSCRIBERS:
|
2012-04-14 16:05:58 +02:00
|
|
|
if ($value) {
|
|
|
|
$value = json_decode($value);
|
|
|
|
}
|
2013-09-23 23:29:59 +02:00
|
|
|
if (!$value) {
|
|
|
|
$value = array();
|
|
|
|
}
|
2014-12-11 01:27:30 +01:00
|
|
|
$phids = array();
|
|
|
|
foreach ($value as $cc_phid) {
|
2013-09-23 23:29:59 +02:00
|
|
|
$phids[] = $cc_phid;
|
|
|
|
}
|
2014-12-11 01:27:30 +01:00
|
|
|
$transaction->setOldValue(array());
|
|
|
|
$transaction->setNewValue($phids);
|
2012-04-14 16:05:58 +02:00
|
|
|
break;
|
2014-12-18 23:17:16 +01:00
|
|
|
case PhabricatorTransactions::TYPE_EDGE:
|
2012-04-14 16:05:58 +02:00
|
|
|
if ($value) {
|
|
|
|
$value = json_decode($value);
|
|
|
|
}
|
2013-09-23 23:33:09 +02:00
|
|
|
if (!$value) {
|
|
|
|
$value = array();
|
|
|
|
}
|
|
|
|
|
2014-07-18 00:43:40 +02:00
|
|
|
$phids = array();
|
|
|
|
$value = array_fuse($value);
|
|
|
|
foreach ($value as $project_phid) {
|
2013-09-23 23:33:09 +02:00
|
|
|
$phids[] = $project_phid;
|
2014-07-18 00:43:40 +02:00
|
|
|
$value[$project_phid] = array('dst' => $project_phid);
|
2013-09-23 23:33:09 +02:00
|
|
|
}
|
|
|
|
|
2014-07-18 00:43:40 +02:00
|
|
|
$project_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
|
|
|
|
$transaction
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
|
|
|
|
->setMetadataValue('edge:type', $project_type)
|
|
|
|
->setOldValue(array())
|
|
|
|
->setNewValue($value);
|
2012-04-14 16:05:58 +02:00
|
|
|
break;
|
2014-01-29 19:41:51 +01:00
|
|
|
case ManiphestTransaction::TYPE_STATUS:
|
|
|
|
$phids = array();
|
2014-02-14 04:37:31 +01:00
|
|
|
$transaction->setOldValue($task->getStatus());
|
2014-01-29 19:41:51 +01:00
|
|
|
$transaction->setNewValue($value);
|
|
|
|
break;
|
2012-04-14 16:05:58 +02:00
|
|
|
default:
|
|
|
|
$phids = array();
|
|
|
|
$transaction->setNewValue($value);
|
2011-05-11 13:17:48 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-04-14 16:05:58 +02:00
|
|
|
$phids[] = $user->getPHID();
|
2011-05-11 13:17:48 +02:00
|
|
|
|
2012-09-05 04:02:56 +02:00
|
|
|
$handles = $this->loadViewerHandles($phids);
|
2011-05-10 17:29:28 +02:00
|
|
|
|
2013-09-23 23:29:59 +02:00
|
|
|
$transactions = array();
|
2011-05-10 17:29:28 +02:00
|
|
|
$transactions[] = $transaction;
|
|
|
|
|
2012-07-11 20:40:10 +02:00
|
|
|
$engine = new PhabricatorMarkupEngine();
|
2012-09-05 20:40:48 +02:00
|
|
|
$engine->setViewer($user);
|
2013-09-24 19:48:58 +02:00
|
|
|
if ($transaction->hasComment()) {
|
2013-09-23 23:29:59 +02:00
|
|
|
$engine->addObject(
|
2013-09-24 19:48:58 +02:00
|
|
|
$transaction->getComment(),
|
2013-09-23 23:29:59 +02:00
|
|
|
PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT);
|
|
|
|
}
|
2012-07-11 20:40:10 +02:00
|
|
|
$engine->process();
|
2011-05-10 17:29:28 +02:00
|
|
|
|
2013-09-24 19:48:58 +02:00
|
|
|
$transaction->setHandles($handles);
|
2013-09-23 23:29:59 +02:00
|
|
|
|
|
|
|
$view = id(new PhabricatorApplicationTransactionView())
|
|
|
|
->setUser($user)
|
2013-09-24 19:48:58 +02:00
|
|
|
->setTransactions($transactions)
|
2014-02-14 04:37:31 +01:00
|
|
|
->setIsPreview(true);
|
2011-05-10 17:29:28 +02:00
|
|
|
|
|
|
|
return id(new AphrontAjaxResponse())
|
2013-09-23 23:29:59 +02:00
|
|
|
->setContent((string)phutil_implode_html('', $view->buildEvents()));
|
2011-05-10 17:29:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|