Make sure one-click unsubscribe url won't redirect internally
[MAILPOET-4703]
This commit is contained in:
@ -274,6 +274,7 @@ class SendingQueue {
|
||||
$unsubscribeUrls = [];
|
||||
$statistics = [];
|
||||
$metas = [];
|
||||
$oneClickUnsubscribeUrls = [];
|
||||
|
||||
$newsletterEntity = $this->newslettersRepository->findOneById($newsletter->id);
|
||||
|
||||
@ -301,7 +302,8 @@ class SendingQueue {
|
||||
);
|
||||
$preparedSubscribersIds[] = $subscriber->id;
|
||||
// create personalized instant unsubsribe link
|
||||
$unsubscribeUrls[] = $this->links->getUnsubscribeUrl($queue, $subscriber->id);
|
||||
$unsubscribeUrls[] = $this->links->getUnsubscribeUrl($queue->id, $subscriberEntity);
|
||||
$oneClickUnsubscribeUrls[] = $this->links->getOneClickUnsubscribeUrl($queue->id, $subscriberEntity);
|
||||
|
||||
$metas[] = $this->mailerMetaInfo->getNewsletterMetaInfo($newsletter, $subscriberEntity);
|
||||
|
||||
@ -319,12 +321,17 @@ class SendingQueue {
|
||||
$preparedSubscribers[0],
|
||||
$statistics[0],
|
||||
$timer,
|
||||
['unsubscribe_url' => $unsubscribeUrls[0], 'meta' => $metas[0]]
|
||||
[
|
||||
'unsubscribe_url' => $unsubscribeUrls[0],
|
||||
'meta' => $metas[0],
|
||||
'one_click_unsubscribe' => $oneClickUnsubscribeUrls,
|
||||
]
|
||||
);
|
||||
$preparedNewsletters = [];
|
||||
$preparedSubscribers = [];
|
||||
$preparedSubscribersIds = [];
|
||||
$unsubscribeUrls = [];
|
||||
$oneClickUnsubscribeUrls = [];
|
||||
$statistics = [];
|
||||
$metas = [];
|
||||
}
|
||||
@ -337,7 +344,7 @@ class SendingQueue {
|
||||
$preparedSubscribers,
|
||||
$statistics,
|
||||
$timer,
|
||||
['unsubscribe_url' => $unsubscribeUrls, 'meta' => $metas]
|
||||
['unsubscribe_url' => $unsubscribeUrls, 'meta' => $metas, 'one_click_unsubscribe' => $oneClickUnsubscribeUrls]
|
||||
);
|
||||
}
|
||||
return $queue;
|
||||
|
@ -5,6 +5,7 @@ namespace MailPoet\Cron\Workers\SendingQueue\Tasks;
|
||||
use MailPoet\Cron\Workers\StatsNotifications\NewsletterLinkRepository;
|
||||
use MailPoet\Entities\NewsletterEntity;
|
||||
use MailPoet\Entities\NewsletterLinkEntity;
|
||||
use MailPoet\Entities\SubscriberEntity;
|
||||
use MailPoet\Newsletter\Links\Links as NewsletterLinks;
|
||||
use MailPoet\Router\Endpoints\Track;
|
||||
use MailPoet\Router\Router;
|
||||
@ -68,12 +69,11 @@ class Links {
|
||||
return $this->newsletterLinks->save($links, $newsletter->getId(), $queue->id);
|
||||
}
|
||||
|
||||
public function getUnsubscribeUrl($queue, $subscriberId) {
|
||||
$subscriber = $this->subscribersRepository->findOneById($subscriberId);
|
||||
public function getUnsubscribeUrl($queueId, SubscriberEntity $subscriber = null) {
|
||||
if ($this->trackingConfig->isEmailTrackingEnabled() && $subscriber) {
|
||||
$linkHash = $this->newsletterLinkRepository->findOneBy(
|
||||
[
|
||||
'queue' => $queue->id,
|
||||
'queue' => $queueId,
|
||||
'url' => NewsletterLinkEntity::INSTANT_UNSUBSCRIBE_LINK_SHORT_CODE,
|
||||
]
|
||||
);
|
||||
@ -84,7 +84,7 @@ class Links {
|
||||
$data = $this->newsletterLinks->createUrlDataObject(
|
||||
$subscriber->getId(),
|
||||
$this->linkTokens->getToken($subscriber),
|
||||
$queue->id,
|
||||
$queueId,
|
||||
$linkHash->getHash(),
|
||||
false
|
||||
);
|
||||
@ -95,8 +95,13 @@ class Links {
|
||||
);
|
||||
} else {
|
||||
$subscriptionUrlFactory = SubscriptionUrlFactory::getInstance();
|
||||
$url = $subscriptionUrlFactory->getUnsubscribeUrl($subscriber, $queue->id);
|
||||
$url = $subscriptionUrlFactory->getUnsubscribeUrl($subscriber, $queueId);
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function getOneClickUnsubscribeUrl($queueId, SubscriberEntity $subscriber): string {
|
||||
$subscriptionUrlFactory = SubscriptionUrlFactory::getInstance();
|
||||
return $subscriptionUrlFactory->getUnsubscribeUrl($subscriber, $queueId);
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +111,7 @@ class MailPoet implements MailerMethod {
|
||||
$newsletter[$record],
|
||||
$this->processSubscriber($subscriber[$record]),
|
||||
(!empty($extraParams['unsubscribe_url'][$record])) ? $extraParams['unsubscribe_url'][$record] : false,
|
||||
(!empty($extraParams['one_click_unsubscribe'][$record])) ? $extraParams['one_click_unsubscribe'][$record] : false,
|
||||
(!empty($extraParams['meta'][$record])) ? $extraParams['meta'][$record] : false
|
||||
);
|
||||
}
|
||||
@ -119,13 +120,14 @@ class MailPoet implements MailerMethod {
|
||||
$newsletter,
|
||||
$this->processSubscriber($subscriber),
|
||||
(!empty($extraParams['unsubscribe_url'])) ? $extraParams['unsubscribe_url'] : false,
|
||||
(!empty($extraParams['one_click_unsubscribe'])) ? $extraParams['one_click_unsubscribe'] : false,
|
||||
(!empty($extraParams['meta'])) ? $extraParams['meta'] : false
|
||||
);
|
||||
}
|
||||
return $body;
|
||||
}
|
||||
|
||||
private function composeBody($newsletter, $subscriber, $unsubscribeUrl, $meta): array {
|
||||
private function composeBody($newsletter, $subscriber, $unsubscribeUrl, $oneClickUnsubscribeUrl, $meta): array {
|
||||
$body = [
|
||||
'to' => ([
|
||||
'address' => $subscriber['email'],
|
||||
@ -150,9 +152,10 @@ class MailPoet implements MailerMethod {
|
||||
$body['text'] = $newsletter['body']['text'];
|
||||
}
|
||||
if ($unsubscribeUrl) {
|
||||
$oneClickIsPossible = $this->url->isUsingHttps($unsubscribeUrl);
|
||||
$body['unsubscribe'] = [
|
||||
'url' => $unsubscribeUrl,
|
||||
'post' => $this->url->isUsingHttps($unsubscribeUrl),
|
||||
'url' => $oneClickIsPossible ? $oneClickUnsubscribeUrl : $unsubscribeUrl,
|
||||
'post' => $oneClickIsPossible,
|
||||
];
|
||||
}
|
||||
if ($meta) {
|
||||
|
Reference in New Issue
Block a user