diff --git a/src/applications/audit/storage/PhabricatorAuditInlineComment.php b/src/applications/audit/storage/PhabricatorAuditInlineComment.php --- a/src/applications/audit/storage/PhabricatorAuditInlineComment.php +++ b/src/applications/audit/storage/PhabricatorAuditInlineComment.php @@ -65,7 +65,6 @@ ->withAuthorPHIDs(array($viewer->getPHID())) ->withCommitPHIDs(array($commit_phid)) ->withHasTransaction(false) - ->withHasPath(true) ->withIsDeleted(false) ->needReplyToComments(true) ->execute(); @@ -85,7 +84,6 @@ ->setViewer($viewer) ->withCommitPHIDs(array($commit_phid)) ->withHasTransaction(true) - ->withHasPath(true) ->execute(); return self::buildProxies($inlines); diff --git a/src/applications/differential/query/DifferentialDiffInlineCommentQuery.php b/src/applications/differential/query/DifferentialDiffInlineCommentQuery.php --- a/src/applications/differential/query/DifferentialDiffInlineCommentQuery.php +++ b/src/applications/differential/query/DifferentialDiffInlineCommentQuery.php @@ -5,23 +5,40 @@ private $revisionPHIDs; + protected function newApplicationTransactionCommentTemplate() { + return new DifferentialTransactionComment(); + } + public function withRevisionPHIDs(array $phids) { $this->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); } diff --git a/src/applications/diffusion/query/DiffusionDiffInlineCommentQuery.php b/src/applications/diffusion/query/DiffusionDiffInlineCommentQuery.php --- a/src/applications/diffusion/query/DiffusionDiffInlineCommentQuery.php +++ b/src/applications/diffusion/query/DiffusionDiffInlineCommentQuery.php @@ -4,17 +4,19 @@ extends PhabricatorDiffInlineCommentQuery { private $commitPHIDs; - private $hasPath; private $pathIDs; + protected function newApplicationTransactionCommentTemplate() { + return new PhabricatorAuditTransactionComment(); + } + public function withCommitPHIDs(array $phids) { $this->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) { @@ -22,37 +24,36 @@ 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); } diff --git a/src/applications/transactions/query/PhabricatorApplicationTransactionCommentQuery.php b/src/applications/transactions/query/PhabricatorApplicationTransactionCommentQuery.php --- a/src/applications/transactions/query/PhabricatorApplicationTransactionCommentQuery.php +++ b/src/applications/transactions/query/PhabricatorApplicationTransactionCommentQuery.php @@ -10,7 +10,7 @@ private $isDeleted; private $hasTransaction; - abstract protected function getTemplate(); + abstract protected function newApplicationTransactionCommentTemplate(); public function withIDs(array $ids) { $this->ids = $ids; @@ -42,64 +42,55 @@ 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); } @@ -107,21 +98,26 @@ 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 --- a/src/applications/transactions/query/PhabricatorApplicationTransactionTemplatedCommentQuery.php +++ b/src/applications/transactions/query/PhabricatorApplicationTransactionTemplatedCommentQuery.php @@ -11,8 +11,8 @@ 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 --- a/src/infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php +++ b/src/infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php @@ -6,6 +6,10 @@ private $fixedStates; private $needReplyToComments; + abstract protected function buildInlineCommentWhereClauseParts( + AphrontDatabaseConnection $conn); + abstract public function withObjectPHIDs(array $phids); + public function withFixedStates(array $states) { $this->fixedStates = $states; return $this; @@ -16,14 +20,19 @@ 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); }