2014-02-01 23:35:55 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expands aggregate mail recipients into their component mailables. For
|
|
|
|
* example, a project currently expands into all of its members.
|
|
|
|
*/
|
|
|
|
final class PhabricatorMetaMTAMemberQuery extends PhabricatorQuery {
|
|
|
|
|
|
|
|
private $phids = array();
|
|
|
|
private $viewer;
|
|
|
|
|
|
|
|
public function setViewer(PhabricatorUser $viewer) {
|
|
|
|
$this->viewer = $viewer;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getViewer() {
|
|
|
|
return $this->viewer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
$this->phids = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
$phids = array_fuse($this->phids);
|
|
|
|
$actors = array();
|
|
|
|
$type_map = array();
|
|
|
|
foreach ($phids as $phid) {
|
|
|
|
$type_map[phid_get_type($phid)][] = $phid;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Generalize this somewhere else.
|
|
|
|
|
|
|
|
$results = array();
|
|
|
|
foreach ($type_map as $type => $phids) {
|
|
|
|
switch ($type) {
|
|
|
|
case PhabricatorProjectPHIDTypeProject::TYPECONST:
|
2014-02-11 16:45:56 +01:00
|
|
|
// NOTE: We're loading the projects here in order to respect policies.
|
2014-02-01 23:35:55 +01:00
|
|
|
|
|
|
|
$projects = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withPHIDs($phids)
|
|
|
|
->execute();
|
|
|
|
|
2014-02-11 16:45:56 +01:00
|
|
|
$subscribers = id(new PhabricatorSubscribersQuery())
|
|
|
|
->withObjectPHIDs($phids)
|
|
|
|
->execute();
|
|
|
|
|
2014-02-01 23:35:55 +01:00
|
|
|
$projects = mpull($projects, null, 'getPHID');
|
|
|
|
foreach ($phids as $phid) {
|
|
|
|
$project = idx($projects, $phid);
|
|
|
|
if (!$project) {
|
|
|
|
$results[$phid] = array();
|
|
|
|
} else {
|
2014-02-11 16:45:56 +01:00
|
|
|
$results[$phid] = idx($subscribers, $phid, array());
|
2014-02-01 23:35:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|