mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 04:20:55 +01:00
Use TransactionEditor in differential.createcomment
Summary: Ref T2222. Update this callsite; pretty straightforward. Test Plan: Used Conduit to take actions and saw their effects in Differential. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2222 Differential Revision: https://secure.phabricator.com/D8442
This commit is contained in:
parent
b04f706c0a
commit
1c51ed5940
4 changed files with 97 additions and 55 deletions
|
@ -7,7 +7,7 @@ final class ConduitAPI_differential_createcomment_Method
|
||||||
extends ConduitAPIMethod {
|
extends ConduitAPIMethod {
|
||||||
|
|
||||||
public function getMethodDescription() {
|
public function getMethodDescription() {
|
||||||
return "Add a comment to a Differential revision.";
|
return pht("Add a comment to a Differential revision.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function defineParamTypes() {
|
public function defineParamTypes() {
|
||||||
|
@ -31,32 +31,55 @@ final class ConduitAPI_differential_createcomment_Method
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function execute(ConduitAPIRequest $request) {
|
protected function execute(ConduitAPIRequest $request) {
|
||||||
|
$viewer = $request->getUser();
|
||||||
|
|
||||||
$revision = id(new DifferentialRevisionQuery())
|
$revision = id(new DifferentialRevisionQuery())
|
||||||
->setViewer($request->getUser())
|
->setViewer($viewer)
|
||||||
->withIDs(array($request->getValue('revision_id')))
|
->withIDs(array($request->getValue('revision_id')))
|
||||||
|
->needReviewerStatus(true)
|
||||||
->executeOne();
|
->executeOne();
|
||||||
if (!$revision) {
|
if (!$revision) {
|
||||||
throw new ConduitException('ERR_BAD_REVISION');
|
throw new ConduitException('ERR_BAD_REVISION');
|
||||||
}
|
}
|
||||||
|
|
||||||
$content_source = PhabricatorContentSource::newForSource(
|
$xactions = array();
|
||||||
PhabricatorContentSource::SOURCE_CONDUIT,
|
|
||||||
array());
|
|
||||||
|
|
||||||
$action = $request->getValue('action');
|
$action = $request->getValue('action');
|
||||||
if (!$action) {
|
if ($action && ($action != 'comment')) {
|
||||||
$action = 'none';
|
$xactions[] = id(new DifferentialTransaction())
|
||||||
|
->setTransactionType(DifferentialTransaction::TYPE_ACTION)
|
||||||
|
->setNewValue($action);
|
||||||
}
|
}
|
||||||
|
|
||||||
$editor = new DifferentialCommentEditor(
|
$content = $request->getValue('message');
|
||||||
$revision,
|
if (strlen($content)) {
|
||||||
$action);
|
$xactions[] = id(new DifferentialTransaction())
|
||||||
$editor->setActor($request->getUser());
|
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
||||||
$editor->setContentSource($content_source);
|
->attachComment(
|
||||||
$editor->setMessage($request->getValue('message'));
|
id(new DifferentialTransactionComment())
|
||||||
$editor->setNoEmail($request->getValue('silent'));
|
->setContent($content));
|
||||||
$editor->setAttachInlineComments($request->getValue('attach_inlines'));
|
}
|
||||||
$editor->save();
|
|
||||||
|
if ($request->getValue('attach_inlines')) {
|
||||||
|
$type_inline = DifferentialTransaction::TYPE_INLINE;
|
||||||
|
$inlines = DifferentialTransactionQuery::loadUnsubmittedInlineComments(
|
||||||
|
$viewer,
|
||||||
|
$revision);
|
||||||
|
foreach ($inlines as $inline) {
|
||||||
|
$xactions[] = id(new DifferentialTransaction())
|
||||||
|
->setTransactionType($type_inline)
|
||||||
|
->attachComment($inline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$editor = id(new DifferentialTransactionEditor())
|
||||||
|
->setActor($viewer)
|
||||||
|
->setDisableEmail($request->getValue('silent'))
|
||||||
|
->setContentSourceFromConduitRequest($request)
|
||||||
|
->setContinueOnNoEffect(true)
|
||||||
|
->setContinueOnMissingFields(true);
|
||||||
|
|
||||||
|
$editor->applyTransactions($revision, $xactions);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'revisionid' => $revision->getID(),
|
'revisionid' => $revision->getID(),
|
||||||
|
|
|
@ -87,17 +87,9 @@ final class DifferentialCommentSaveController
|
||||||
->setNewValue(array('+' => $reviewer_edges));
|
->setNewValue(array('+' => $reviewer_edges));
|
||||||
}
|
}
|
||||||
|
|
||||||
$inline_phids = $this->loadUnsubmittedInlinePHIDs($revision);
|
$inlines = DifferentialTransactionQuery::loadUnsubmittedInlineComments(
|
||||||
if ($inline_phids) {
|
$viewer,
|
||||||
$inlines = id(new PhabricatorApplicationTransactionCommentQuery())
|
$revision);
|
||||||
->setTemplate(new DifferentialTransactionComment())
|
|
||||||
->setViewer($viewer)
|
|
||||||
->withPHIDs($inline_phids)
|
|
||||||
->execute();
|
|
||||||
} else {
|
|
||||||
$inlines = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($inlines as $inline) {
|
foreach ($inlines as $inline) {
|
||||||
$xactions[] = id(new DifferentialTransaction())
|
$xactions[] = id(new DifferentialTransaction())
|
||||||
->setTransactionType($type_inline)
|
->setTransactionType($type_inline)
|
||||||
|
@ -153,30 +145,4 @@ final class DifferentialCommentSaveController
|
||||||
->setURI('/D'.$revision->getID());
|
->setURI('/D'.$revision->getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function loadUnsubmittedInlinePHIDs(DifferentialRevision $revision) {
|
|
||||||
$viewer = $this->getRequest()->getUser();
|
|
||||||
|
|
||||||
// TODO: This probably needs to move somewhere more central as we move
|
|
||||||
// away from DifferentialInlineCommentQuery, but
|
|
||||||
// PhabricatorApplicationTransactionCommentQuery is currently `final` and
|
|
||||||
// I'm not yet decided on how to approach that. For now, just get the PHIDs
|
|
||||||
// and then execute a PHID-based query through the standard stack.
|
|
||||||
|
|
||||||
$table = new DifferentialTransactionComment();
|
|
||||||
$conn_r = $table->establishConnection('r');
|
|
||||||
|
|
||||||
$phids = queryfx_all(
|
|
||||||
$conn_r,
|
|
||||||
'SELECT phid FROM %T
|
|
||||||
WHERE revisionPHID = %s
|
|
||||||
AND authorPHID = %s
|
|
||||||
AND transactionPHID IS NULL',
|
|
||||||
$table->getTableName(),
|
|
||||||
$revision->getPHID(),
|
|
||||||
$viewer->getPHID());
|
|
||||||
|
|
||||||
return ipull($phids, 'phid');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,4 +7,39 @@ final class DifferentialTransactionQuery
|
||||||
return new DifferentialTransaction();
|
return new DifferentialTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function loadUnsubmittedInlineComments(
|
||||||
|
PhabricatorUser $viewer,
|
||||||
|
DifferentialRevision $revision) {
|
||||||
|
|
||||||
|
// TODO: This probably needs to move somewhere more central as we move
|
||||||
|
// away from DifferentialInlineCommentQuery, but
|
||||||
|
// PhabricatorApplicationTransactionCommentQuery is currently `final` and
|
||||||
|
// I'm not yet decided on how to approach that. For now, just get the PHIDs
|
||||||
|
// and then execute a PHID-based query through the standard stack.
|
||||||
|
|
||||||
|
$table = new DifferentialTransactionComment();
|
||||||
|
$conn_r = $table->establishConnection('r');
|
||||||
|
|
||||||
|
$phids = queryfx_all(
|
||||||
|
$conn_r,
|
||||||
|
'SELECT phid FROM %T
|
||||||
|
WHERE revisionPHID = %s
|
||||||
|
AND authorPHID = %s
|
||||||
|
AND transactionPHID IS NULL',
|
||||||
|
$table->getTableName(),
|
||||||
|
$revision->getPHID(),
|
||||||
|
$viewer->getPHID());
|
||||||
|
|
||||||
|
$phids = ipull($phids, 'phid');
|
||||||
|
if (!$phids) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
return id(new PhabricatorApplicationTransactionCommentQuery())
|
||||||
|
->setTemplate(new DifferentialTransactionComment())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withPHIDs($phids)
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ abstract class PhabricatorApplicationTransactionEditor
|
||||||
private $isPreview;
|
private $isPreview;
|
||||||
private $isHeraldEditor;
|
private $isHeraldEditor;
|
||||||
private $actingAsPHID;
|
private $actingAsPHID;
|
||||||
|
private $disableEmail;
|
||||||
|
|
||||||
public function setActingAsPHID($acting_as_phid) {
|
public function setActingAsPHID($acting_as_phid) {
|
||||||
$this->actingAsPHID = $acting_as_phid;
|
$this->actingAsPHID = $acting_as_phid;
|
||||||
|
@ -128,6 +129,21 @@ abstract class PhabricatorApplicationTransactionEditor
|
||||||
return $this->isHeraldEditor;
|
return $this->isHeraldEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prevent this editor from generating email when applying transactions.
|
||||||
|
*
|
||||||
|
* @param bool True to disable email.
|
||||||
|
* @return this
|
||||||
|
*/
|
||||||
|
public function setDisableEmail($disable_email) {
|
||||||
|
$this->disableEmail = $disable_email;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDisableEmail() {
|
||||||
|
return $this->disableEmail;
|
||||||
|
}
|
||||||
|
|
||||||
public function getTransactionTypes() {
|
public function getTransactionTypes() {
|
||||||
$types = array();
|
$types = array();
|
||||||
|
|
||||||
|
@ -682,9 +698,11 @@ abstract class PhabricatorApplicationTransactionEditor
|
||||||
$this->loadHandles($xactions);
|
$this->loadHandles($xactions);
|
||||||
|
|
||||||
$mail = null;
|
$mail = null;
|
||||||
|
if (!$this->getDisableEmail()) {
|
||||||
if ($this->shouldSendMail($object, $xactions)) {
|
if ($this->shouldSendMail($object, $xactions)) {
|
||||||
$mail = $this->sendMail($object, $xactions);
|
$mail = $this->sendMail($object, $xactions);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->supportsSearch()) {
|
if ($this->supportsSearch()) {
|
||||||
id(new PhabricatorSearchIndexer())
|
id(new PhabricatorSearchIndexer())
|
||||||
|
|
Loading…
Reference in a new issue