15use Psr\Log\LoggerInterface;
37 private readonly LoggerInterface $logger,
39 $this->options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
42 private function buildEmailByType(
46 $builder = $this->confirmEmailBuilderFactory->newFromContext( $ctx );
47 return match ( $type ) {
48 self::EMAIL_TYPE_CREATED => $builder->buildEmailCreated( $data ),
49 self::EMAIL_TYPE_CHANGED => $builder->buildEmailChanged( $data ),
50 self::EMAIL_TYPE_SET => $builder->buildEmailSet( $data ),
51 default =>
throw new LogicException(
52 '$type "' . $type .
'" is not any of the supported types'
64 private function sendEmailToRecipient(
65 MessageLocalizer $localizer,
67 ConfirmEmailContent $emailContent
69 $sender = new MailAddress(
71 $localizer->msg(
'emailsender' )->inContentLanguage()->text()
74 return $this->emailer->send(
77 $emailContent->getSubject(),
78 $emailContent->getPlaintext(),
79 $emailContent->getHtml()
95 $emailContent = $this->buildEmailByType( $ctx, $type, $data );
96 $recipientUser = $this->userFactory->newFromUserIdentity( $data->
getRecipientUser() );
98 $emailAsArray = $emailContent->toArray();
99 $this->hookRunner->onUserSendConfirmationMail(
110 $emailContent = ConfirmEmailContent::newFromArray( $emailAsArray );
112 $status = $this->sendEmailToRecipient( $ctx, $recipientUser, $emailContent );
114 if ( $status->isGood() ) {
115 $this->logger->info(
'Confirmation email sent', [
116 'event' =>
'email_confirmation_sent',
120 $this->logger->warning(
'Confirmation email failed', [
121 'event' =>
'email_confirmation_send_failed',
Value class defining an email sent to the user.
A class containing constants representing the names of configuration variables.
const PasswordSender
Name constant for the PasswordSender setting, for use with Config::get()
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Interface for objects which can provide a MediaWiki context on request.