From 2e5b1885e70147f1c46737dda156bb29749c4475 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 21 May 2019 05:23:31 -0700 Subject: [PATCH] Add support for querying feed transactions by author and date range Summary: Depends on D20531. Ref T13294. Enable finding raw transactions in particular date ranges or with particular authors. Test Plan: {F6463471} Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13294 Differential Revision: https://secure.phabricator.com/D20533 --- .../query/PhabricatorFeedTransactionQuery.php | 11 ++++++ ...PhabricatorFeedTransactionSearchEngine.php | 36 +++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/applications/feed/query/PhabricatorFeedTransactionQuery.php b/src/applications/feed/query/PhabricatorFeedTransactionQuery.php index 00da566532..e7ab4cc55d 100644 --- a/src/applications/feed/query/PhabricatorFeedTransactionQuery.php +++ b/src/applications/feed/query/PhabricatorFeedTransactionQuery.php @@ -4,6 +4,7 @@ final class PhabricatorFeedTransactionQuery extends PhabricatorCursorPagedPolicyAwareQuery { private $phids; + private $authorPHIDs; private $createdMin; private $createdMax; @@ -12,6 +13,11 @@ final class PhabricatorFeedTransactionQuery return $this; } + public function withAuthorPHIDs(array $phids) { + $this->authorPHIDs = $phids; + return $this; + } + public function withDateCreatedBetween($min, $max) { $this->createdMin = $min; $this->createdMax = $max; @@ -59,6 +65,7 @@ final class PhabricatorFeedTransactionQuery $created_max = $this->createdMax; $xaction_phids = $this->phids; + $author_phids = $this->authorPHIDs; foreach ($queries as $query) { $query->withDateCreatedBetween($created_min, $created_max); @@ -67,6 +74,10 @@ final class PhabricatorFeedTransactionQuery $query->withPHIDs($xaction_phids); } + if ($author_phids !== null) { + $query->withAuthorPHIDs($author_phids); + } + if ($limit !== null) { $query->setLimit($limit); } diff --git a/src/applications/feed/query/PhabricatorFeedTransactionSearchEngine.php b/src/applications/feed/query/PhabricatorFeedTransactionSearchEngine.php index bc0d27c70c..5c73818e4d 100644 --- a/src/applications/feed/query/PhabricatorFeedTransactionSearchEngine.php +++ b/src/applications/feed/query/PhabricatorFeedTransactionSearchEngine.php @@ -16,12 +16,44 @@ final class PhabricatorFeedTransactionSearchEngine } protected function buildCustomSearchFields() { - return array(); + return array( + id(new PhabricatorUsersSearchField()) + ->setLabel(pht('Authors')) + ->setKey('authorPHIDs') + ->setAliases(array('author', 'authors')), + id(new PhabricatorSearchDateField()) + ->setLabel(pht('Created After')) + ->setKey('createdStart'), + id(new PhabricatorSearchDateField()) + ->setLabel(pht('Created Before')) + ->setKey('createdEnd'), + ); } protected function buildQueryFromParameters(array $map) { $query = $this->newQuery(); + if ($map['authorPHIDs']) { + $query->withAuthorPHIDs($map['authorPHIDs']); + } + + $created_min = $map['createdStart']; + $created_max = $map['createdEnd']; + + if ($created_min && $created_max) { + if ($created_min > $created_max) { + throw new PhabricatorSearchConstraintException( + pht( + 'The specified "Created Before" date is earlier in time than the '. + 'specified "Created After" date, so this query can never match '. + 'any results.')); + } + } + + if ($created_min || $created_max) { + $query->withDateCreatedBetween($created_min, $created_max); + } + return $query; } @@ -93,7 +125,7 @@ final class PhabricatorFeedTransactionSearchEngine $table = id(new AphrontTableView($rows)) ->setHeaders( array( - pht('Actor'), + pht('Author'), pht('Object'), pht('Transaction'), pht('Date'),