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())
15 ->withPHIDs(array($author_phid))
18 throw new PhabricatorWorkerPermanentFailureException(
19 pht('Invite has invalid author PHID ("%s").', $author_phid));
22 $invite = id(new PhabricatorAuthInviteQuery())
24 ->withEmailAddresses(array($address))
27 // If we're inviting a user who has already been invited, we just
28 // regenerate their invite code.
29 $invite->regenerateVerificationCode();
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
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);
49 $mail = id(new PhabricatorMetaMTAMail())
50 ->addRawTos(array($invite->getEmailAddress()))
51 ->setForceDelivery(true)
54 '[%s] %s has invited you to join %s',
55 PlatformSymbols
::getPlatformServerName(),
56 $author->getFullName(),
57 PlatformSymbols
::getPlatformServerName()))