Differential D12468 Diff 29959 src/applications/search/engine/PhabricatorApplicationSearchEngine.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/engine/PhabricatorApplicationSearchEngine.php
Show First 20 Lines • Show All 372 Lines • ▼ Show 20 Lines | /* -( Reading Utilities )--------------------------------------------------- */ | ||||
* | * | ||||
* The main goal of this flexibility is to allow external programs to generate | * The main goal of this flexibility is to allow external programs to generate | ||||
* links to pages (like "alincoln's open revisions") without needing to make | * links to pages (like "alincoln's open revisions") without needing to make | ||||
* API calls. | * API calls. | ||||
* | * | ||||
* @param AphrontRequest Request to read user PHIDs from. | * @param AphrontRequest Request to read user PHIDs from. | ||||
* @param string Key to read in the request. | * @param string Key to read in the request. | ||||
* @param list<const> Other permitted PHID types. | * @param list<const> Other permitted PHID types. | ||||
* @return list<phid> List of user PHIDs. | * @return list<phid> List of user PHIDs and selector functions. | ||||
* | |||||
* @task read | * @task read | ||||
*/ | */ | ||||
protected function readUsersFromRequest( | protected function readUsersFromRequest( | ||||
AphrontRequest $request, | AphrontRequest $request, | ||||
$key, | $key, | ||||
array $allow_types = array()) { | array $allow_types = array()) { | ||||
$list = $this->readListFromRequest($request, $key); | $list = $this->readListFromRequest($request, $key); | ||||
$phids = array(); | $phids = array(); | ||||
$names = array(); | $names = array(); | ||||
$allow_types = array_fuse($allow_types); | $allow_types = array_fuse($allow_types); | ||||
$user_type = PhabricatorPHIDConstants::PHID_TYPE_USER; | $user_type = PhabricatorPeopleUserPHIDType::TYPECONST; | ||||
foreach ($list as $item) { | foreach ($list as $item) { | ||||
$type = phid_get_type($item); | $type = phid_get_type($item); | ||||
if ($type == $user_type) { | if ($type == $user_type) { | ||||
$phids[] = $item; | $phids[] = $item; | ||||
} else if (isset($allow_types[$type])) { | } else if (isset($allow_types[$type])) { | ||||
$phids[] = $item; | $phids[] = $item; | ||||
} else { | } else { | ||||
if (PhabricatorTypeaheadDatasource::isFunctionToken($item)) { | if (PhabricatorTypeaheadDatasource::isFunctionToken($item)) { | ||||
Show All 17 Lines | if ($names) { | ||||
$phids = array_unique($phids); | $phids = array_unique($phids); | ||||
} | } | ||||
return $phids; | return $phids; | ||||
} | } | ||||
/** | /** | ||||
* Read a list of project PHIDs from a request in a flexible way. | |||||
* | |||||
* @param AphrontRequest Request to read user PHIDs from. | |||||
* @param string Key to read in the request. | |||||
* @return list<phid> List of projet PHIDs and selector functions. | |||||
* @task read | |||||
*/ | |||||
protected function readProjectsFromRequest(AphrontRequest $request, $key) { | |||||
$list = $this->readListFromRequest($request, $key); | |||||
$phids = array(); | |||||
$slugs = array(); | |||||
$project_type = PhabricatorProjectProjectPHIDType::TYPECONST; | |||||
foreach ($list as $item) { | |||||
$type = phid_get_type($item); | |||||
if ($type == $project_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 { | |||||
$slugs[] = $item; | |||||
} | |||||
} | |||||
} | |||||
if ($slugs) { | |||||
$projects = id(new PhabricatorProjectQuery()) | |||||
->setViewer($this->requireViewer()) | |||||
->withSlugs($slugs) | |||||
->execute(); | |||||
foreach ($projects as $project) { | |||||
$phids[] = $project->getPHID(); | |||||
} | |||||
$phids = array_unique($phids); | |||||
} | |||||
return $phids; | |||||
} | |||||
/** | |||||
* Read a list of subscribers from a request in a flexible way. | |||||
* | |||||
* @param AphrontRequest Request to read PHIDs from. | |||||
* @param string Key to read in the request. | |||||
* @return list<phid> List of object PHIDs. | |||||
* @task read | |||||
*/ | |||||
protected function readSubscribersFromRequest( | |||||
AphrontRequest $request, | |||||
$key) { | |||||
return $this->readUsersFromRequest( | |||||
$request, | |||||
$key, | |||||
array( | |||||
PhabricatorProjectProjectPHIDType::TYPECONST, | |||||
PhabricatorMailingListListPHIDType::TYPECONST, | |||||
)); | |||||
} | |||||
/** | |||||
* Read a list of generic PHIDs from a request in a flexible way. Like | * Read a list of generic PHIDs from a request in a flexible way. Like | ||||
* @{method:readUsersFromRequest}, this method supports either array or | * @{method:readUsersFromRequest}, this method supports either array or | ||||
* comma-delimited forms. Objects can be specified either by PHID or by | * comma-delimited forms. Objects can be specified either by PHID or by | ||||
* object name. | * object name. | ||||
* | * | ||||
* @param AphrontRequest Request to read PHIDs from. | * @param AphrontRequest Request to read PHIDs from. | ||||
* @param string Key to read in the request. | * @param string Key to read in the request. | ||||
* @param list<const> Optional, list of permitted PHID types. | * @param list<const> Optional, list of permitted PHID types. | ||||
▲ Show 20 Lines • Show All 529 Lines • Show Last 20 Lines |