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

Deduplicate handle code

Summary: There's quite some duplicate code here.

Test Plan: Searched for a commit.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4665
This commit is contained in:
vrana 2013-01-28 16:44:15 -08:00
parent 93eac1f9d3
commit 13eb77fe6c
2 changed files with 228 additions and 278 deletions

View file

@ -26,102 +26,114 @@ final class PhabricatorObjectHandleData {
} }
public function loadObjects() { public function loadObjects() {
$types = array(); $types = phid_group_by_type($this->phids);
foreach ($this->phids as $phid) {
$type = phid_get_type($phid);
$types[$type][] = $phid;
}
$objects = array(); $objects = array();
foreach ($types as $type => $phids) { foreach ($types as $type => $phids) {
$objects += $this->loadObjectsOfType($type, $phids);
}
return $objects;
}
private function loadObjectsOfType($type, array $phids) {
switch ($type) { switch ($type) {
case PhabricatorPHIDConstants::PHID_TYPE_USER: case PhabricatorPHIDConstants::PHID_TYPE_USER:
$user_dao = new PhabricatorUser(); $user_dao = new PhabricatorUser();
$users = $user_dao->loadAllWhere( $users = $user_dao->loadAllWhere(
'phid in (%Ls)', 'phid in (%Ls)',
$phids); $phids);
foreach ($users as $user) { return mpull($users, null, 'getPHID');
$objects[$user->getPHID()] = $user;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_CMIT: case PhabricatorPHIDConstants::PHID_TYPE_CMIT:
$commit_dao = new PhabricatorRepositoryCommit(); $commit_dao = new PhabricatorRepositoryCommit();
$commits = $commit_dao->loadAllWhere( $commits = $commit_dao->putInSet(new LiskDAOSet())->loadAllWhere(
'phid IN (%Ls)', 'phid IN (%Ls)',
$phids); $phids);
$commit_data = array(); return mpull($commits, null, 'getPHID');
if ($commits) {
$data_dao = new PhabricatorRepositoryCommitData();
$commit_data = $data_dao->loadAllWhere(
'commitID IN (%Ld)',
mpull($commits, 'getID'));
$commit_data = mpull($commit_data, null, 'getCommitID');
}
foreach ($commits as $commit) {
$data = idx($commit_data, $commit->getID());
if ($data) {
$commit->attachCommitData($data);
$objects[$commit->getPHID()] = $commit;
} else {
// If we couldn't load the commit data, just act as though we
// couldn't load the object at all so we don't load half an object.
}
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_TASK: case PhabricatorPHIDConstants::PHID_TYPE_TASK:
$task_dao = new ManiphestTask(); $task_dao = new ManiphestTask();
$tasks = $task_dao->loadAllWhere( $tasks = $task_dao->loadAllWhere(
'phid IN (%Ls)', 'phid IN (%Ls)',
$phids); $phids);
foreach ($tasks as $task) { return mpull($tasks, null, 'getPHID');
$objects[$task->getPHID()] = $task;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_CONF: case PhabricatorPHIDConstants::PHID_TYPE_CONF:
$config_dao = new PhabricatorConfigEntry(); $config_dao = new PhabricatorConfigEntry();
$entries = $config_dao->loadAllWhere( $entries = $config_dao->loadAllWhere(
'phid IN (%Ls)', 'phid IN (%Ls)',
$phids); $phids);
foreach ($entries as $entry) { return mpull($entries, null, 'getPHID');
$objects[$entry->getPHID()] = $entry;
case PhabricatorPHIDConstants::PHID_TYPE_FILE:
$object = new PhabricatorFile();
$files = $object->loadAllWhere('phid IN (%Ls)', $phids);
return mpull($files, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_PROJ:
$object = new PhabricatorProject();
if ($this->viewer) {
$projects = id(new PhabricatorProjectQuery())
->setViewer($this->viewer)
->withPHIDs($phids)
->execute();
} else {
$projects = $object->loadAllWhere('phid IN (%Ls)', $phids);
} }
break; return mpull($projects, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_REPO:
$object = new PhabricatorRepository();
$repositories = $object->loadAllWhere('phid in (%Ls)', $phids);
return mpull($repositories, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_OPKG:
$object = new PhabricatorOwnersPackage();
$packages = $object->loadAllWhere('phid in (%Ls)', $phids);
return mpull($packages, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_APRJ:
$project_dao = new PhabricatorRepositoryArcanistProject();
$projects = $project_dao->loadAllWhere(
'phid IN (%Ls)',
$phids);
return mpull($projects, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_MLST:
$object = new PhabricatorMetaMTAMailingList();
$lists = $object->loadAllWhere('phid IN (%Ls)', $phids);
return mpull($lists, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_DREV: case PhabricatorPHIDConstants::PHID_TYPE_DREV:
$revision_dao = new DifferentialRevision(); $revision_dao = new DifferentialRevision();
$revisions = $revision_dao->loadAllWhere( $revisions = $revision_dao->loadAllWhere(
'phid IN (%Ls)', 'phid IN (%Ls)',
$phids); $phids);
foreach ($revisions as $revision) { return mpull($revisions, null, 'getPHID');
$objects[$revision->getPHID()] = $revision;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_WIKI: case PhabricatorPHIDConstants::PHID_TYPE_WIKI:
$document_dao = new PhrictionDocument(); $document_dao = new PhrictionDocument();
$documents = $document_dao->loadAllWhere( $documents = $document_dao->loadAllWhere(
'phid IN (%Ls)', 'phid IN (%Ls)',
$phids); $phids);
foreach ($documents as $document) { return mpull($documents, null, 'getPHID');
$objects[$document->getPHID()] = $document;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_QUES: case PhabricatorPHIDConstants::PHID_TYPE_QUES:
$questions = id(new PonderQuestionQuery()) $questions = id(new PonderQuestionQuery())
->setViewer($this->viewer) ->setViewer($this->viewer)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
foreach ($questions as $question) { return mpull($questions, null, 'getPHID');
$objects[$question->getPHID()] = $question;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_MOCK: case PhabricatorPHIDConstants::PHID_TYPE_MOCK:
$mocks = id(new PholioMockQuery()) $mocks = id(new PholioMockQuery())
->setViewer($this->viewer) ->setViewer($this->viewer)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
foreach ($mocks as $mock) { return mpull($mocks, null, 'getPHID');
$objects[$mock->getPHID()] = $mock;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_XACT: case PhabricatorPHIDConstants::PHID_TYPE_XACT:
$subtypes = array(); $subtypes = array();
foreach ($phids as $phid) { foreach ($phids as $phid) {
@ -147,20 +159,36 @@ final class PhabricatorObjectHandleData {
break; break;
} }
} }
foreach ($xactions as $xaction) { return mpull($xactions, null, 'getPHID');
$objects[$xaction->getPHID()] = $xaction;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_MCRO: case PhabricatorPHIDConstants::PHID_TYPE_MCRO:
$macros = id(new PhabricatorFileImageMacro())->loadAllWhere( $macros = id(new PhabricatorFileImageMacro())->loadAllWhere(
'phid IN (%Ls)', 'phid IN (%Ls)',
$phids); $phids);
$objects += mpull($macros, null, 'getPHID'); return mpull($macros, null, 'getPHID');
break;
}
}
return $objects; case PhabricatorPHIDConstants::PHID_TYPE_PSTE:
$pastes = id(new PhabricatorPasteQuery())
->withPHIDs($phids)
->setViewer($this->viewer)
->execute();
return mpull($pastes, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_BLOG:
$blogs = id(new PhameBlogQuery())
->withPHIDs($phids)
->setViewer($this->viewer)
->execute();
return mpull($blogs, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_POST:
$posts = id(new PhamePostQuery())
->withPHIDs($phids)
->setViewer($this->viewer)
->execute();
return mpull($posts, null, 'getPHID');
}
} }
public function loadHandles() { public function loadHandles() {
@ -172,7 +200,10 @@ final class PhabricatorObjectHandleData {
$external_loaders = PhabricatorEnv::getEnvConfig('phid.external-loaders'); $external_loaders = PhabricatorEnv::getEnvConfig('phid.external-loaders');
foreach ($types as $type => $phids) { foreach ($types as $type => $phids) {
$objects = $this->loadObjectsOfType($type, $phids);
switch ($type) { switch ($type) {
case PhabricatorPHIDConstants::PHID_TYPE_MAGIC: case PhabricatorPHIDConstants::PHID_TYPE_MAGIC:
// Black magic! // Black magic!
foreach ($phids as $phid) { foreach ($phids as $phid) {
@ -197,13 +228,9 @@ final class PhabricatorObjectHandleData {
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_USER: case PhabricatorPHIDConstants::PHID_TYPE_USER:
$object = new PhabricatorUser(); $image_phids = mpull($objects, 'getProfileImagePHID');
$users = $object->loadAllWhere('phid IN (%Ls)', $phids);
$users = mpull($users, null, 'getPHID');
$image_phids = mpull($users, 'getProfileImagePHID');
$image_phids = array_unique(array_filter($image_phids)); $image_phids = array_unique(array_filter($image_phids));
$images = array(); $images = array();
@ -221,10 +248,10 @@ final class PhabricatorObjectHandleData {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();
$handle->setPHID($phid); $handle->setPHID($phid);
$handle->setType($type); $handle->setType($type);
if (empty($users[$phid])) { if (empty($objects[$phid])) {
$handle->setName('Unknown User'); $handle->setName('Unknown User');
} else { } else {
$user = $users[$phid]; $user = $objects[$phid];
$handle->setName($user->getUsername()); $handle->setName($user->getUsername());
$handle->setURI('/p/'.$user->getUsername().'/'); $handle->setURI('/p/'.$user->getUsername().'/');
$handle->setFullName( $handle->setFullName(
@ -251,20 +278,16 @@ final class PhabricatorObjectHandleData {
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_MLST: case PhabricatorPHIDConstants::PHID_TYPE_MLST:
$object = new PhabricatorMetaMTAMailingList();
$lists = $object->loadAllWhere('phid IN (%Ls)', $phids);
$lists = mpull($lists, null, 'getPHID');
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();
$handle->setPHID($phid); $handle->setPHID($phid);
$handle->setType($type); $handle->setType($type);
if (empty($lists[$phid])) { if (empty($objects[$phid])) {
$handle->setName('Unknown Mailing List'); $handle->setName('Unknown Mailing List');
} else { } else {
$list = $lists[$phid]; $list = $objects[$phid];
$handle->setName($list->getName()); $handle->setName($list->getName());
$handle->setURI($list->getURI()); $handle->setURI($list->getURI());
$handle->setFullName($list->getName()); $handle->setFullName($list->getName());
@ -273,20 +296,16 @@ final class PhabricatorObjectHandleData {
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_DREV: case PhabricatorPHIDConstants::PHID_TYPE_DREV:
$object = new DifferentialRevision();
$revs = $object->loadAllWhere('phid in (%Ls)', $phids);
$revs = mpull($revs, null, 'getPHID');
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();
$handle->setPHID($phid); $handle->setPHID($phid);
$handle->setType($type); $handle->setType($type);
if (empty($revs[$phid])) { if (empty($objects[$phid])) {
$handle->setName('Unknown Revision'); $handle->setName('Unknown Revision');
} else { } else {
$rev = $revs[$phid]; $rev = $objects[$phid];
$handle->setName($rev->getTitle()); $handle->setName($rev->getTitle());
$handle->setURI('/D'.$rev->getID()); $handle->setURI('/D'.$rev->getID());
$handle->setFullName('D'.$rev->getID().': '.$rev->getTitle()); $handle->setFullName('D'.$rev->getID().': '.$rev->getTitle());
@ -303,36 +322,28 @@ final class PhabricatorObjectHandleData {
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_CMIT: case PhabricatorPHIDConstants::PHID_TYPE_CMIT:
$object = new PhabricatorRepositoryCommit();
$commits = $object->loadAllWhere('phid in (%Ls)', $phids);
$commits = mpull($commits, null, 'getPHID');
$repository_ids = array();
$callsigns = array();
if ($commits) {
$repository_ids = mpull($commits, 'getRepositoryID');
$repositories = id(new PhabricatorRepository())->loadAllWhere(
'id in (%Ld)', array_unique($repository_ids));
$callsigns = mpull($repositories, 'getCallsign');
}
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();
$handle->setPHID($phid); $handle->setPHID($phid);
$handle->setType($type); $handle->setType($type);
if (empty($commits[$phid]) || $repository = null;
!isset($callsigns[$repository_ids[$phid]])) { if (!empty($objects[$phid])) {
$repository = $objects[$phid]->loadOneRelative(
new PhabricatorRepository(),
'id',
'getRepositoryID');
}
if (!$repository) {
$handle->setName('Unknown Commit'); $handle->setName('Unknown Commit');
} else { } else {
$commit = $commits[$phid]; $commit = $objects[$phid];
$callsign = $callsigns[$repository_ids[$phid]]; $callsign = $repository->getCallsign();
$repository = $repositories[$repository_ids[$phid]];
$commit_identifier = $commit->getCommitIdentifier(); $commit_identifier = $commit->getCommitIdentifier();
// In case where the repository for the commit was deleted, // In case where the repository for the commit was deleted,
// we don't have have info about the repository anymore. // we don't have info about the repository anymore.
if ($repository) { if ($repository) {
$name = $repository->formatCommitName($commit_identifier); $name = $repository->formatCommitName($commit_identifier);
$handle->setName($name); $handle->setName($name);
@ -348,20 +359,16 @@ final class PhabricatorObjectHandleData {
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_TASK: case PhabricatorPHIDConstants::PHID_TYPE_TASK:
$object = new ManiphestTask();
$tasks = $object->loadAllWhere('phid in (%Ls)', $phids);
$tasks = mpull($tasks, null, 'getPHID');
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();
$handle->setPHID($phid); $handle->setPHID($phid);
$handle->setType($type); $handle->setType($type);
if (empty($tasks[$phid])) { if (empty($objects[$phid])) {
$handle->setName('Unknown Task'); $handle->setName('Unknown Task');
} else { } else {
$task = $tasks[$phid]; $task = $objects[$phid];
$handle->setName($task->getTitle()); $handle->setName($task->getTitle());
$handle->setURI('/T'.$task->getID()); $handle->setURI('/T'.$task->getID());
$handle->setFullName('T'.$task->getID().': '.$task->getTitle()); $handle->setFullName('T'.$task->getID().': '.$task->getTitle());
@ -375,20 +382,16 @@ final class PhabricatorObjectHandleData {
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_CONF: case PhabricatorPHIDConstants::PHID_TYPE_CONF:
$object = new PhabricatorConfigEntry();
$entries = $object->loadAllWhere('phid in (%Ls)', $phids);
$entries = mpull($entries, null, 'getPHID');
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();
$handle->setPHID($phid); $handle->setPHID($phid);
$handle->setType($type); $handle->setType($type);
if (empty($entries[$phid])) { if (empty($objects[$phid])) {
$handle->setName('Unknown Config Entry'); $handle->setName('Unknown Config Entry');
} else { } else {
$entry = $entries[$phid]; $entry = $objects[$phid];
$handle->setName($entry->getKey()); $handle->setName($entry->getKey());
$handle->setURI('/config/edit/'.$entry->getKey()); $handle->setURI('/config/edit/'.$entry->getKey());
$handle->setFullName($entry->getKey()); $handle->setFullName($entry->getKey());
@ -397,20 +400,16 @@ final class PhabricatorObjectHandleData {
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_FILE: case PhabricatorPHIDConstants::PHID_TYPE_FILE:
$object = new PhabricatorFile();
$files = $object->loadAllWhere('phid IN (%Ls)', $phids);
$files = mpull($files, null, 'getPHID');
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();
$handle->setPHID($phid); $handle->setPHID($phid);
$handle->setType($type); $handle->setType($type);
if (empty($files[$phid])) { if (empty($objects[$phid])) {
$handle->setName('Unknown File'); $handle->setName('Unknown File');
} else { } else {
$file = $files[$phid]; $file = $objects[$phid];
$handle->setName($file->getName()); $handle->setName($file->getName());
$handle->setURI($file->getBestURI()); $handle->setURI($file->getBestURI());
$handle->setComplete(true); $handle->setComplete(true);
@ -421,28 +420,16 @@ final class PhabricatorObjectHandleData {
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_PROJ: case PhabricatorPHIDConstants::PHID_TYPE_PROJ:
$object = new PhabricatorProject();
if ($this->viewer) {
$projects = id(new PhabricatorProjectQuery())
->setViewer($this->viewer)
->withPHIDs($phids)
->execute();
} else {
$projects = $object->loadAllWhere('phid IN (%Ls)', $phids);
}
$projects = mpull($projects, null, 'getPHID');
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();
$handle->setPHID($phid); $handle->setPHID($phid);
$handle->setType($type); $handle->setType($type);
if (empty($projects[$phid])) { if (empty($objects[$phid])) {
$handle->setName('Unknown Project'); $handle->setName('Unknown Project');
} else { } else {
$project = $projects[$phid]; $project = $objects[$phid];
$handle->setName($project->getName()); $handle->setName($project->getName());
$handle->setURI('/project/view/'.$project->getID().'/'); $handle->setURI('/project/view/'.$project->getID().'/');
$handle->setComplete(true); $handle->setComplete(true);
@ -450,20 +437,16 @@ final class PhabricatorObjectHandleData {
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_REPO: case PhabricatorPHIDConstants::PHID_TYPE_REPO:
$object = new PhabricatorRepository();
$repositories = $object->loadAllWhere('phid in (%Ls)', $phids);
$repositories = mpull($repositories, null, 'getPHID');
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();
$handle->setPHID($phid); $handle->setPHID($phid);
$handle->setType($type); $handle->setType($type);
if (empty($repositories[$phid])) { if (empty($objects[$phid])) {
$handle->setName('Unknown Repository'); $handle->setName('Unknown Repository');
} else { } else {
$repository = $repositories[$phid]; $repository = $objects[$phid];
$handle->setName($repository->getCallsign()); $handle->setName($repository->getCallsign());
$handle->setURI('/diffusion/'.$repository->getCallsign().'/'); $handle->setURI('/diffusion/'.$repository->getCallsign().'/');
$handle->setComplete(true); $handle->setComplete(true);
@ -471,20 +454,16 @@ final class PhabricatorObjectHandleData {
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_OPKG: case PhabricatorPHIDConstants::PHID_TYPE_OPKG:
$object = new PhabricatorOwnersPackage();
$packages = $object->loadAllWhere('phid in (%Ls)', $phids);
$packages = mpull($packages, null, 'getPHID');
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();
$handle->setPHID($phid); $handle->setPHID($phid);
$handle->setType($type); $handle->setType($type);
if (empty($packages[$phid])) { if (empty($objects[$phid])) {
$handle->setName('Unknown Package'); $handle->setName('Unknown Package');
} else { } else {
$package = $packages[$phid]; $package = $objects[$phid];
$handle->setName($package->getName()); $handle->setName($package->getName());
$handle->setURI('/owners/package/'.$package->getID().'/'); $handle->setURI('/owners/package/'.$package->getID().'/');
$handle->setComplete(true); $handle->setComplete(true);
@ -492,27 +471,23 @@ final class PhabricatorObjectHandleData {
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_APRJ:
$project_dao = new PhabricatorRepositoryArcanistProject();
$projects = $project_dao->loadAllWhere( case PhabricatorPHIDConstants::PHID_TYPE_APRJ:
'phid IN (%Ls)',
$phids);
$projects = mpull($projects, null, 'getPHID');
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();
$handle->setPHID($phid); $handle->setPHID($phid);
$handle->setType($type); $handle->setType($type);
if (empty($projects[$phid])) { if (empty($objects[$phid])) {
$handle->setName('Unknown Arcanist Project'); $handle->setName('Unknown Arcanist Project');
} else { } else {
$project = $projects[$phid]; $project = $objects[$phid];
$handle->setName($project->getName()); $handle->setName($project->getName());
$handle->setComplete(true); $handle->setComplete(true);
} }
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_WIKI: case PhabricatorPHIDConstants::PHID_TYPE_WIKI:
$document_dao = new PhrictionDocument(); $document_dao = new PhrictionDocument();
$content_dao = new PhrictionContent(); $content_dao = new PhrictionContent();
@ -547,21 +522,16 @@ final class PhabricatorObjectHandleData {
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_QUES:
$questions = id(new PonderQuestionQuery())
->setViewer($this->viewer)
->withPHIDs($phids)
->execute();
$questions = mpull($questions, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_QUES:
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();
$handle->setPHID($phid); $handle->setPHID($phid);
$handle->setType($type); $handle->setType($type);
if (empty($questions[$phid])) { if (empty($objects[$phid])) {
$handle->setName('Unknown Ponder Question'); $handle->setName('Unknown Ponder Question');
} else { } else {
$question = $questions[$phid]; $question = $objects[$phid];
$handle->setName(phutil_utf8_shorten($question->getTitle(), 60)); $handle->setName(phutil_utf8_shorten($question->getTitle(), 60));
$handle->setURI(new PhutilURI('/Q' . $question->getID())); $handle->setURI(new PhutilURI('/Q' . $question->getID()));
$handle->setComplete(true); $handle->setComplete(true);
@ -569,21 +539,16 @@ final class PhabricatorObjectHandleData {
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_PSTE:
$pastes = id(new PhabricatorPasteQuery())
->withPHIDs($phids)
->setViewer($this->viewer)
->execute();
$pastes = mpull($pastes, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_PSTE:
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();
$handle->setPHID($phid); $handle->setPHID($phid);
$handle->setType($type); $handle->setType($type);
if (empty($pastes[$phid])) { if (empty($objects[$phid])) {
$handle->setName('Unknown Paste'); $handle->setName('Unknown Paste');
} else { } else {
$paste = $pastes[$phid]; $paste = $objects[$phid];
$handle->setName($paste->getTitle()); $handle->setName($paste->getTitle());
$handle->setFullName($paste->getFullName()); $handle->setFullName($paste->getFullName());
$handle->setURI('/P'.$paste->getID()); $handle->setURI('/P'.$paste->getID());
@ -592,21 +557,16 @@ final class PhabricatorObjectHandleData {
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_BLOG:
$blogs = id(new PhameBlogQuery())
->withPHIDs($phids)
->setViewer($this->viewer)
->execute();
$blogs = mpull($blogs, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_BLOG:
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();
$handle->setPHID($phid); $handle->setPHID($phid);
$handle->setType($type); $handle->setType($type);
if (empty($blogs[$phid])) { if (empty($objects[$phid])) {
$handle->setName('Unknown Blog'); $handle->setName('Unknown Blog');
} else { } else {
$blog = $blogs[$phid]; $blog = $objects[$phid];
$handle->setName($blog->getName()); $handle->setName($blog->getName());
$handle->setFullName($blog->getName()); $handle->setFullName($blog->getName());
$handle->setURI('/phame/blog/view/'.$blog->getID().'/'); $handle->setURI('/phame/blog/view/'.$blog->getID().'/');
@ -615,21 +575,16 @@ final class PhabricatorObjectHandleData {
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_POST:
$posts = id(new PhamePostQuery())
->withPHIDs($phids)
->setViewer($this->viewer)
->execute();
$posts = mpull($posts, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_POST:
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();
$handle->setPHID($phid); $handle->setPHID($phid);
$handle->setType($type); $handle->setType($type);
if (empty($posts[$phid])) { if (empty($objects[$phid])) {
$handle->setName('Unknown Post'); $handle->setName('Unknown Post');
} else { } else {
$post = $posts[$phid]; $post = $objects[$phid];
$handle->setName($post->getTitle()); $handle->setName($post->getTitle());
$handle->setFullName($post->getTitle()); $handle->setFullName($post->getTitle());
$handle->setURI('/phame/post/view/'.$post->getID().'/'); $handle->setURI('/phame/post/view/'.$post->getID().'/');
@ -638,21 +593,16 @@ final class PhabricatorObjectHandleData {
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_MOCK:
$mocks = id(new PholioMockQuery())
->withPHIDs($phids)
->setViewer($this->viewer)
->execute();
$mocks = mpull($mocks, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_MOCK:
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();
$handle->setPHID($phid); $handle->setPHID($phid);
$handle->setType($type); $handle->setType($type);
if (empty($mocks[$phid])) { if (empty($objects[$phid])) {
$handle->setName('Unknown Mock'); $handle->setName('Unknown Mock');
} else { } else {
$mock = $mocks[$phid]; $mock = $objects[$phid];
$handle->setName($mock->getName()); $handle->setName($mock->getName());
$handle->setFullName('M'.$mock->getID().': '.$mock->getName()); $handle->setFullName('M'.$mock->getID().': '.$mock->getName());
$handle->setURI('/M'.$mock->getID()); $handle->setURI('/M'.$mock->getID());
@ -661,19 +611,16 @@ final class PhabricatorObjectHandleData {
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_MCRO: case PhabricatorPHIDConstants::PHID_TYPE_MCRO:
$macros = id(new PhabricatorFileImageMacro())->loadAllWhere(
'phid IN (%Ls)',
$phids);
$macros = mpull($macros, null, 'getPHID');
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();
$handle->setPHID($phid); $handle->setPHID($phid);
$handle->setType($type); $handle->setType($type);
if (empty($macros[$phid])) { if (empty($objects[$phid])) {
$handle->setName('Unknown Macro'); $handle->setName('Unknown Macro');
} else { } else {
$macro = $macros[$phid]; $macro = $objects[$phid];
$handle->setName($macro->getName()); $handle->setName($macro->getName());
$handle->setFullName('Image Macro "'.$macro->getName().'"'); $handle->setFullName('Image Macro "'.$macro->getName().'"');
$handle->setURI('/macro/view/'.$macro->getID().'/'); $handle->setURI('/macro/view/'.$macro->getID().'/');
@ -682,6 +629,7 @@ final class PhabricatorObjectHandleData {
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
default: default:
$loader = null; $loader = null;
if (isset($external_loaders[$type])) { if (isset($external_loaders[$type])) {
@ -706,6 +654,7 @@ final class PhabricatorObjectHandleData {
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }
break; break;
} }
} }

View file

@ -57,9 +57,10 @@ final class PhabricatorSearchResultView extends AphrontView {
case PhabricatorPHIDConstants::PHID_TYPE_CMIT: case PhabricatorPHIDConstants::PHID_TYPE_CMIT:
$object_name = $handle->getName(); $object_name = $handle->getName();
if ($this->object) { if ($this->object) {
$data = $this->object->getCommitData(); $data = $this->object->loadOneRelative(
$summary = $data->getSummary(); new PhabricatorRepositoryCommitData(),
if (strlen($summary)) { 'commitID');
if ($data && strlen($data->getSummary())) {
$object_name = $handle->getName().': '.$data->getSummary(); $object_name = $handle->getName().': '.$data->getSummary();
} }
} }