Skip to content

Commit 3ce3f5d

Browse files
ljalonenepriestley
authored andcommitted
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
1 parent 431e2be commit 3ce3f5d

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

src/applications/pholio/constants/PholioTransactionType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ final class PholioTransactionType extends PholioConstants {
44

55
const TYPE_NAME = 'name';
66
const TYPE_DESCRIPTION = 'description';
7+
const TYPE_INLINE = 'inline';
78

89
}

src/applications/pholio/controller/PholioMockCommentController.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function processRequest() {
2222
$mock = id(new PholioMockQuery())
2323
->setViewer($user)
2424
->withIDs(array($this->id))
25+
->needImages(true)
2526
->executeOne();
2627

2728
if (!$mock) {
@@ -49,6 +50,18 @@ public function processRequest() {
4950
id(new PholioTransactionComment())
5051
->setContent($comment));
5152

53+
$inlineComments = id(new PholioTransactionComment())->loadAllWhere(
54+
'authorphid = %s AND transactionphid IS NULL AND imageid IN (%Ld)',
55+
$user->getPHID(),
56+
mpull($mock->getImages(), 'getID')
57+
);
58+
59+
foreach ($inlineComments as $inlineComment) {
60+
$xactions[] = id(new PholioTransaction())
61+
->setTransactionType(PholioTransactionType::TYPE_INLINE)
62+
->attachComment($inlineComment);
63+
}
64+
5265
$editor = id(new PholioMockEditor())
5366
->setActor($user)
5467
->setContentSource($content_source)

src/applications/pholio/editor/PholioMockEditor.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public function getTransactionTypes() {
1414

1515
$types[] = PholioTransactionType::TYPE_NAME;
1616
$types[] = PholioTransactionType::TYPE_DESCRIPTION;
17+
$types[] = PholioTransactionType::TYPE_INLINE;
1718
return $types;
1819
}
1920

@@ -40,6 +41,18 @@ protected function getCustomTransactionNewValue(
4041
}
4142
}
4243

44+
protected function transactionHasEffect(
45+
PhabricatorLiskDAO $object,
46+
PhabricatorApplicationTransaction $xaction) {
47+
48+
switch ($xaction->getTransactionType()) {
49+
case PholioTransactionType::TYPE_INLINE:
50+
return true;
51+
}
52+
53+
return parent::transactionHasEffect($object, $xaction);
54+
}
55+
4356
protected function applyCustomInternalTransaction(
4457
PhabricatorLiskDAO $object,
4558
PhabricatorApplicationTransaction $xaction) {

src/applications/transactions/editor/PhabricatorApplicationTransactionCommentEditor.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,12 @@ private function validateEdit(
7575
"Transaction must have a PHID before calling applyEdit()!");
7676
}
7777

78-
if ($comment->getPHID()) {
79-
throw new Exception(
78+
$type_comment = PhabricatorTransactions::TYPE_COMMENT;
79+
if ($xaction->getTransactionType() == $type_comment) {
80+
if ($comment->getPHID()) {
81+
throw new Exception(
8082
"Transaction comment must not yet have a PHID!");
83+
}
8184
}
8285

8386
if (!$this->getContentSource()) {

0 commit comments

Comments
 (0)