Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/transactions/engineextension/PhabricatorTransactionsFulltextEngineExtension.php b/src/applications/transactions/engineextension/PhabricatorTransactionsFulltextEngineExtension.php
index 701ad34ca7..c9f43f49b2 100644
--- a/src/applications/transactions/engineextension/PhabricatorTransactionsFulltextEngineExtension.php
+++ b/src/applications/transactions/engineextension/PhabricatorTransactionsFulltextEngineExtension.php
@@ -1,44 +1,45 @@
<?php
final class PhabricatorTransactionsFulltextEngineExtension
extends PhabricatorFulltextEngineExtension {
const EXTENSIONKEY = 'transactions';
public function getExtensionName() {
return pht('Comments');
}
public function shouldEnrichFulltextObject($object) {
return ($object instanceof PhabricatorApplicationTransactionInterface);
}
public function enrichFulltextObject(
$object,
PhabricatorSearchAbstractDocument $document) {
$query = PhabricatorApplicationTransactionQuery::newQueryForObject($object);
if (!$query) {
return;
}
$xactions = $query
->setViewer($this->getViewer())
->withObjectPHIDs(array($object->getPHID()))
+ ->withComments(true)
->needComments(true)
->execute();
foreach ($xactions as $xaction) {
if (!$xaction->hasComment()) {
continue;
}
$comment = $xaction->getComment();
$document->addField(
PhabricatorSearchDocumentFieldType::FIELD_COMMENT,
$comment->getContent());
}
}
}
diff --git a/src/applications/transactions/query/PhabricatorApplicationTransactionQuery.php b/src/applications/transactions/query/PhabricatorApplicationTransactionQuery.php
index da8454c7fc..abe1498fc0 100644
--- a/src/applications/transactions/query/PhabricatorApplicationTransactionQuery.php
+++ b/src/applications/transactions/query/PhabricatorApplicationTransactionQuery.php
@@ -1,210 +1,239 @@
<?php
abstract class PhabricatorApplicationTransactionQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $phids;
private $objectPHIDs;
private $authorPHIDs;
private $transactionTypes;
+ private $withComments;
private $needComments = true;
private $needHandles = true;
final public static function newQueryForObject(
PhabricatorApplicationTransactionInterface $object) {
$xaction = $object->getApplicationTransactionTemplate();
$target_class = get_class($xaction);
$queries = id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->execute();
foreach ($queries as $query) {
$query_xaction = $query->getTemplateApplicationTransaction();
$query_class = get_class($query_xaction);
if ($query_class === $target_class) {
return id(clone $query);
}
}
return null;
}
abstract public function getTemplateApplicationTransaction();
- protected function buildMoreWhereClauses(AphrontDatabaseConnection $conn_r) {
- return array();
- }
-
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withObjectPHIDs(array $object_phids) {
$this->objectPHIDs = $object_phids;
return $this;
}
public function withAuthorPHIDs(array $author_phids) {
$this->authorPHIDs = $author_phids;
return $this;
}
public function withTransactionTypes(array $transaction_types) {
$this->transactionTypes = $transaction_types;
return $this;
}
+ public function withComments($with_comments) {
+ $this->withComments = $with_comments;
+ return $this;
+ }
+
public function needComments($need) {
$this->needComments = $need;
return $this;
}
public function needHandles($need) {
$this->needHandles = $need;
return $this;
}
protected function loadPage() {
$table = $this->getTemplateApplicationTransaction();
- $conn_r = $table->establishConnection('r');
-
- $data = queryfx_all(
- $conn_r,
- 'SELECT * FROM %T x %Q %Q %Q',
- $table->getTableName(),
- $this->buildWhereClause($conn_r),
- $this->buildOrderClause($conn_r),
- $this->buildLimitClause($conn_r));
- $xactions = $table->loadAllFromArray($data);
+ $xactions = $this->loadStandardPage($table);
foreach ($xactions as $xaction) {
$xaction->attachViewer($this->getViewer());
}
if ($this->needComments) {
$comment_phids = array_filter(mpull($xactions, 'getCommentPHID'));
$comments = array();
if ($comment_phids) {
$comments =
id(new PhabricatorApplicationTransactionTemplatedCommentQuery())
->setTemplate($table->getApplicationTransactionCommentObject())
->setViewer($this->getViewer())
->withPHIDs($comment_phids)
->execute();
$comments = mpull($comments, null, 'getPHID');
}
foreach ($xactions as $xaction) {
if ($xaction->getCommentPHID()) {
$comment = idx($comments, $xaction->getCommentPHID());
if ($comment) {
$xaction->attachComment($comment);
}
}
}
} else {
foreach ($xactions as $xaction) {
$xaction->setCommentNotLoaded(true);
}
}
return $xactions;
}
protected function willFilterPage(array $xactions) {
$object_phids = array_keys(mpull($xactions, null, 'getObjectPHID'));
$objects = id(new PhabricatorObjectQuery())
->setViewer($this->getViewer())
->setParentQuery($this)
->withPHIDs($object_phids)
->execute();
foreach ($xactions as $key => $xaction) {
$object_phid = $xaction->getObjectPHID();
if (empty($objects[$object_phid])) {
unset($xactions[$key]);
continue;
}
$xaction->attachObject($objects[$object_phid]);
}
// NOTE: We have to do this after loading objects, because the objects
// may help determine which handles are required (for example, in the case
// of custom fields).
if ($this->needHandles) {
$phids = array();
foreach ($xactions as $xaction) {
$phids[$xaction->getPHID()] = $xaction->getRequiredHandlePHIDs();
}
$handles = array();
$merged = array_mergev($phids);
if ($merged) {
$handles = $this->getViewer()->loadHandles($merged);
$handles = iterator_to_array($handles);
}
foreach ($xactions as $xaction) {
$xaction->setHandles(
array_select_keys(
$handles,
$phids[$xaction->getPHID()]));
}
}
return $xactions;
}
- protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
- $where = array();
+ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
+ $where = parent::buildWhereClauseParts($conn);
- if ($this->phids) {
+ if ($this->phids !== null) {
$where[] = qsprintf(
- $conn_r,
- 'phid IN (%Ls)',
+ $conn,
+ 'x.phid IN (%Ls)',
$this->phids);
}
- if ($this->objectPHIDs) {
+ if ($this->objectPHIDs !== null) {
$where[] = qsprintf(
- $conn_r,
- 'objectPHID IN (%Ls)',
+ $conn,
+ 'x.objectPHID IN (%Ls)',
$this->objectPHIDs);
}
- if ($this->authorPHIDs) {
+ if ($this->authorPHIDs !== null) {
$where[] = qsprintf(
- $conn_r,
- 'authorPHID IN (%Ls)',
+ $conn,
+ 'x.authorPHID IN (%Ls)',
$this->authorPHIDs);
}
- if ($this->transactionTypes) {
+ if ($this->transactionTypes !== null) {
$where[] = qsprintf(
- $conn_r,
- 'transactionType IN (%Ls)',
+ $conn,
+ 'x.transactionType IN (%Ls)',
$this->transactionTypes);
}
- foreach ($this->buildMoreWhereClauses($conn_r) as $clause) {
- $where[] = $clause;
+ if ($this->withComments !== null) {
+ if (!$this->withComments) {
+ $where[] = qsprintf(
+ $conn,
+ 'c.id IS NULL');
+ }
}
- $where[] = $this->buildPagingClause($conn_r);
+ return $where;
+ }
+
+ protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
+ $joins = parent::buildJoinClauseParts($conn);
+
+ if ($this->withComments !== null) {
+ $xaction = $this->getTemplateApplicationTransaction();
+ $comment = $xaction->getApplicationTransactionCommentObject();
+
+ 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());
+ }
+ }
- return $this->formatWhereClause($where);
+ return $joins;
}
+ protected function shouldGroupQueryResultRows() {
+ if ($this->withComments !== null) {
+ return true;
+ }
+
+ return parent::shouldGroupQueryResultRows();
+ }
public function getQueryApplicationClass() {
// TODO: Sort this out?
return null;
}
+ protected function getPrimaryTableAlias() {
+ return 'x';
+ }
+
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, May 1, 6:30 AM (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
108895
Default Alt Text
(9 KB)

Event Timeline