1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-30 01:10:58 +01:00

Remove PhabricatorPHID::fromObjectName

Summary: Ref T2715. This only ever supported like 10% of object types; get rid of it in favor of the new infra.

Test Plan:
  - Ran `bin/search index D12`; `bin/search index <some valid phid>`, `bin/search index derp`.
  - Turned off Search jump, searched for `D12`.
  - Used `phid.lookup`.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2715

Differential Revision: https://secure.phabricator.com/D6519
This commit is contained in:
epriestley 2013-07-21 13:11:39 -07:00
parent 2ff57f6938
commit 2845d11962
5 changed files with 67 additions and 69 deletions

View file

@ -26,34 +26,22 @@ final class ConduitAPI_phid_lookup_Method
protected function execute(ConduitAPIRequest $request) {
$names = $request->getValue('names');
$phids = array();
foreach ($names as $name) {
$phid = PhabricatorPHID::fromObjectName($name, $request->getUser());
if ($phid) {
$phids[$name] = $phid;
}
}
$query = id(new PhabricatorObjectQuery())
->setViewer($request->getUser())
->withNames($names);
$query->execute();
$objects = $query->getNamedResults();
$name_map = $query->getNamedResults();
foreach ($objects as $name => $object) {
$phids[$name] = $object->getPHID();
}
$handles = id(new PhabricatorObjectHandleData($phids))
$handles = id(new PhabricatorObjectHandleData(mpull($name_map, 'getPHID')))
->setViewer($request->getUser())
->loadHandles();
$result = array();
foreach ($phids as $name => $phid) {
if (isset($handles[$phid]) && $handles[$phid]->isComplete()) {
$result[$name] = $this->buildHandleInformationDictionary(
$handles[$phid]);
}
foreach ($name_map as $name => $object) {
$phid = $object->getPHID();
$handle = $handles[$phid];
$result[$phid] = $this->buildHandleInformationDictionary($handle);
}
return $result;

View file

@ -19,12 +19,50 @@ final class PhabricatorObjectQuery
}
public function loadPage() {
if ($this->namedResults === null) {
$this->namedResults = array();
}
$types = PhabricatorPHIDType::getAllTypes();
$this->namedResults = $this->loadObjectsByName($types);
$names = $this->names;
$phids = $this->phids;
return $this->loadObjectsByPHID($types) +
mpull($this->namedResults, null, 'getPHID');
// We allow objects to be named by their PHID in addition to their normal
// name so that, e.g., CLI tools which accept object names can also accept
// PHIDs and work as users expect.
$actually_phids = array();
if ($names) {
foreach ($names as $key => $name) {
if (!strncmp($name, 'PHID-', 5)) {
$actually_phids[] = $name;
$phids[] = $name;
unset($names[$key]);
}
}
}
if ($names) {
$name_results = $this->loadObjectsByName($types, $names);
} else {
$name_results = array();
}
if ($phids) {
$phid_results = $this->loadObjectsByPHID($types, $phids);
} else {
$phid_results = array();
}
foreach ($actually_phids as $phid) {
if (isset($phid_results[$phid])) {
$name_results[$phid] = $phid_results[$phid];
}
}
$this->namedResults += $name_results;
return $phid_results + mpull($name_results, null, 'getPHID');
}
public function getNamedResults() {
@ -34,12 +72,7 @@ final class PhabricatorObjectQuery
return $this->namedResults;
}
private function loadObjectsByName(array $types) {
$names = $this->names;
if (!$names) {
return array();
}
private function loadObjectsByName(array $types, array $names) {
$groups = array();
foreach ($names as $name) {
foreach ($types as $type => $type_impl) {
@ -59,12 +92,7 @@ final class PhabricatorObjectQuery
return $results;
}
private function loadObjectsByPHID(array $types) {
$phids = $this->phids;
if (!$phids) {
return array();
}
private function loadObjectsByPHID(array $types, array $phids) {
$groups = array();
foreach ($phids as $phid) {
$type = phid_get_type($phid);

View file

@ -24,30 +24,4 @@ final class PhabricatorPHID {
return "PHID-{$type_str}-{$uniq}";
}
public static function fromObjectName($name, PhabricatorUser $viewer) {
$query = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withNames(array($name));
$query->execute();
$objects = $query->getNamedResults();
if ($objects) {
return head($objects)->getPHID();
}
/// TODO: Destroy this legacy stuff.
$object = null;
$match = null;
if (preg_match('/^PHID-[A-Z]+-.{20}$/', $name)) {
// It's already a PHID! Yay.
return $name;
}
if ($object) {
return $object->getPHID();
}
return null;
}
}

View file

@ -220,10 +220,16 @@ final class PhabricatorSearchController
$results = $engine->executeSearch($query);
$results = $pager->sliceResults($results);
// If there are any objects which match the query by name, and we're
// not paging through the results, prefix the results with the named
// objects.
if (!$request->getInt('page')) {
$jump = PhabricatorPHID::fromObjectName($query->getQuery(), $user);
if ($jump) {
array_unshift($results, $jump);
$named = id(new PhabricatorObjectQuery())
->setViewer($user)
->withNames(array($query->getQuery()))
->execute();
if ($named) {
$results = array_merge(array_keys($named), $results);
}
}

View file

@ -91,18 +91,20 @@ final class PhabricatorSearchManagementIndexWorkflow
}
private function loadPHIDsByNames(array $names) {
$phids = array();
$query = id(new PhabricatorObjectQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withNames($names);
$query->execute();
$objects = $query->getNamedResults();
foreach ($names as $name) {
$phid = PhabricatorPHID::fromObjectName(
$name,
PhabricatorUser::getOmnipotentUser());
if (!$phid) {
if (empty($objects[$name])) {
throw new PhutilArgumentUsageException(
"'{$name}' is not the name of a known object.");
}
$phids[] = $phid;
}
return $phids;
return mpull($objects, 'getPHID');
}
private function loadPHIDsByTypes($type) {