Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / auth / worker / PhabricatorAuthInviteWorker.php
blob25ad6961f260e78262dc8630a18e173e2e433a8e
1 <?php
3 final class PhabricatorAuthInviteWorker
4 extends PhabricatorWorker {
6 protected function doWork() {
7 $data = $this->getTaskData();
8 $viewer = PhabricatorUser::getOmnipotentUser();
10 $address = idx($data, 'address');
11 $author_phid = idx($data, 'authorPHID');
13 $author = id(new PhabricatorPeopleQuery())
14 ->setViewer($viewer)
15 ->withPHIDs(array($author_phid))
16 ->executeOne();
17 if (!$author) {
18 throw new PhabricatorWorkerPermanentFailureException(
19 pht('Invite has invalid author PHID ("%s").', $author_phid));
22 $invite = id(new PhabricatorAuthInviteQuery())
23 ->setViewer($viewer)
24 ->withEmailAddresses(array($address))
25 ->executeOne();
26 if ($invite) {
27 // If we're inviting a user who has already been invited, we just
28 // regenerate their invite code.
29 $invite->regenerateVerificationCode();
30 } else {
31 // Otherwise, we're creating a new invite.
32 $invite = id(new PhabricatorAuthInvite())
33 ->setEmailAddress($address);
36 // Whether this is a new invite or not, tag this most recent author as
37 // the invite author.
38 $invite->setAuthorPHID($author_phid);
40 $code = $invite->getVerificationCode();
41 $invite_uri = '/auth/invite/'.$code.'/';
42 $invite_uri = PhabricatorEnv::getProductionURI($invite_uri);
44 $template = idx($data, 'template');
45 $template = str_replace('{$INVITE_URI}', $invite_uri, $template);
47 $invite->save();
49 $mail = id(new PhabricatorMetaMTAMail())
50 ->addRawTos(array($invite->getEmailAddress()))
51 ->setForceDelivery(true)
52 ->setSubject(
53 pht(
54 '[%s] %s has invited you to join %s',
55 PlatformSymbols::getPlatformServerName(),
56 $author->getFullName(),
57 PlatformSymbols::getPlatformServerName()))
58 ->setBody($template)
59 ->saveAndSend();