diff --git a/src/applications/audit/storage/PhabricatorAuditInlineComment.php b/src/applications/audit/storage/PhabricatorAuditInlineComment.php index 0c2bbd3cca..c33a5de8e1 100644 --- a/src/applications/audit/storage/PhabricatorAuditInlineComment.php +++ b/src/applications/audit/storage/PhabricatorAuditInlineComment.php @@ -1,161 +1,159 @@ 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) - ->withHasPath(true) ->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) - ->withHasPath(true) ->execute(); return self::buildProxies($inlines); } public static function loadDraftAndPublishedComments( PhabricatorUser $viewer, $commit_phid, $path_id = null) { if ($path_id === null) { $inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere( 'commitPHID = %s AND (transactionPHID IS NOT NULL OR authorPHID = %s) AND pathID IS NOT NULL', $commit_phid, $viewer->getPHID()); } else { $inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere( 'commitPHID = %s AND pathID = %d AND ((authorPHID = %s AND isDeleted = 0) OR transactionPHID IS NOT NULL)', $commit_phid, $path_id, $viewer->getPHID()); } 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/differential/query/DifferentialDiffInlineCommentQuery.php b/src/applications/differential/query/DifferentialDiffInlineCommentQuery.php index e29d63320e..0a679f4c3d 100644 --- a/src/applications/differential/query/DifferentialDiffInlineCommentQuery.php +++ b/src/applications/differential/query/DifferentialDiffInlineCommentQuery.php @@ -1,31 +1,48 @@ revisionPHIDs = $phids; return $this; } - protected function getTemplate() { - return new DifferentialTransactionComment(); + public function withObjectPHIDs(array $phids) { + return $this->withRevisionPHIDs($phids); + } + + protected function buildInlineCommentWhereClauseParts( + AphrontDatabaseConnection $conn) { + $where = array(); + $alias = $this->getPrimaryTableAlias(); + + $where[] = qsprintf( + $conn, + 'changesetID IS NOT NULL'); + + return $where; } - protected function buildWhereClauseComponents( - AphrontDatabaseConnection $conn_r) { - $where = parent::buildWhereClauseComponents($conn_r); + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { + $where = parent::buildWhereClauseParts($conn); + $alias = $this->getPrimaryTableAlias(); if ($this->revisionPHIDs !== null) { $where[] = qsprintf( - $conn_r, - 'revisionPHID IN (%Ls)', + $conn, + '%T.revisionPHID IN (%Ls)', + $alias, $this->revisionPHIDs); } return $where; } } diff --git a/src/applications/diffusion/query/DiffusionDiffInlineCommentQuery.php b/src/applications/diffusion/query/DiffusionDiffInlineCommentQuery.php index 6d408f85d2..68992b60e7 100644 --- a/src/applications/diffusion/query/DiffusionDiffInlineCommentQuery.php +++ b/src/applications/diffusion/query/DiffusionDiffInlineCommentQuery.php @@ -1,62 +1,63 @@ commitPHIDs = $phids; return $this; } - public function withHasPath($has_path) { - $this->hasPath = $has_path; - return $this; + public function withObjectPHIDs(array $phids) { + return $this->withCommitPHIDs($phids); } public function withPathIDs(array $path_ids) { $this->pathIDs = $path_ids; return $this; } - protected function getTemplate() { - return new PhabricatorAuditTransactionComment(); + protected function buildInlineCommentWhereClauseParts( + AphrontDatabaseConnection $conn) { + $where = array(); + $alias = $this->getPrimaryTableAlias(); + + $where[] = qsprintf( + $conn, + '%T.pathID IS NOT NULL', + $alias); + + return $where; } - protected function buildWhereClauseComponents( - AphrontDatabaseConnection $conn_r) { - $where = parent::buildWhereClauseComponents($conn_r); + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { + $where = parent::buildWhereClauseParts($conn); + $alias = $this->getPrimaryTableAlias(); if ($this->commitPHIDs !== null) { $where[] = qsprintf( - $conn_r, - 'xcomment.commitPHID IN (%Ls)', + $conn, + '%T.commitPHID IN (%Ls)', + $alias, $this->commitPHIDs); } - if ($this->hasPath !== null) { - if ($this->hasPath) { - $where[] = qsprintf( - $conn_r, - 'xcomment.pathID IS NOT NULL'); - } else { - $where[] = qsprintf( - $conn_r, - 'xcomment.pathID IS NULL'); - } - } - if ($this->pathIDs !== null) { $where[] = qsprintf( - $conn_r, - 'xcomment.pathID IN (%Ld)', + $conn, + '%T.pathID IN (%Ld)', + $alias, $this->pathIDs); } return $where; } } diff --git a/src/applications/transactions/query/PhabricatorApplicationTransactionCommentQuery.php b/src/applications/transactions/query/PhabricatorApplicationTransactionCommentQuery.php index 4ca56101fc..4f6f45bea7 100644 --- a/src/applications/transactions/query/PhabricatorApplicationTransactionCommentQuery.php +++ b/src/applications/transactions/query/PhabricatorApplicationTransactionCommentQuery.php @@ -1,127 +1,123 @@ ids = $ids; return $this; } public function withPHIDs(array $phids) { $this->phids = $phids; return $this; } public function withTransactionPHIDs(array $transaction_phids) { $this->transactionPHIDs = $transaction_phids; return $this; } public function withAuthorPHIDs(array $phids) { $this->authorPHIDs = $phids; return $this; } public function withIsDeleted($deleted) { $this->isDeleted = $deleted; return $this; } public function withHasTransaction($has_transaction) { $this->hasTransaction = $has_transaction; return $this; } - protected function loadPage() { - $table = $this->getTemplate(); - $conn_r = $table->establishConnection('r'); - - $data = queryfx_all( - $conn_r, - 'SELECT * FROM %T xcomment %Q %Q %Q', - $table->getTableName(), - $this->buildWhereClause($conn_r), - $this->buildOrderClause($conn_r), - $this->buildLimitClause($conn_r)); - - return $table->loadAllFromArray($data); + public function newResultObject() { + return $this->newApplicationTransactionCommentTemplate(); } - protected function buildWhereClause(AphrontDatabaseConnection $conn) { - return $this->formatWhereClause( - $conn, - $this->buildWhereClauseComponents($conn)); + protected function loadPage() { + return $this->loadStandardPage($this->newResultObject()); } - protected function buildWhereClauseComponents( - AphrontDatabaseConnection $conn) { - - $where = array(); + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { + $where = parent::buildWhereClauseParts($conn); + $alias = $this->getPrimaryTableAlias(); if ($this->ids !== null) { $where[] = qsprintf( $conn, - 'xcomment.id IN (%Ld)', + '%T.id IN (%Ld)', + $alias, $this->ids); } if ($this->phids !== null) { $where[] = qsprintf( $conn, - 'xcomment.phid IN (%Ls)', + '%T.phid IN (%Ls)', + $alias, $this->phids); } if ($this->authorPHIDs !== null) { $where[] = qsprintf( $conn, - 'xcomment.authorPHID IN (%Ls)', + '%T.authorPHID IN (%Ls)', + $alias, $this->authorPHIDs); } if ($this->transactionPHIDs !== null) { $where[] = qsprintf( $conn, - 'xcomment.transactionPHID IN (%Ls)', + '%T.transactionPHID IN (%Ls)', + $alias, $this->transactionPHIDs); } if ($this->isDeleted !== null) { $where[] = qsprintf( $conn, - 'xcomment.isDeleted = %d', + '%T.isDeleted = %d', + $alias, (int)$this->isDeleted); } if ($this->hasTransaction !== null) { if ($this->hasTransaction) { $where[] = qsprintf( $conn, - 'xcomment.transactionPHID IS NOT NULL'); + '%T.transactionPHID IS NOT NULL', + $alias); } else { $where[] = qsprintf( $conn, - 'xcomment.transactionPHID IS NULL'); + '%T.transactionPHID IS NULL', + $alias); } } return $where; } + protected function getPrimaryTableAlias() { + return 'xcomment'; + } + public function getQueryApplicationClass() { // TODO: Figure out the app via the template? return null; } - } diff --git a/src/applications/transactions/query/PhabricatorApplicationTransactionTemplatedCommentQuery.php b/src/applications/transactions/query/PhabricatorApplicationTransactionTemplatedCommentQuery.php index 41758a4f26..75df93933e 100644 --- a/src/applications/transactions/query/PhabricatorApplicationTransactionTemplatedCommentQuery.php +++ b/src/applications/transactions/query/PhabricatorApplicationTransactionTemplatedCommentQuery.php @@ -1,18 +1,18 @@ template = $template; return $this; } - protected function getTemplate() { - return $this->template; + protected function newApplicationTransactionCommentTemplate() { + return id(clone $this->template); } } diff --git a/src/infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php b/src/infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php index 6a3ab39e12..48f98dc531 100644 --- a/src/infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php +++ b/src/infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php @@ -1,73 +1,82 @@ fixedStates = $states; return $this; } public function needReplyToComments($need_reply_to) { $this->needReplyToComments = $need_reply_to; return $this; } - protected function buildWhereClauseComponents( - AphrontDatabaseConnection $conn_r) { - $where = parent::buildWhereClauseComponents($conn_r); + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { + $where = parent::buildWhereClauseParts($conn); + $alias = $this->getPrimaryTableAlias(); + + foreach ($this->buildInlineCommentWhereClauseParts($conn) as $part) { + $where[] = $part; + } if ($this->fixedStates !== null) { $where[] = qsprintf( - $conn_r, - 'fixedState IN (%Ls)', + $conn, + '%T.fixedState IN (%Ls)', + $alias, $this->fixedStates); } return $where; } protected function willFilterPage(array $comments) { if ($this->needReplyToComments) { $reply_phids = array(); foreach ($comments as $comment) { $reply_phid = $comment->getReplyToCommentPHID(); if ($reply_phid) { $reply_phids[] = $reply_phid; } } if ($reply_phids) { $reply_comments = newv(get_class($this), array()) ->setViewer($this->getViewer()) ->setParentQuery($this) ->withPHIDs($reply_phids) ->execute(); $reply_comments = mpull($reply_comments, null, 'getPHID'); } else { $reply_comments = array(); } foreach ($comments as $key => $comment) { $reply_phid = $comment->getReplyToCommentPHID(); if (!$reply_phid) { $comment->attachReplyToComment(null); continue; } $reply = idx($reply_comments, $reply_phid); if (!$reply) { $this->didRejectResult($comment); unset($comments[$key]); continue; } $comment->attachReplyToComment($reply); } } return $comments; } }