mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-16 11:52:40 +01:00
3cdaf52ce9
Summary: Ref T8441. Ref T7715. For modern Query classes, automatically make subscriber queries and SearchField integrations work. In particular, we can just drive this query with EdgeLogic and don't need to do anything specific on these Query classes beyond making sure they're implemented in a way that picks up all of the EdgeLogic clauses. Test Plan: - Searched for subscribers in Pholio, Files, Paste, and Projects. - Searched for all other fields in Projects to check that Query changes are OK. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T7715, T8441 Differential Revision: https://secure.phabricator.com/D13191
70 lines
1.7 KiB
PHP
70 lines
1.7 KiB
PHP
<?php
|
|
|
|
abstract class PhabricatorSearchTokenizerField
|
|
extends PhabricatorSearchField {
|
|
|
|
protected function getDefaultValue() {
|
|
return array();
|
|
}
|
|
|
|
protected function getValueFromRequest(AphrontRequest $request, $key) {
|
|
return $this->getListFromRequest($request, $key);
|
|
}
|
|
|
|
public function getValueForQuery($value) {
|
|
return $this->newDatasource()
|
|
->setViewer($this->getViewer())
|
|
->evaluateTokens($value);
|
|
}
|
|
|
|
protected function newControl() {
|
|
return id(new AphrontFormTokenizerControl())
|
|
->setDatasource($this->newDatasource());
|
|
}
|
|
|
|
|
|
abstract protected function newDatasource();
|
|
|
|
|
|
protected function getUsersFromRequest(
|
|
AphrontRequest $request,
|
|
$key,
|
|
array $allow_types = array()) {
|
|
$list = $this->getListFromRequest($request, $key);
|
|
|
|
$phids = array();
|
|
$names = array();
|
|
$allow_types = array_fuse($allow_types);
|
|
$user_type = PhabricatorPeopleUserPHIDType::TYPECONST;
|
|
foreach ($list as $item) {
|
|
$type = phid_get_type($item);
|
|
if ($type == $user_type) {
|
|
$phids[] = $item;
|
|
} else if (isset($allow_types[$type])) {
|
|
$phids[] = $item;
|
|
} else {
|
|
if (PhabricatorTypeaheadDatasource::isFunctionToken($item)) {
|
|
// If this is a function, pass it through unchanged; we'll evaluate
|
|
// it later.
|
|
$phids[] = $item;
|
|
} else {
|
|
$names[] = $item;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($names) {
|
|
$users = id(new PhabricatorPeopleQuery())
|
|
->setViewer($this->getViewer())
|
|
->withUsernames($names)
|
|
->execute();
|
|
foreach ($users as $user) {
|
|
$phids[] = $user->getPHID();
|
|
}
|
|
$phids = array_unique($phids);
|
|
}
|
|
|
|
return $phids;
|
|
}
|
|
|
|
}
|