From 3ce3f5d368031e9597bd0c5119e0a829dfff714f Mon Sep 17 00:00:00 2001 From: Lauri-Henrik Jalonen Date: Thu, 7 Feb 2013 08:02:52 -0800 Subject: [PATCH] Drafts are saved as inline comments for images when user comments mock Summary: Drafts are saved as inline comments for images when user comments mock. Test Plan: Verified that drafts receive transactionphid when user comments mock. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2446 Differential Revision: https://secure.phabricator.com/D4850 --- .../pholio/constants/PholioTransactionType.php | 1 + .../controller/PholioMockCommentController.php | 13 +++++++++++++ src/applications/pholio/editor/PholioMockEditor.php | 13 +++++++++++++ ...abricatorApplicationTransactionCommentEditor.php | 7 +++++-- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/applications/pholio/constants/PholioTransactionType.php b/src/applications/pholio/constants/PholioTransactionType.php index f2227a0401..561e813b66 100644 --- a/src/applications/pholio/constants/PholioTransactionType.php +++ b/src/applications/pholio/constants/PholioTransactionType.php @@ -4,5 +4,6 @@ final class PholioTransactionType extends PholioConstants { const TYPE_NAME = 'name'; const TYPE_DESCRIPTION = 'description'; + const TYPE_INLINE = 'inline'; } diff --git a/src/applications/pholio/controller/PholioMockCommentController.php b/src/applications/pholio/controller/PholioMockCommentController.php index 51ade41e94..2830adeec8 100644 --- a/src/applications/pholio/controller/PholioMockCommentController.php +++ b/src/applications/pholio/controller/PholioMockCommentController.php @@ -22,6 +22,7 @@ final class PholioMockCommentController extends PholioController { $mock = id(new PholioMockQuery()) ->setViewer($user) ->withIDs(array($this->id)) + ->needImages(true) ->executeOne(); if (!$mock) { @@ -49,6 +50,18 @@ final class PholioMockCommentController extends PholioController { id(new PholioTransactionComment()) ->setContent($comment)); + $inlineComments = id(new PholioTransactionComment())->loadAllWhere( + 'authorphid = %s AND transactionphid IS NULL AND imageid IN (%Ld)', + $user->getPHID(), + mpull($mock->getImages(), 'getID') + ); + + foreach ($inlineComments as $inlineComment) { + $xactions[] = id(new PholioTransaction()) + ->setTransactionType(PholioTransactionType::TYPE_INLINE) + ->attachComment($inlineComment); + } + $editor = id(new PholioMockEditor()) ->setActor($user) ->setContentSource($content_source) diff --git a/src/applications/pholio/editor/PholioMockEditor.php b/src/applications/pholio/editor/PholioMockEditor.php index 36ab5a847a..51502bb593 100644 --- a/src/applications/pholio/editor/PholioMockEditor.php +++ b/src/applications/pholio/editor/PholioMockEditor.php @@ -14,6 +14,7 @@ final class PholioMockEditor extends PhabricatorApplicationTransactionEditor { $types[] = PholioTransactionType::TYPE_NAME; $types[] = PholioTransactionType::TYPE_DESCRIPTION; + $types[] = PholioTransactionType::TYPE_INLINE; return $types; } @@ -40,6 +41,18 @@ final class PholioMockEditor extends PhabricatorApplicationTransactionEditor { } } + protected function transactionHasEffect( + PhabricatorLiskDAO $object, + PhabricatorApplicationTransaction $xaction) { + + switch ($xaction->getTransactionType()) { + case PholioTransactionType::TYPE_INLINE: + return true; + } + + return parent::transactionHasEffect($object, $xaction); + } + protected function applyCustomInternalTransaction( PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) { diff --git a/src/applications/transactions/editor/PhabricatorApplicationTransactionCommentEditor.php b/src/applications/transactions/editor/PhabricatorApplicationTransactionCommentEditor.php index fe0680a121..fc35653e6b 100644 --- a/src/applications/transactions/editor/PhabricatorApplicationTransactionCommentEditor.php +++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionCommentEditor.php @@ -75,9 +75,12 @@ final class PhabricatorApplicationTransactionCommentEditor "Transaction must have a PHID before calling applyEdit()!"); } - if ($comment->getPHID()) { - throw new Exception( + $type_comment = PhabricatorTransactions::TYPE_COMMENT; + if ($xaction->getTransactionType() == $type_comment) { + if ($comment->getPHID()) { + throw new Exception( "Transaction comment must not yet have a PHID!"); + } } if (!$this->getContentSource()) {