3 final class PhabricatorHandleQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery
{
6 private $objectCapabilities;
7 private $phids = array();
9 public function withPHIDs(array $phids) {
10 $this->phids
= $phids;
14 public function requireObjectCapabilities(array $capabilities) {
15 $this->objectCapabilities
= $capabilities;
19 protected function getRequiredObjectCapabilities() {
20 if ($this->objectCapabilities
) {
21 return $this->objectCapabilities
;
23 return $this->getRequiredCapabilities();
26 protected function loadPage() {
27 $types = PhabricatorPHIDType
::getAllTypes();
29 $phids = array_unique($this->phids
);
34 $object_query = id(new PhabricatorObjectQuery())
36 ->setParentQuery($this)
37 ->requireCapabilities($this->getRequiredObjectCapabilities())
38 ->setViewer($this->getViewer());
40 // We never want the subquery to raise policy exceptions, even if this
41 // query is being executed via executeOne(). Policy exceptions are not
42 // meaningful or relevant for handles, which load in an "Unknown" or
43 // "Restricted" state after encountering a policy violation.
44 $object_query->setRaisePolicyExceptions(false);
46 $objects = $object_query->execute();
47 $filtered = $object_query->getPolicyFilteredPHIDs();
50 foreach ($phids as $phid) {
51 $type = phid_get_type($phid);
52 $groups[$type][] = $phid;
56 foreach ($groups as $type => $phid_group) {
58 foreach ($phid_group as $key => $phid) {
59 if (isset($handles[$phid])) {
60 unset($phid_group[$key]);
61 // The input had a duplicate PHID; just skip it.
64 $handles[$phid] = id(new PhabricatorObjectHandle())
67 if (isset($objects[$phid])) {
68 $handles[$phid]->setComplete(true);
69 } else if (isset($filtered[$phid])) {
70 $handles[$phid]->setPolicyFiltered(true);
74 if (isset($types[$type])) {
75 $type_objects = array_select_keys($objects, $phid_group);
77 $have_object_phids = array_keys($type_objects);
78 $types[$type]->loadHandles(
80 array_select_keys($handles, $have_object_phids),
91 public function getQueryApplicationClass() {