1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +01:00

Support filtering feed transactions by object type

Summary: Depends on D20533. Allow querying for transactions of a specific object type, so you can run queries like "Show all edits to Herald rules between date X and Y".

Test Plan: {F6463478}

Reviewers: amckinley

Reviewed By: amckinley

Differential Revision: https://secure.phabricator.com/D20534
This commit is contained in:
epriestley 2019-05-21 05:40:11 -07:00
parent 2e5b1885e7
commit 16537f7b32
4 changed files with 95 additions and 3 deletions

View file

@ -4809,6 +4809,7 @@ phutil_register_library_map(array(
'PhabricatorTransactionsApplication' => 'applications/transactions/application/PhabricatorTransactionsApplication.php',
'PhabricatorTransactionsDestructionEngineExtension' => 'applications/transactions/engineextension/PhabricatorTransactionsDestructionEngineExtension.php',
'PhabricatorTransactionsFulltextEngineExtension' => 'applications/transactions/engineextension/PhabricatorTransactionsFulltextEngineExtension.php',
'PhabricatorTransactionsObjectTypeDatasource' => 'applications/transactions/typeahead/PhabricatorTransactionsObjectTypeDatasource.php',
'PhabricatorTransformedFile' => 'applications/files/storage/PhabricatorTransformedFile.php',
'PhabricatorTranslationSetting' => 'applications/settings/setting/PhabricatorTranslationSetting.php',
'PhabricatorTranslationsConfigOptions' => 'applications/config/option/PhabricatorTranslationsConfigOptions.php',
@ -11158,6 +11159,7 @@ phutil_register_library_map(array(
'PhabricatorTransactionsApplication' => 'PhabricatorApplication',
'PhabricatorTransactionsDestructionEngineExtension' => 'PhabricatorDestructionEngineExtension',
'PhabricatorTransactionsFulltextEngineExtension' => 'PhabricatorFulltextEngineExtension',
'PhabricatorTransactionsObjectTypeDatasource' => 'PhabricatorTypeaheadDatasource',
'PhabricatorTransformedFile' => 'PhabricatorFileDAO',
'PhabricatorTranslationSetting' => 'PhabricatorOptionGroupSetting',
'PhabricatorTranslationsConfigOptions' => 'PhabricatorApplicationConfigOptions',

View file

@ -5,6 +5,7 @@ final class PhabricatorFeedTransactionQuery
private $phids;
private $authorPHIDs;
private $objectTypes;
private $createdMin;
private $createdMax;
@ -18,6 +19,11 @@ final class PhabricatorFeedTransactionQuery
return $this;
}
public function withObjectTypes(array $types) {
$this->objectTypes = $types;
return $this;
}
public function withDateCreatedBetween($min, $max) {
$this->createdMin = $min;
$this->createdMax = $max;
@ -158,12 +164,24 @@ final class PhabricatorFeedTransactionQuery
}
}
$object_types = $this->objectTypes;
if ($object_types) {
$object_types = array_fuse($object_types);
}
$results = array();
foreach ($queries as $query) {
$query_type = $query->getTemplateApplicationTransaction()
->getApplicationTransactionType();
if ($type_map) {
$type = $query->getTemplateApplicationTransaction()
->getApplicationTransactionType();
if (!isset($type_map[$type])) {
if (!isset($type_map[$query_type])) {
continue;
}
}
if ($object_types) {
if (!isset($object_types[$query_type])) {
continue;
}
}

View file

@ -21,6 +21,11 @@ final class PhabricatorFeedTransactionSearchEngine
->setLabel(pht('Authors'))
->setKey('authorPHIDs')
->setAliases(array('author', 'authors')),
id(new PhabricatorSearchDatasourceField())
->setLabel(pht('Object Types'))
->setKey('objectTypes')
->setAliases(array('objectType'))
->setDatasource(new PhabricatorTransactionsObjectTypeDatasource()),
id(new PhabricatorSearchDateField())
->setLabel(pht('Created After'))
->setKey('createdStart'),
@ -37,6 +42,10 @@ final class PhabricatorFeedTransactionSearchEngine
$query->withAuthorPHIDs($map['authorPHIDs']);
}
if ($map['objectTypes']) {
$query->withObjectTypes($map['objectTypes']);
}
$created_min = $map['createdStart'];
$created_max = $map['createdEnd'];

View file

@ -0,0 +1,63 @@
<?php
final class PhabricatorTransactionsObjectTypeDatasource
extends PhabricatorTypeaheadDatasource {
public function getBrowseTitle() {
return pht('Browse Forms');
}
public function getPlaceholderText() {
return pht('Type an object type name...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorTransactionsApplication';
}
protected function renderSpecialTokens(array $values) {
return $this->renderTokensFromResults($this->buildResults(), $values);
}
public function loadResults() {
$results = $this->buildResults();
return $this->filterResultsAgainstTokens($results);
}
private function buildResults() {
$queries = id(new PhutilClassMapQuery())
->setAncestorClass('PhabricatorApplicationTransactionQuery')
->execute();
$phid_types = PhabricatorPHIDType::getAllTypes();
$results = array();
foreach ($queries as $query) {
$query_type = $query->getTemplateApplicationTransaction()
->getApplicationTransactionType();
$phid_type = idx($phid_types, $query_type);
if ($phid_type) {
$name = $phid_type->getTypeName();
$icon = $phid_type->getTypeIcon();
} else {
$name = pht('%s ("%s")', $query_type, get_class($query));
$icon = null;
}
$result = id(new PhabricatorTypeaheadResult())
->setName($name)
->setPHID($query_type);
if ($icon) {
$result->setIcon($icon);
}
$results[$query_type] = $result;
}
return $results;
}
}