Path: blob/master/src/applications/auth/worker/PhabricatorAuthInviteWorker.php
12256 views
<?php12final class PhabricatorAuthInviteWorker3extends PhabricatorWorker {45protected function doWork() {6$data = $this->getTaskData();7$viewer = PhabricatorUser::getOmnipotentUser();89$address = idx($data, 'address');10$author_phid = idx($data, 'authorPHID');1112$author = id(new PhabricatorPeopleQuery())13->setViewer($viewer)14->withPHIDs(array($author_phid))15->executeOne();16if (!$author) {17throw new PhabricatorWorkerPermanentFailureException(18pht('Invite has invalid author PHID ("%s").', $author_phid));19}2021$invite = id(new PhabricatorAuthInviteQuery())22->setViewer($viewer)23->withEmailAddresses(array($address))24->executeOne();25if ($invite) {26// If we're inviting a user who has already been invited, we just27// regenerate their invite code.28$invite->regenerateVerificationCode();29} else {30// Otherwise, we're creating a new invite.31$invite = id(new PhabricatorAuthInvite())32->setEmailAddress($address);33}3435// Whether this is a new invite or not, tag this most recent author as36// the invite author.37$invite->setAuthorPHID($author_phid);3839$code = $invite->getVerificationCode();40$invite_uri = '/auth/invite/'.$code.'/';41$invite_uri = PhabricatorEnv::getProductionURI($invite_uri);4243$template = idx($data, 'template');44$template = str_replace('{$INVITE_URI}', $invite_uri, $template);4546$invite->save();4748$mail = id(new PhabricatorMetaMTAMail())49->addRawTos(array($invite->getEmailAddress()))50->setForceDelivery(true)51->setSubject(52pht(53'[%s] %s has invited you to join %s',54PlatformSymbols::getPlatformServerName(),55$author->getFullName(),56PlatformSymbols::getPlatformServerName()))57->setBody($template)58->saveAndSend();59}6061}626364