Changeset View
Changeset View
Standalone View
Standalone View
src/applications/metamta/query/PhabricatorMetaMTAMemberQuery.php
| Show All 18 Lines | final class PhabricatorMetaMTAMemberQuery extends PhabricatorQuery { | ||||
| } | } | ||||
| public function withPHIDs(array $phids) { | public function withPHIDs(array $phids) { | ||||
| $this->phids = $phids; | $this->phids = $phids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function execute() { | public function execute() { | ||||
| $viewer = $this->getViewer(); | |||||
| $phids = array_fuse($this->phids); | $phids = array_fuse($this->phids); | ||||
| $actors = array(); | $actors = array(); | ||||
| $type_map = array(); | $type_map = array(); | ||||
| foreach ($phids as $phid) { | foreach ($phids as $phid) { | ||||
| $type_map[phid_get_type($phid)][] = $phid; | $type_map[phid_get_type($phid)][] = $phid; | ||||
| } | } | ||||
| // TODO: Generalize this somewhere else. | // TODO: Generalize this somewhere else. | ||||
| // If we have packages, break them down into their constituent user and | |||||
| // project owners first. Then we'll resolve those and build the packages | |||||
| // back up from the pieces. | |||||
| $package_type = PhabricatorOwnersPackagePHIDType::TYPECONST; | |||||
| $package_phids = idx($type_map, $package_type, array()); | |||||
| unset($type_map[$package_type]); | |||||
| $package_map = array(); | |||||
| if ($package_phids) { | |||||
| $packages = id(new PhabricatorOwnersPackageQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withPHIDs($package_phids) | |||||
| ->execute(); | |||||
| foreach ($packages as $package) { | |||||
| $package_owners = array(); | |||||
| foreach ($package->getOwners() as $owner) { | |||||
| $owner_phid = $owner->getUserPHID(); | |||||
| $owner_type = phid_get_type($owner_phid); | |||||
| $type_map[$owner_type][] = $owner_phid; | |||||
| $package_owners[] = $owner_phid; | |||||
| } | |||||
| $package_map[$package->getPHID()] = $package_owners; | |||||
| } | |||||
| } | |||||
| $results = array(); | $results = array(); | ||||
| foreach ($type_map as $type => $phids) { | foreach ($type_map as $type => $phids) { | ||||
| switch ($type) { | switch ($type) { | ||||
| case PhabricatorProjectProjectPHIDType::TYPECONST: | case PhabricatorProjectProjectPHIDType::TYPECONST: | ||||
| // NOTE: We're loading the projects here in order to respect policies. | // NOTE: We're loading the projects here in order to respect policies. | ||||
| $projects = id(new PhabricatorProjectQuery()) | $projects = id(new PhabricatorProjectQuery()) | ||||
| ->setViewer($this->getViewer()) | ->setViewer($viewer) | ||||
| ->withPHIDs($phids) | ->withPHIDs($phids) | ||||
| ->needMembers(true) | ->needMembers(true) | ||||
| ->needWatchers(true) | ->needWatchers(true) | ||||
| ->execute(); | ->execute(); | ||||
| $edge_type = PhabricatorProjectSilencedEdgeType::EDGECONST; | $edge_type = PhabricatorProjectSilencedEdgeType::EDGECONST; | ||||
| $edge_query = id(new PhabricatorEdgeQuery()) | $edge_query = id(new PhabricatorEdgeQuery()) | ||||
| Show All 39 Lines | foreach ($type_map as $type => $phids) { | ||||
| // This allows callers to do less work. | // This allows callers to do less work. | ||||
| foreach ($phids as $phid) { | foreach ($phids as $phid) { | ||||
| $results[$phid] = array($phid); | $results[$phid] = array($phid); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| // For any packages, stitch them back together from the resolved users | |||||
| // and projects. | |||||
| if ($package_map) { | |||||
| foreach ($package_map as $package_phid => $owner_phids) { | |||||
| $resolved = array(); | |||||
| foreach ($owner_phids as $owner_phid) { | |||||
| $resolved_phids = idx($results, $owner_phid, array()); | |||||
| foreach ($resolved_phids as $resolved_phid) { | |||||
| $resolved[] = $resolved_phid; | |||||
| } | |||||
| } | |||||
| $results[$package_phid] = $resolved; | |||||
| } | |||||
| } | |||||
| return $results; | return $results; | ||||
| } | } | ||||
| /** | /** | ||||
| * Execute the query, merging results into a single list of unique member | * Execute the query, merging results into a single list of unique member | ||||
| * PHIDs. | * PHIDs. | ||||
| */ | */ | ||||
| public function executeExpansion() { | public function executeExpansion() { | ||||
| return array_unique(array_mergev($this->execute())); | return array_unique(array_mergev($this->execute())); | ||||
| } | } | ||||
| } | } | ||||