From 8297f7a18288b5858674f65de17570abd2c139e9 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 2 Oct 2017 07:21:38 -0700 Subject: [PATCH] (stable) Fix transaction queries using withComments() for transactions with no comments Summary: See . Some object types (for example, Passphrase Credentials) support indexing but not commenting. Make `withComments(...)` work properly if the transaction type does not support comments. Test Plan: Indexed a credential (no comments) and a revision (comments) with `bin/search index --trace ...`. Before, credential fataled. After, credetial succeeds, and skips the transaction query. Before and after, the revision queries the transaction table. Reviewers: amckinley Reviewed By: amckinley Differential Revision: https://secure.phabricator.com/D18667 --- ...PhabricatorApplicationTransactionQuery.php | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/applications/transactions/query/PhabricatorApplicationTransactionQuery.php b/src/applications/transactions/query/PhabricatorApplicationTransactionQuery.php index abe1498fc0..f15522a087 100644 --- a/src/applications/transactions/query/PhabricatorApplicationTransactionQuery.php +++ b/src/applications/transactions/query/PhabricatorApplicationTransactionQuery.php @@ -203,16 +203,29 @@ abstract class PhabricatorApplicationTransactionQuery $xaction = $this->getTemplateApplicationTransaction(); $comment = $xaction->getApplicationTransactionCommentObject(); - if ($this->withComments) { - $joins[] = qsprintf( - $conn, - 'JOIN %T c ON x.phid = c.transactionPHID', - $comment->getTableName()); + // Not every transaction type has comments, so we may be able to + // implement this constraint trivially. + + if (!$comment) { + if ($this->withComments) { + throw new PhabricatorEmptyQueryException(); + } else { + // If we're querying for transactions with no comments and the + // transaction type does not support comments, we don't need to + // do anything. + } } else { - $joins[] = qsprintf( - $conn, - 'LEFT JOIN %T c ON x.phid = c.transactionPHID', - $comment->getTableName()); + if ($this->withComments) { + $joins[] = qsprintf( + $conn, + 'JOIN %T c ON x.phid = c.transactionPHID', + $comment->getTableName()); + } else { + $joins[] = qsprintf( + $conn, + 'LEFT JOIN %T c ON x.phid = c.transactionPHID', + $comment->getTableName()); + } } }