Path: blob/master/src/applications/metamta/engine/PhabricatorMailSMSEngine.php
12256 views
<?php12final class PhabricatorMailSMSEngine3extends PhabricatorMailMessageEngine {45public function newMessage() {6$mailer = $this->getMailer();7$mail = $this->getMail();89$message = new PhabricatorMailSMSMessage();1011$phids = $mail->getToPHIDs();12if (!$phids) {13$mail->setMessage(pht('Message has no "To" recipient.'));14return null;15}1617if (count($phids) > 1) {18$mail->setMessage(pht('Message has more than one "To" recipient.'));19return null;20}2122$phid = head($phids);2324$actor = $this->getActor($phid);25if (!$actor) {26$mail->setMessage(pht('Message recipient has no mailable actor.'));27return null;28}2930if (!$actor->isDeliverable()) {31$mail->setMessage(pht('Message recipient is not deliverable.'));32return null;33}3435$omnipotent = PhabricatorUser::getOmnipotentUser();3637$contact_numbers = id(new PhabricatorAuthContactNumberQuery())38->setViewer($omnipotent)39->withObjectPHIDs(array($phid))40->withStatuses(41array(42PhabricatorAuthContactNumber::STATUS_ACTIVE,43))44->withIsPrimary(true)45->execute();4647if (!$contact_numbers) {48$mail->setMessage(49pht('Message recipient has no primary contact number.'));50return null;51}5253// The database does not strictly guarantee that only one number is54// primary, so make sure no one has monkeyed with stuff.55if (count($contact_numbers) > 1) {56$mail->setMessage(57pht('Message recipient has more than one primary contact number.'));58return null;59}6061$contact_number = head($contact_numbers);62$contact_number = $contact_number->getContactNumber();63$to_number = new PhabricatorPhoneNumber($contact_number);64$message->setToNumber($to_number);6566$body = $mail->getBody();67if ($body !== null) {68$message->setTextBody($body);69}7071return $message;72}7374}757677