diff --git a/src/applications/audit/storage/PhabricatorAuditInlineComment.php b/src/applications/audit/storage/PhabricatorAuditInlineComment.php index f7686fcf0c..905694b24a 100644 --- a/src/applications/audit/storage/PhabricatorAuditInlineComment.php +++ b/src/applications/audit/storage/PhabricatorAuditInlineComment.php @@ -1,136 +1,115 @@ getCommitPHID()); } public function supportsHiding() { return false; } public function isHidden() { return false; } public function getTransactionCommentForSave() { $content_source = PhabricatorContentSource::newForSource( PhabricatorOldWorldContentSource::SOURCECONST); $this->getStorageObject() ->setViewPolicy('public') ->setEditPolicy($this->getAuthorPHID()) ->setContentSource($content_source) ->setCommentVersion(1); return $this->getStorageObject(); } public static function loadID($id) { $inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere( 'id = %d', $id); if (!$inlines) { return null; } return head(self::buildProxies($inlines)); } public static function loadPHID($phid) { $inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere( 'phid = %s', $phid); if (!$inlines) { return null; } return head(self::buildProxies($inlines)); } - public static function loadDraftComments( - PhabricatorUser $viewer, - $commit_phid, - $raw = false) { - - $inlines = id(new DiffusionDiffInlineCommentQuery()) - ->setViewer($viewer) - ->withAuthorPHIDs(array($viewer->getPHID())) - ->withCommitPHIDs(array($commit_phid)) - ->withHasTransaction(false) - ->withIsDeleted(false) - ->needReplyToComments(true) - ->execute(); - - if ($raw) { - return $inlines; - } - - return self::buildProxies($inlines); - } - public static function loadPublishedComments( PhabricatorUser $viewer, $commit_phid) { $inlines = id(new DiffusionDiffInlineCommentQuery()) ->setViewer($viewer) ->withCommitPHIDs(array($commit_phid)) ->withHasTransaction(true) ->execute(); return self::buildProxies($inlines); } private static function buildProxies(array $inlines) { $results = array(); foreach ($inlines as $key => $inline) { $results[$key] = self::newFromModernComment( $inline); } return $results; } public static function newFromModernComment( PhabricatorAuditTransactionComment $comment) { $obj = new PhabricatorAuditInlineComment(); $obj->setStorageObject($comment); return $obj; } public function setPathID($id) { $this->getStorageObject()->setPathID($id); return $this; } public function getPathID() { return $this->getStorageObject()->getPathID(); } public function setCommitPHID($commit_phid) { $this->getStorageObject()->setCommitPHID($commit_phid); return $this; } public function getCommitPHID() { return $this->getStorageObject()->getCommitPHID(); } public function setChangesetID($id) { return $this->setPathID($id); } public function getChangesetID() { return $this->getPathID(); } } diff --git a/src/applications/diffusion/editor/DiffusionCommitEditEngine.php b/src/applications/diffusion/editor/DiffusionCommitEditEngine.php index 6e45241d68..348a3e82c6 100644 --- a/src/applications/diffusion/editor/DiffusionCommitEditEngine.php +++ b/src/applications/diffusion/editor/DiffusionCommitEditEngine.php @@ -1,180 +1,182 @@ attachRepository($repository) ->attachCommitData($data) ->attachAudits(array()); } protected function newObjectQuery() { $viewer = $this->getViewer(); return id(new DiffusionCommitQuery()) ->needCommitData(true) ->needAuditRequests(true) ->needAuditAuthority(array($viewer)) ->needIdentities(true); } protected function getEditorURI() { return $this->getApplication()->getApplicationURI('commit/edit/'); } protected function newCommentActionGroups() { return array( id(new PhabricatorEditEngineCommentActionGroup()) ->setKey(self::ACTIONGROUP_AUDIT) ->setLabel(pht('Audit Actions')), id(new PhabricatorEditEngineCommentActionGroup()) ->setKey(self::ACTIONGROUP_COMMIT) ->setLabel(pht('Commit Actions')), ); } protected function getObjectCreateTitleText($object) { return pht('Create Commit'); } protected function getObjectCreateShortText() { return pht('Create Commit'); } protected function getObjectEditTitleText($object) { return pht('Edit Commit: %s', $object->getDisplayName()); } protected function getObjectEditShortText($object) { return $object->getDisplayName(); } protected function getObjectName() { return pht('Commit'); } protected function getObjectViewURI($object) { return $object->getURI(); } protected function getCreateNewObjectPolicy() { return PhabricatorPolicies::POLICY_NOONE; } protected function buildCustomEditFields($object) { $viewer = $this->getViewer(); $data = $object->getCommitData(); $fields = array(); $fields[] = id(new PhabricatorDatasourceEditField()) ->setKey('auditors') ->setLabel(pht('Auditors')) ->setDatasource(new DiffusionAuditorDatasource()) ->setUseEdgeTransactions(true) ->setTransactionType( DiffusionCommitAuditorsTransaction::TRANSACTIONTYPE) ->setCommentActionLabel(pht('Change Auditors')) ->setDescription(pht('Auditors for this commit.')) ->setConduitDescription(pht('Change the auditors for this commit.')) ->setConduitTypeDescription(pht('New auditors.')) ->setValue($object->getAuditorPHIDsForEdit()); $actions = DiffusionCommitActionTransaction::loadAllActions(); $actions = msortv($actions, 'getCommitActionOrderVector'); foreach ($actions as $key => $action) { $fields[] = $action->newEditField($object, $viewer); } return $fields; } protected function newAutomaticCommentTransactions($object) { $viewer = $this->getViewer(); $xactions = array(); - $inlines = PhabricatorAuditInlineComment::loadDraftComments( - $viewer, - $object->getPHID(), - $raw = true); + $inlines = id(new DiffusionDiffInlineCommentQuery()) + ->setViewer($viewer) + ->withObjectPHIDs(array($object->getPHID())) + ->withPublishableComments(true) + ->needReplyToComments(true) + ->execute(); $inlines = msort($inlines, 'getID'); $editor = $object->getApplicationTransactionEditor() ->setActor($viewer); $query_template = id(new DiffusionDiffInlineCommentQuery()) ->withCommitPHIDs(array($object->getPHID())); $xactions = $editor->newAutomaticInlineTransactions( $object, $inlines, PhabricatorAuditActionConstants::INLINE, $query_template); return $xactions; } protected function newCommentPreviewContent($object, array $xactions) { $viewer = $this->getViewer(); $type_inline = PhabricatorAuditActionConstants::INLINE; $inlines = array(); foreach ($xactions as $xaction) { if ($xaction->getTransactionType() === $type_inline) { $inlines[] = $xaction->getComment(); } } $content = array(); if ($inlines) { $inline_preview = id(new PHUIDiffInlineCommentPreviewListView()) ->setViewer($viewer) ->setInlineComments($inlines); $content[] = phutil_tag( 'div', array( 'id' => 'inline-comment-preview', ), $inline_preview); } return $content; } } diff --git a/src/applications/diffusion/engine/DiffusionCommitDraftEngine.php b/src/applications/diffusion/engine/DiffusionCommitDraftEngine.php index ce39e525a6..6245cf60fd 100644 --- a/src/applications/diffusion/engine/DiffusionCommitDraftEngine.php +++ b/src/applications/diffusion/engine/DiffusionCommitDraftEngine.php @@ -1,18 +1,19 @@ getViewer(); $commit = $this->getObject(); - $inlines = PhabricatorAuditInlineComment::loadDraftComments( - $viewer, - $commit->getPHID(), - $raw = true); + $inlines = id(new DiffusionDiffInlineCommentQuery()) + ->setViewer($viewer) + ->withCommitPHIDs(array($commit->getPHID())) + ->withPublishableComments(true) + ->execute(); return (bool)$inlines; } }