Differential D13131 Diff 31772 src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
| Show First 20 Lines • Show All 986 Lines • ▼ Show 20 Lines | public function publishTransactions( | ||||
| // Before sending mail or publishing feed stories, reload the object | // Before sending mail or publishing feed stories, reload the object | ||||
| // subscribers to pick up changes caused by Herald (or by other side effects | // subscribers to pick up changes caused by Herald (or by other side effects | ||||
| // in various transaction phases). | // in various transaction phases). | ||||
| $this->loadSubscribers($object); | $this->loadSubscribers($object); | ||||
| // Hook for other edges that may need (re-)loading | // Hook for other edges that may need (re-)loading | ||||
| $object = $this->willPublish($object, $xactions); | $object = $this->willPublish($object, $xactions); | ||||
| $this->loadHandles($xactions); | $mailed = array(); | ||||
| $mail = null; | |||||
| if (!$this->getDisableEmail()) { | if (!$this->getDisableEmail()) { | ||||
| if ($this->shouldSendMail($object, $xactions)) { | if ($this->shouldSendMail($object, $xactions)) { | ||||
| $mail = $this->sendMail($object, $xactions); | $mailed = $this->sendMail($object, $xactions); | ||||
| } | } | ||||
| } | } | ||||
| if ($this->supportsSearch()) { | if ($this->supportsSearch()) { | ||||
| id(new PhabricatorSearchIndexer()) | id(new PhabricatorSearchIndexer()) | ||||
| ->queueDocumentForIndexing( | ->queueDocumentForIndexing( | ||||
| $object->getPHID(), | $object->getPHID(), | ||||
| $this->getSearchContextParameter($object, $xactions)); | $this->getSearchContextParameter($object, $xactions)); | ||||
| } | } | ||||
| if ($this->shouldPublishFeedStory($object, $xactions)) { | if ($this->shouldPublishFeedStory($object, $xactions)) { | ||||
| $mailed = array(); | |||||
| if ($mail) { | |||||
| $mailed = $mail->buildRecipientList(); | |||||
| } | |||||
| $this->publishFeedStory( | $this->publishFeedStory( | ||||
| $object, | $object, | ||||
| $xactions, | $xactions, | ||||
| $mailed); | $mailed); | ||||
| } | } | ||||
| return $xactions; | return $xactions; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,099 Lines • ▼ Show 20 Lines | protected function sendMail( | ||||
| foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
| if (!$xaction->shouldHideForMail($xactions)) { | if (!$xaction->shouldHideForMail($xactions)) { | ||||
| $any_visible = true; | $any_visible = true; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| if (!$any_visible) { | if (!$any_visible) { | ||||
| return; | return array(); | ||||
| } | } | ||||
| $email_force = array(); | |||||
| $email_to = $this->mailToPHIDs; | $email_to = $this->mailToPHIDs; | ||||
| $email_cc = $this->mailCCPHIDs; | $email_cc = $this->mailCCPHIDs; | ||||
| $email_cc = array_merge($email_cc, $this->heraldEmailPHIDs); | $email_cc = array_merge($email_cc, $this->heraldEmailPHIDs); | ||||
| $email_force = $this->heraldForcedEmailPHIDs; | |||||
| $phids = array_merge($email_to, $email_cc); | $targets = $this->buildReplyHandler($object) | ||||
| $handles = id(new PhabricatorHandleQuery()) | ->getMailTargets($email_to, $email_cc); | ||||
| ->setViewer($this->requireActor()) | |||||
| ->withPHIDs($phids) | // Set this explicitly before we start swapping out the effective actor. | ||||
| ->execute(); | $this->setActingAsPHID($this->getActingAsPHID()); | ||||
| $mailed = array(); | |||||
| foreach ($targets as $target) { | |||||
| $original_actor = $this->getActor(); | |||||
| $this->setActor($target->getViewer()); | |||||
| // TODO: Swap locale to viewer locale. | |||||
| $caught = null; | |||||
| try { | |||||
| // Reload handles for the new viewer. | |||||
| $this->loadHandles($xactions); | |||||
| $template = $this->buildMailTemplate($object); | $mail = $this->sendMailToTarget($object, $xactions, $target); | ||||
| } catch (Exception $ex) { | |||||
| $caught = $ex; | |||||
| } | |||||
| $this->setActor($original_actor); | |||||
| if ($caught) { | |||||
| throw $ex; | |||||
| } | |||||
| foreach ($mail->buildRecipientList() as $phid) { | |||||
| $mailed[$phid] = true; | |||||
| } | |||||
| } | |||||
| return array_keys($mailed); | |||||
| } | |||||
| private function sendMailToTarget( | |||||
| PhabricatorLiskDAO $object, | |||||
| array $xactions, | |||||
| PhabricatorMailTarget $target) { | |||||
| $mail = $this->buildMailTemplate($object); | |||||
| $body = $this->buildMailBody($object, $xactions); | $body = $this->buildMailBody($object, $xactions); | ||||
| $mail_tags = $this->getMailTags($object, $xactions); | $mail_tags = $this->getMailTags($object, $xactions); | ||||
| $action = $this->getMailAction($object, $xactions); | $action = $this->getMailAction($object, $xactions); | ||||
| $reply_handler = $this->buildReplyHandler($object); | |||||
| if (PhabricatorEnv::getEnvConfig('metamta.email-preferences')) { | if (PhabricatorEnv::getEnvConfig('metamta.email-preferences')) { | ||||
| $this->addEmailPreferenceSectionToMailBody( | $this->addEmailPreferenceSectionToMailBody( | ||||
| $body, | $body, | ||||
| $object, | $object, | ||||
| $xactions); | $xactions); | ||||
| } | } | ||||
| $template | |||||
| ->setFrom($this->getActingAsPHID()) | ->setFrom($this->getActingAsPHID()) | ||||
| ->setSubjectPrefix($this->getMailSubjectPrefix()) | ->setSubjectPrefix($this->getMailSubjectPrefix()) | ||||
| ->setVarySubjectPrefix('['.$action.']') | ->setVarySubjectPrefix('['.$action.']') | ||||
| ->setThreadID($this->getMailThreadID($object), $this->getIsNewObject()) | ->setThreadID($this->getMailThreadID($object), $this->getIsNewObject()) | ||||
| ->setRelatedPHID($object->getPHID()) | ->setRelatedPHID($object->getPHID()) | ||||
| ->setExcludeMailRecipientPHIDs($this->getExcludeMailRecipientPHIDs()) | ->setExcludeMailRecipientPHIDs($this->getExcludeMailRecipientPHIDs()) | ||||
| ->setForceHeraldMailRecipientPHIDs($email_force) | ->setForceHeraldMailRecipientPHIDs($this->heraldForcedEmailPHIDs) | ||||
| ->setMailTags($mail_tags) | ->setMailTags($mail_tags) | ||||
| ->setIsBulk(true) | ->setIsBulk(true) | ||||
| ->setBody($body->render()) | ->setBody($body->render()) | ||||
| ->setHTMLBody($body->renderHTML()); | ->setHTMLBody($body->renderHTML()); | ||||
| foreach ($body->getAttachments() as $attachment) { | foreach ($body->getAttachments() as $attachment) { | ||||
| $template->addAttachment($attachment); | $mail->addAttachment($attachment); | ||||
| } | } | ||||
| if ($this->heraldHeader) { | if ($this->heraldHeader) { | ||||
| $template->addHeader('X-Herald-Rules', $this->heraldHeader); | $mail->addHeader('X-Herald-Rules', $this->heraldHeader); | ||||
| } | } | ||||
| if ($object instanceof PhabricatorProjectInterface) { | if ($object instanceof PhabricatorProjectInterface) { | ||||
| $this->addMailProjectMetadata($object, $template); | $this->addMailProjectMetadata($object, $mail); | ||||
| } | } | ||||
| if ($this->getParentMessageID()) { | if ($this->getParentMessageID()) { | ||||
| $template->setParentMessageID($this->getParentMessageID()); | $mail->setParentMessageID($this->getParentMessageID()); | ||||
| } | } | ||||
| $mails = $reply_handler->multiplexMail( | return $target->sendMail($mail); | ||||
| $template, | |||||
| array_select_keys($handles, $email_to), | |||||
| array_select_keys($handles, $email_cc)); | |||||
| foreach ($mails as $mail) { | |||||
| $mail->saveAndSend(); | |||||
| } | |||||
| $template->addTos($email_to); | |||||
| $template->addCCs($email_cc); | |||||
| return $template; | |||||
| } | } | ||||
| private function addMailProjectMetadata( | private function addMailProjectMetadata( | ||||
| PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
| PhabricatorMetaMTAMail $template) { | PhabricatorMetaMTAMail $template) { | ||||
| $project_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( | $project_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( | ||||
| $object->getPHID(), | $object->getPHID(), | ||||
| ▲ Show 20 Lines • Show All 752 Lines • Show Last 20 Lines | |||||