feat: offer a newsletter opt-in for the other participants
addresses #869etn6c5
This commit is contained in:
1 parent
96b7b3f451
commit
876e69e62c
10 files changed
+598
-71
No files matched your search
@@ -7,6 +7,7 @@ namespace App\Service;
|
||||
use App\Email\Mailer;
|
||||
use App\Entity\NewsletterConsent;
|
||||
use App\Entity\NewsletterOptInRequest;
|
||||
use App\Enum\NewsletterOptInContext;
|
||||
use App\Exception\NewsletterListNotAllowedException;
|
||||
use App\Exception\NewsletterProviderException;
|
||||
use App\Mailjet\ApiClient;
|
||||
@@ -37,8 +38,13 @@ class NewsletterManager
|
||||
) {
|
||||
}
|
||||
|
||||
public function requestConfirmation(string $email, ?string $firstName = null, ?string $lastName = null): void
|
||||
{
|
||||
public function requestConfirmation(
|
||||
string $email,
|
||||
?string $firstName = null,
|
||||
?string $lastName = null,
|
||||
NewsletterOptInContext $optInContext = NewsletterOptInContext::Own,
|
||||
?string $requestedByName = null,
|
||||
): void {
|
||||
$normalizedEmail = $this->normalizeEmail($email);
|
||||
|
||||
if (false === filter_var($normalizedEmail, FILTER_VALIDATE_EMAIL)) {
|
||||
@@ -51,6 +57,8 @@ class NewsletterManager
|
||||
mailjetListIds: [$this->defaultMailjetListId()],
|
||||
firstName: $this->normalizeName($firstName),
|
||||
lastName: $this->normalizeName($lastName),
|
||||
optInContext: $optInContext,
|
||||
requestedByName: $this->normalizeName($requestedByName),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -210,7 +218,7 @@ class NewsletterManager
|
||||
/**
|
||||
* @param list<int|string> $mailjetListIds
|
||||
*/
|
||||
private function createOrRefreshConfirmation(string $normalizedEmail, bool $deleteExpiredPending = true, bool $findExistingPending = true, array $mailjetListIds = [], ?string $firstName = null, ?string $lastName = null): void
|
||||
private function createOrRefreshConfirmation(string $normalizedEmail, bool $deleteExpiredPending = true, bool $findExistingPending = true, array $mailjetListIds = [], ?string $firstName = null, ?string $lastName = null, NewsletterOptInContext $optInContext = NewsletterOptInContext::Own, ?string $requestedByName = null): void
|
||||
{
|
||||
$token = $this->generateToken();
|
||||
$tokenHash = $this->hashToken($token);
|
||||
@@ -255,11 +263,13 @@ class NewsletterManager
|
||||
$context = [
|
||||
'token' => $token,
|
||||
'newsletterLists' => $this->createListIdMapping($mailjetListIds),
|
||||
'recipientFirstName' => $firstName,
|
||||
'requestedByName' => $requestedByName,
|
||||
];
|
||||
$options = [
|
||||
'to' => $normalizedEmail,
|
||||
'subject' => 'Deine Anmeldung zum E&P Newsletter',
|
||||
'template' => 'email/newsletter_opt_in.html.twig',
|
||||
'subject' => $optInContext->subject(),
|
||||
'template' => $optInContext->template(),
|
||||
];
|
||||
$this->mailer->createAndSendEmail($context, $options);
|
||||
} catch (\Throwable $exception) {
|
||||
@@ -275,9 +285,13 @@ class NewsletterManager
|
||||
throw new NewsletterProviderException('Could not send newsletter confirmation email.', previous: $exception);
|
||||
}
|
||||
|
||||
// The log line is the provenance record for third-party sign-ups: there is no column
|
||||
// saying who requested a companion's opt-in, so it has to be recoverable from here.
|
||||
$this->logger->info('Newsletter confirmation requested', [
|
||||
'email' => $normalizedEmail,
|
||||
'expires_at' => $expiresAt->format(DATE_ATOM),
|
||||
'context' => $optInContext->value,
|
||||
'requested_by' => $requestedByName,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user