From 25f4a23a959f006d361c124ee9ebbdb14dbc9e74 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 5 Sep 2014 12:27:34 -0700 Subject: [PATCH] When adding `{Fnnn}` file references by editing comments, link objects to files Summary: Fixes T6037. We don't currently write the "this file is attached to such-and-such object" edge on comment edits. Test Plan: Edited a comment, adding `{Fnnn}`. Verified file was not attached before the edit, but was afterward. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T6037 Differential Revision: https://secure.phabricator.com/D10423 --- ...torApplicationTransactionCommentEditor.php | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/applications/transactions/editor/PhabricatorApplicationTransactionCommentEditor.php b/src/applications/transactions/editor/PhabricatorApplicationTransactionCommentEditor.php index 3ba62978e2..bca48b5c7c 100644 --- a/src/applications/transactions/editor/PhabricatorApplicationTransactionCommentEditor.php +++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionCommentEditor.php @@ -46,6 +46,12 @@ final class PhabricatorApplicationTransactionCommentEditor $comment->setViewPolicy(PhabricatorPolicies::POLICY_PUBLIC); $comment->setEditPolicy($this->getActingAsPHID()); + $file_phids = PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles( + $actor, + array( + $comment->getContent(), + )); + $xaction->openTransaction(); $xaction->beginReadLocking(); if ($xaction->getID()) { @@ -67,10 +73,19 @@ final class PhabricatorApplicationTransactionCommentEditor $xaction->endReadLocking(); $xaction->saveTransaction(); - $xaction->attachComment($comment); + // Add links to any files newly referenced by the edit. + if ($file_phids) { + $editor = new PhabricatorEdgeEditor(); + foreach ($file_phids as $file_phid) { + $editor->addEdge( + $xaction->getObjectPHID(), + PhabricatorEdgeConfig::TYPE_OBJECT_HAS_FILE, + $file_phid); + } + $editor->save(); + } - // TODO: Emit an event for notifications/feed? Can we handle them - // generically? + $xaction->attachComment($comment); return $this; }