1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00

Use a policy-aware query in PhabricatorSearchSelectController

Summary: Ref T603. This didn't impact policies anyway, but using PhabricatorObjectQuery is far simpler and more general.

Test Plan: Used "Attach" dialog to find mocks, tasks, and revisions by "Dxx", "Mxx", etc.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T603

Differential Revision: https://secure.phabricator.com/D7195
This commit is contained in:
epriestley 2013-10-02 13:11:44 -07:00
parent ea5bc2efac
commit 901bdda6b1

View file

@ -62,57 +62,15 @@ final class PhabricatorSearchSelectController
}
private function queryObjectNames($query) {
$viewer = $this->getRequest()->getUser();
$pattern = null;
switch ($this->type) {
case ManiphestPHIDTypeTask::TYPECONST:
$pattern = '/\bT(\d+)\b/i';
break;
case DifferentialPHIDTypeRevision::TYPECONST:
$pattern = '/\bD(\d+)\b/i';
break;
case PholioPHIDTypeMock::TYPECONST:
$pattern = '/\bM(\d+)\b/i';
break;
}
$objects = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withTypes(array($this->type))
->withNames(array($query))
->execute();
if (!$pattern) {
return array();
}
$matches = array();
preg_match_all($pattern, $query, $matches);
if (!$matches) {
return array();
}
$object_ids = $matches[1];
if (!$object_ids) {
return array();
}
switch ($this->type) {
case DifferentialPHIDTypeRevision::TYPECONST:
// TODO: (T603) See below. This whole thing needs cleanup.
$objects = id(new DifferentialRevision())->loadAllWhere(
'id IN (%Ld)',
$object_ids);
break;
case ManiphestPHIDTypeTask::TYPECONST:
// TODO: (T603) Clean this up. This should probably all run through
// ObjectQuery?
$objects = id(new ManiphestTask())->loadAllWhere(
'id IN (%Ld)',
$object_ids);
break;
case PholioPHIDTypeMock::TYPECONST:
$objects = id(new PholioMock())->loadAllWhere(
'id IN (%Ld)',
$object_ids);
break;
}
return array_fill_keys(mpull($objects, 'getPHID'), true);
return mpull($objects, 'getPHID');
}
}