1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 12:00:55 +01:00

Hide direct accesses to Audit inline comment table behind API

Summary: Ref T4896. Move all direct accesses to the inline comment table behind a small amount of API to make it easier to migrate the table.

Test Plan:
  - Grepped for `PhabricatorAuditInlineComment`.
  - Grepped for `audit_inlinecomment`.
  - Created a draft comment.
  - Previewed a draft comment.
  - Reloaded page, still saw draft.
  - Viewed standalone, still saw draft.
  - Made comment, inline published.
  - Added a draft, saw both.
  - Edited inline comment.
  - Reindexed commit.
  - Searched for unique word in published comment, found commit.
  - Searched for unique word in draft comment, no results.

Reviewers: btrahan, joshuaspence

Reviewed By: joshuaspence

Subscribers: epriestley

Maniphest Tasks: T4896

Differential Revision: https://secure.phabricator.com/D10016
This commit is contained in:
epriestley 2014-07-24 17:59:28 -07:00
parent 023dee0d3b
commit 8605a1808d
6 changed files with 53 additions and 20 deletions

View file

@ -46,10 +46,8 @@ final class PhabricatorAuditCommentEditor extends PhabricatorEditor {
$inline_comments = array();
if ($this->attachInlineComments) {
$inline_comments = id(new PhabricatorAuditInlineComment())->loadAllWhere(
'authorPHID = %s AND commitPHID = %s
AND auditCommentID IS NULL',
$actor->getPHID(),
$inline_comments = PhabricatorAuditInlineComment::loadDraftComments(
$actor,
$commit->getPHID());
}

View file

@ -17,6 +17,45 @@ final class PhabricatorAuditInlineComment
private $syntheticAuthor;
public static function loadDraftComments(
PhabricatorUser $viewer,
$commit_phid) {
return id(new PhabricatorAuditInlineComment())->loadAllWhere(
'authorPHID = %s AND commitPHID = %s AND auditCommentID IS NULL',
$viewer->getPHID(),
$commit_phid);
}
public static function loadPublishedComments(
PhabricatorUser $viewer,
$commit_phid) {
return id(new PhabricatorAuditInlineComment())->loadAllWhere(
'commitPHID = %s AND auditCommentID IS NOT NULL',
$commit_phid);
}
public static function loadDraftAndPublishedComments(
PhabricatorUser $viewer,
$commit_phid,
$path_id = null) {
if ($path_id === null) {
return id(new PhabricatorAuditInlineComment())->loadAllWhere(
'commitPHID = %s AND (auditCommentID IS NOT NULL OR authorPHID = %s)',
$commit_phid,
$viewer->getPHID());
} else {
return id(new PhabricatorAuditInlineComment())->loadAllWhere(
'commitPHID = %s AND pathID = %d AND
(authorPHID = %s OR auditCommentID IS NOT NULL)',
$commit_phid,
$path_id,
$viewer->getPHID());
}
}
public function setSyntheticAuthor($synthetic_author) {
$this->syntheticAuthor = $synthetic_author;
return $this;

View file

@ -323,10 +323,9 @@ final class DiffusionCommitController extends DiffusionController {
$visible_changesets = $changesets;
} else {
$visible_changesets = array();
$inlines = id(new PhabricatorAuditInlineComment())->loadAllWhere(
'commitPHID = %s AND (auditCommentID IS NOT NULL OR authorPHID = %s)',
$commit->getPHID(),
$user->getPHID());
$inlines = PhabricatorAuditInlineComment::loadDraftAndPublishedComments(
$user,
$commit->getPHID());
$path_ids = mpull($inlines, null, 'getPathID');
foreach ($changesets as $key => $changeset) {
if (array_key_exists($changeset->getID(), $path_ids)) {
@ -648,8 +647,8 @@ final class DiffusionCommitController extends DiffusionController {
'targetPHID = %s ORDER BY dateCreated ASC',
$commit->getPHID());
$inlines = id(new PhabricatorAuditInlineComment())->loadAllWhere(
'commitPHID = %s AND auditCommentID IS NOT NULL',
$inlines = PhabricatorAuditInlineComment::loadPublishedComments(
$user,
$commit->getPHID());
$path_ids = mpull($inlines, 'getPathID');

View file

@ -86,12 +86,10 @@ final class DiffusionDiffController extends DiffusionController {
$parser->setWhitespaceMode(
DifferentialChangesetParser::WHITESPACE_SHOW_ALL);
$inlines = id(new PhabricatorAuditInlineComment())->loadAllWhere(
'commitPHID = %s AND pathID = %d AND
(authorPHID = %s OR auditCommentID IS NOT NULL)',
$inlines = PhabricatorAuditInlineComment::loadDraftAndPublishedComments(
$user,
$drequest->loadCommit()->getPHID(),
$path_id,
$user->getPHID());
$path_id);
if ($inlines) {
foreach ($inlines as $inline) {

View file

@ -12,9 +12,8 @@ final class DiffusionInlineCommentPreviewController
protected function loadInlineComments() {
$user = $this->getRequest()->getUser();
$inlines = id(new PhabricatorAuditInlineComment())->loadAllWhere(
'authorPHID = %s AND commitPHID = %s AND auditCommentID IS NULL',
$user->getPHID(),
$inlines = PhabricatorAuditInlineComment::loadDraftComments(
$user,
$this->commitPHID);
return $inlines;

View file

@ -77,8 +77,8 @@ final class PhabricatorRepositoryCommitSearchIndexer
}
}
$inlines = id(new PhabricatorAuditInlineComment())->loadAllWhere(
'commitPHID = %s AND (auditCommentID IS NOT NULL)',
$inlines = PhabricatorAuditInlineComment::loadPublishedComments(
$this->getViewer(),
$commit->getPHID());
foreach ($inlines as $inline) {
if (strlen($inline->getContent())) {