Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/metamta/engine/PhabricatorMailSMSEngine.php
12256 views
1
<?php
2
3
final class PhabricatorMailSMSEngine
4
extends PhabricatorMailMessageEngine {
5
6
public function newMessage() {
7
$mailer = $this->getMailer();
8
$mail = $this->getMail();
9
10
$message = new PhabricatorMailSMSMessage();
11
12
$phids = $mail->getToPHIDs();
13
if (!$phids) {
14
$mail->setMessage(pht('Message has no "To" recipient.'));
15
return null;
16
}
17
18
if (count($phids) > 1) {
19
$mail->setMessage(pht('Message has more than one "To" recipient.'));
20
return null;
21
}
22
23
$phid = head($phids);
24
25
$actor = $this->getActor($phid);
26
if (!$actor) {
27
$mail->setMessage(pht('Message recipient has no mailable actor.'));
28
return null;
29
}
30
31
if (!$actor->isDeliverable()) {
32
$mail->setMessage(pht('Message recipient is not deliverable.'));
33
return null;
34
}
35
36
$omnipotent = PhabricatorUser::getOmnipotentUser();
37
38
$contact_numbers = id(new PhabricatorAuthContactNumberQuery())
39
->setViewer($omnipotent)
40
->withObjectPHIDs(array($phid))
41
->withStatuses(
42
array(
43
PhabricatorAuthContactNumber::STATUS_ACTIVE,
44
))
45
->withIsPrimary(true)
46
->execute();
47
48
if (!$contact_numbers) {
49
$mail->setMessage(
50
pht('Message recipient has no primary contact number.'));
51
return null;
52
}
53
54
// The database does not strictly guarantee that only one number is
55
// primary, so make sure no one has monkeyed with stuff.
56
if (count($contact_numbers) > 1) {
57
$mail->setMessage(
58
pht('Message recipient has more than one primary contact number.'));
59
return null;
60
}
61
62
$contact_number = head($contact_numbers);
63
$contact_number = $contact_number->getContactNumber();
64
$to_number = new PhabricatorPhoneNumber($contact_number);
65
$message->setToNumber($to_number);
66
67
$body = $mail->getBody();
68
if ($body !== null) {
69
$message->setTextBody($body);
70
}
71
72
return $message;
73
}
74
75
}
76
77