Path: blob/master/src/applications/metamta/herald/PhabricatorMetaMTAEmailHeraldAction.php
12256 views
<?php12abstract class PhabricatorMetaMTAEmailHeraldAction3extends HeraldAction {45const DO_SEND = 'do.send';6const DO_FORCE = 'do.force';78public function getRequiredAdapterStates() {9return array(10HeraldMailableState::STATECONST,11);12}1314public function supportsObject($object) {15return self::isMailGeneratingObject($object);16}1718public static function isMailGeneratingObject($object) {19// NOTE: This implementation lacks generality, but there's no great way to20// figure out if something generates email right now.2122if ($object instanceof DifferentialDiff) {23return false;24}2526if ($object instanceof PhabricatorMetaMTAMail) {27return false;28}2930return true;31}3233public function getActionGroupKey() {34return HeraldNotifyActionGroup::ACTIONGROUPKEY;35}3637protected function applyEmail(array $phids, $force) {38$adapter = $this->getAdapter();3940$allowed_types = array(41PhabricatorPeopleUserPHIDType::TYPECONST,42PhabricatorProjectProjectPHIDType::TYPECONST,43);4445// There's no stateful behavior for this action: we always just send an46// email.47$current = array();4849$targets = $this->loadStandardTargets($phids, $allowed_types, $current);50if (!$targets) {51return;52}5354$phids = array_fuse(array_keys($targets));5556foreach ($phids as $phid) {57$adapter->addEmailPHID($phid, $force);58}5960if ($force) {61$this->logEffect(self::DO_FORCE, $phids);62} else {63$this->logEffect(self::DO_SEND, $phids);64}65}6667protected function getActionEffectMap() {68return array(69self::DO_SEND => array(70'icon' => 'fa-envelope',71'color' => 'green',72'name' => pht('Sent Mail'),73),74self::DO_FORCE => array(75'icon' => 'fa-envelope',76'color' => 'blue',77'name' => pht('Forced Mail'),78),79);80}8182protected function renderActionEffectDescription($type, $data) {83switch ($type) {84case self::DO_SEND:85return pht(86'Queued email to be delivered to %s target(s): %s.',87phutil_count($data),88$this->renderHandleList($data));89case self::DO_FORCE:90return pht(91'Queued email to be delivered to %s target(s), ignoring their '.92'notification preferences: %s.',93phutil_count($data),94$this->renderHandleList($data));95}96}9798}99100101