From dc5c87f74cdadd8e0761402b438535ab14a355cc Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 24 Jul 2014 18:00:07 -0700 Subject: [PATCH] Hide Audit comment table reads behind an API Summary: Ref T4896. Buries all direct access to the table so we can limit the surface area affected by the migration. Test Plan: - Grepped for `PhabricatorAuditComment`. - Grepped for `audit_comment`. - Viewed a bunch of comments. - Added a comment. - Reindexed a commit. - Searched for unique term in new comment. Reviewers: btrahan, joshuaspence Reviewed By: joshuaspence Subscribers: epriestley Maniphest Tasks: T4896 Differential Revision: https://secure.phabricator.com/D10019 --- .../audit/editor/PhabricatorAuditCommentEditor.php | 4 ++-- .../audit/storage/PhabricatorAuditComment.php | 9 +++++++++ .../diffusion/controller/DiffusionCommitController.php | 4 ++-- .../search/PhabricatorRepositoryCommitSearchIndexer.php | 4 ++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/applications/audit/editor/PhabricatorAuditCommentEditor.php b/src/applications/audit/editor/PhabricatorAuditCommentEditor.php index bf81fe4fa5..55b91db276 100644 --- a/src/applications/audit/editor/PhabricatorAuditCommentEditor.php +++ b/src/applications/audit/editor/PhabricatorAuditCommentEditor.php @@ -40,8 +40,8 @@ final class PhabricatorAuditCommentEditor extends PhabricatorEditor { $commit = $this->commit; $actor = $this->getActor(); - $other_comments = id(new PhabricatorAuditComment())->loadAllWhere( - 'targetPHID = %s', + $other_comments = PhabricatorAuditComment::loadComments( + $actor, $commit->getPHID()); $inline_comments = array(); diff --git a/src/applications/audit/storage/PhabricatorAuditComment.php b/src/applications/audit/storage/PhabricatorAuditComment.php index fa02ebfd9b..ffb0912e57 100644 --- a/src/applications/audit/storage/PhabricatorAuditComment.php +++ b/src/applications/audit/storage/PhabricatorAuditComment.php @@ -15,6 +15,15 @@ final class PhabricatorAuditComment extends PhabricatorAuditDAO protected $content; protected $metadata = array(); + public static function loadComments( + PhabricatorUser $viewer, + $commit_phid) { + + return id(new PhabricatorAuditComment())->loadAllWhere( + 'targetPHID = %s', + $commit_phid); + } + public function getConfiguration() { return array( self::CONFIG_SERIALIZATION => array( diff --git a/src/applications/diffusion/controller/DiffusionCommitController.php b/src/applications/diffusion/controller/DiffusionCommitController.php index ff0eef5c01..614c885b8a 100644 --- a/src/applications/diffusion/controller/DiffusionCommitController.php +++ b/src/applications/diffusion/controller/DiffusionCommitController.php @@ -643,8 +643,8 @@ final class DiffusionCommitController extends DiffusionController { private function buildComments(PhabricatorRepositoryCommit $commit) { $user = $this->getRequest()->getUser(); - $comments = id(new PhabricatorAuditComment())->loadAllWhere( - 'targetPHID = %s ORDER BY dateCreated ASC', + $comments = PhabricatorAuditComment::loadComments( + $user, $commit->getPHID()); $inlines = PhabricatorAuditInlineComment::loadPublishedComments( diff --git a/src/applications/repository/search/PhabricatorRepositoryCommitSearchIndexer.php b/src/applications/repository/search/PhabricatorRepositoryCommitSearchIndexer.php index d8bc0125b8..ecdd4d6e64 100644 --- a/src/applications/repository/search/PhabricatorRepositoryCommitSearchIndexer.php +++ b/src/applications/repository/search/PhabricatorRepositoryCommitSearchIndexer.php @@ -66,8 +66,8 @@ final class PhabricatorRepositoryCommitSearchIndexer PhabricatorRepositoryRepositoryPHIDType::TYPECONST, $date_created); - $comments = id(new PhabricatorAuditComment())->loadAllWhere( - 'targetPHID = %s', + $comments = PhabricatorAuditComment::loadComments( + $this->getViewer(), $commit->getPHID()); foreach ($comments as $comment) { if (strlen($comment->getContent())) {