mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +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:
parent
2ff57f6938
commit
2845d11962
5 changed files with 67 additions and 69 deletions
|
@ -26,34 +26,22 @@ final class ConduitAPI_phid_lookup_Method
|
||||||
|
|
||||||
protected function execute(ConduitAPIRequest $request) {
|
protected function execute(ConduitAPIRequest $request) {
|
||||||
$names = $request->getValue('names');
|
$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())
|
$query = id(new PhabricatorObjectQuery())
|
||||||
->setViewer($request->getUser())
|
->setViewer($request->getUser())
|
||||||
->withNames($names);
|
->withNames($names);
|
||||||
$query->execute();
|
$query->execute();
|
||||||
$objects = $query->getNamedResults();
|
$name_map = $query->getNamedResults();
|
||||||
|
|
||||||
foreach ($objects as $name => $object) {
|
$handles = id(new PhabricatorObjectHandleData(mpull($name_map, 'getPHID')))
|
||||||
$phids[$name] = $object->getPHID();
|
|
||||||
}
|
|
||||||
|
|
||||||
$handles = id(new PhabricatorObjectHandleData($phids))
|
|
||||||
->setViewer($request->getUser())
|
->setViewer($request->getUser())
|
||||||
->loadHandles();
|
->loadHandles();
|
||||||
|
|
||||||
$result = array();
|
$result = array();
|
||||||
foreach ($phids as $name => $phid) {
|
foreach ($name_map as $name => $object) {
|
||||||
if (isset($handles[$phid]) && $handles[$phid]->isComplete()) {
|
$phid = $object->getPHID();
|
||||||
$result[$name] = $this->buildHandleInformationDictionary(
|
$handle = $handles[$phid];
|
||||||
$handles[$phid]);
|
$result[$phid] = $this->buildHandleInformationDictionary($handle);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
@ -19,12 +19,50 @@ final class PhabricatorObjectQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadPage() {
|
public function loadPage() {
|
||||||
|
if ($this->namedResults === null) {
|
||||||
|
$this->namedResults = array();
|
||||||
|
}
|
||||||
|
|
||||||
$types = PhabricatorPHIDType::getAllTypes();
|
$types = PhabricatorPHIDType::getAllTypes();
|
||||||
|
|
||||||
$this->namedResults = $this->loadObjectsByName($types);
|
$names = $this->names;
|
||||||
|
$phids = $this->phids;
|
||||||
|
|
||||||
return $this->loadObjectsByPHID($types) +
|
// We allow objects to be named by their PHID in addition to their normal
|
||||||
mpull($this->namedResults, null, 'getPHID');
|
// 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() {
|
public function getNamedResults() {
|
||||||
|
@ -34,12 +72,7 @@ final class PhabricatorObjectQuery
|
||||||
return $this->namedResults;
|
return $this->namedResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadObjectsByName(array $types) {
|
private function loadObjectsByName(array $types, array $names) {
|
||||||
$names = $this->names;
|
|
||||||
if (!$names) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$groups = array();
|
$groups = array();
|
||||||
foreach ($names as $name) {
|
foreach ($names as $name) {
|
||||||
foreach ($types as $type => $type_impl) {
|
foreach ($types as $type => $type_impl) {
|
||||||
|
@ -59,12 +92,7 @@ final class PhabricatorObjectQuery
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadObjectsByPHID(array $types) {
|
private function loadObjectsByPHID(array $types, array $phids) {
|
||||||
$phids = $this->phids;
|
|
||||||
if (!$phids) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$groups = array();
|
$groups = array();
|
||||||
foreach ($phids as $phid) {
|
foreach ($phids as $phid) {
|
||||||
$type = phid_get_type($phid);
|
$type = phid_get_type($phid);
|
||||||
|
|
|
@ -24,30 +24,4 @@ final class PhabricatorPHID {
|
||||||
return "PHID-{$type_str}-{$uniq}";
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,10 +220,16 @@ final class PhabricatorSearchController
|
||||||
$results = $engine->executeSearch($query);
|
$results = $engine->executeSearch($query);
|
||||||
$results = $pager->sliceResults($results);
|
$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')) {
|
if (!$request->getInt('page')) {
|
||||||
$jump = PhabricatorPHID::fromObjectName($query->getQuery(), $user);
|
$named = id(new PhabricatorObjectQuery())
|
||||||
if ($jump) {
|
->setViewer($user)
|
||||||
array_unshift($results, $jump);
|
->withNames(array($query->getQuery()))
|
||||||
|
->execute();
|
||||||
|
if ($named) {
|
||||||
|
$results = array_merge(array_keys($named), $results);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,18 +91,20 @@ final class PhabricatorSearchManagementIndexWorkflow
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadPHIDsByNames(array $names) {
|
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) {
|
foreach ($names as $name) {
|
||||||
$phid = PhabricatorPHID::fromObjectName(
|
if (empty($objects[$name])) {
|
||||||
$name,
|
|
||||||
PhabricatorUser::getOmnipotentUser());
|
|
||||||
if (!$phid) {
|
|
||||||
throw new PhutilArgumentUsageException(
|
throw new PhutilArgumentUsageException(
|
||||||
"'{$name}' is not the name of a known object.");
|
"'{$name}' is not the name of a known object.");
|
||||||
}
|
}
|
||||||
$phids[] = $phid;
|
|
||||||
}
|
}
|
||||||
return $phids;
|
|
||||||
|
return mpull($objects, 'getPHID');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadPHIDsByTypes($type) {
|
private function loadPHIDsByTypes($type) {
|
||||||
|
|
Loading…
Reference in a new issue