diff --git a/src/applications/differential/editor/DifferentialRevisionEditor.php b/src/applications/differential/editor/DifferentialRevisionEditor.php index 6e3b99ac23..4e9be00d2a 100644 --- a/src/applications/differential/editor/DifferentialRevisionEditor.php +++ b/src/applications/differential/editor/DifferentialRevisionEditor.php @@ -786,21 +786,29 @@ final class DifferentialRevisionEditor extends PhabricatorEditor { private function createComment() { - $comment = id(new DifferentialComment()) + $template = id(new DifferentialComment()) ->setAuthorPHID($this->getActorPHID()) - ->setRevision($this->revision) - ->setContent($this->getComments()) + ->setRevision($this->revision); + if ($this->contentSource) { + $template->setContentSource($this->contentSource); + } + + // Write the "update active diff" transaction. + id(clone $template) ->setAction(DifferentialAction::ACTION_UPDATE) ->setMetadata( array( DifferentialComment::METADATA_DIFF_ID => $this->getDiff()->getID(), - )); + )) + ->save(); - if ($this->contentSource) { - $comment->setContentSource($this->contentSource); + // If we have a comment, write the "add a comment" transaction. + if (strlen($this->getComments())) { + id(clone $template) + ->setAction(DifferentialAction::ACTION_COMMENT) + ->setContent($this->getComments()) + ->save(); } - - $comment->save(); } private function updateAuxiliaryFields() { diff --git a/src/applications/differential/storage/DifferentialComment.php b/src/applications/differential/storage/DifferentialComment.php index 557cbb6508..1bc0dec2b0 100644 --- a/src/applications/differential/storage/DifferentialComment.php +++ b/src/applications/differential/storage/DifferentialComment.php @@ -127,24 +127,27 @@ final class DifferentialComment extends DifferentialDAO $this->openTransaction(); $result = parent::save(); - $content_source = PhabricatorContentSource::newForSource( - PhabricatorContentSource::SOURCE_LEGACY, - array()); + if (strlen($this->getContent())) { + $content_source = PhabricatorContentSource::newForSource( + PhabricatorContentSource::SOURCE_LEGACY, + array()); - $xaction_phid = PhabricatorPHID::generateNewPHID( - PhabricatorApplicationTransactionPHIDTypeTransaction::TYPECONST, - DifferentialPHIDTypeRevision::TYPECONST); + $xaction_phid = PhabricatorPHID::generateNewPHID( + PhabricatorApplicationTransactionPHIDTypeTransaction::TYPECONST, + DifferentialPHIDTypeRevision::TYPECONST); + + $proxy = $this->getProxyComment(); + $proxy + ->setAuthorPHID($this->getAuthorPHID()) + ->setViewPolicy('public') + ->setEditPolicy($this->getAuthorPHID()) + ->setContentSource($content_source) + ->setCommentVersion(1) + ->setLegacyCommentID($this->getID()) + ->setTransactionPHID($xaction_phid) + ->save(); + } - $proxy = $this->getProxyComment(); - $proxy - ->setAuthorPHID($this->getAuthorPHID()) - ->setViewPolicy('public') - ->setEditPolicy($this->getAuthorPHID()) - ->setContentSource($content_source) - ->setCommentVersion(1) - ->setLegacyCommentID($this->getID()) - ->setTransactionPHID($xaction_phid) - ->save(); $this->saveTransaction(); return $result;