Use instant unsubscribe URL for List-Unsubscribe header
[MAILPOET-2736]
This commit is contained in:
committed by
Veljko V
parent
1f744453d4
commit
d19e7714c3
@ -194,7 +194,7 @@ class SendingQueue {
|
|||||||
$subscriber
|
$subscriber
|
||||||
);
|
);
|
||||||
$preparedSubscribersIds[] = $subscriber->id;
|
$preparedSubscribersIds[] = $subscriber->id;
|
||||||
// save personalized unsubsribe link
|
// create personalized instant unsubsribe link
|
||||||
$unsubscribeUrls[] = Links::getUnsubscribeUrl($queue, $subscriber->id);
|
$unsubscribeUrls[] = Links::getUnsubscribeUrl($queue, $subscriber->id);
|
||||||
$metas[] = $this->mailerMetaInfo->getNewsletterMetaInfo($newsletter, $subscriber);
|
$metas[] = $this->mailerMetaInfo->getNewsletterMetaInfo($newsletter, $subscriber);
|
||||||
// keep track of values for statistics purposes
|
// keep track of values for statistics purposes
|
||||||
|
@ -24,7 +24,7 @@ class Links {
|
|||||||
// join HTML and TEXT rendered body into a text string
|
// join HTML and TEXT rendered body into a text string
|
||||||
$content = Helpers::joinObject($renderedNewsletter);
|
$content = Helpers::joinObject($renderedNewsletter);
|
||||||
list($content, $links) = NewsletterLinks::process($content, $newsletterId, $queueId);
|
list($content, $links) = NewsletterLinks::process($content, $newsletterId, $queueId);
|
||||||
$links = NewsletterLinks::ensureUnsubscribeLink($links);
|
$links = NewsletterLinks::ensureInstantUnsubscribeLink($links);
|
||||||
// split the processed body with hashed links back to HTML and TEXT
|
// split the processed body with hashed links back to HTML and TEXT
|
||||||
list($renderedNewsletter['html'], $renderedNewsletter['text'])
|
list($renderedNewsletter['html'], $renderedNewsletter['text'])
|
||||||
= Helpers::splitObject($content);
|
= Helpers::splitObject($content);
|
||||||
@ -43,7 +43,7 @@ class Links {
|
|||||||
$settings = SettingsController::getInstance();
|
$settings = SettingsController::getInstance();
|
||||||
if ((boolean)$settings->get('tracking.enabled')) {
|
if ((boolean)$settings->get('tracking.enabled')) {
|
||||||
$linkHash = NewsletterLinkModel::where('queue_id', $queue->id)
|
$linkHash = NewsletterLinkModel::where('queue_id', $queue->id)
|
||||||
->where('url', NewsletterLinkModel::UNSUBSCRIBE_LINK_SHORT_CODE)
|
->where('url', NewsletterLinkModel::INSTANT_UNSUBSCRIBE_LINK_SHORT_CODE)
|
||||||
->findOne();
|
->findOne();
|
||||||
if (!$linkHash instanceof NewsletterLinkModel) {
|
if (!$linkHash instanceof NewsletterLinkModel) {
|
||||||
return '';
|
return '';
|
||||||
|
@ -12,4 +12,5 @@ namespace MailPoet\Models;
|
|||||||
class NewsletterLink extends Model {
|
class NewsletterLink extends Model {
|
||||||
public static $_table = MP_NEWSLETTER_LINKS_TABLE; // phpcs:ignore PSR2.Classes.PropertyDeclaration
|
public static $_table = MP_NEWSLETTER_LINKS_TABLE; // phpcs:ignore PSR2.Classes.PropertyDeclaration
|
||||||
const UNSUBSCRIBE_LINK_SHORT_CODE = '[link:subscription_unsubscribe_url]';
|
const UNSUBSCRIBE_LINK_SHORT_CODE = '[link:subscription_unsubscribe_url]';
|
||||||
|
const INSTANT_UNSUBSCRIBE_LINK_SHORT_CODE = '[link:subscription_instant_unsubscribe_url]';
|
||||||
}
|
}
|
||||||
|
@ -136,15 +136,15 @@ class Links {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function ensureUnsubscribeLink(array $processedLinks) {
|
public static function ensureInstantUnsubscribeLink(array $processedLinks) {
|
||||||
if (in_array(
|
if (in_array(
|
||||||
NewsletterLink::UNSUBSCRIBE_LINK_SHORT_CODE,
|
NewsletterLink::INSTANT_UNSUBSCRIBE_LINK_SHORT_CODE,
|
||||||
array_column($processedLinks, 'link'))
|
array_column($processedLinks, 'link'))
|
||||||
) {
|
) {
|
||||||
return $processedLinks;
|
return $processedLinks;
|
||||||
}
|
}
|
||||||
$processedLinks[] = self::hashLink(
|
$processedLinks[] = self::hashLink(
|
||||||
NewsletterLink::UNSUBSCRIBE_LINK_SHORT_CODE,
|
NewsletterLink::INSTANT_UNSUBSCRIBE_LINK_SHORT_CODE,
|
||||||
Links::LINK_TYPE_SHORTCODE
|
Links::LINK_TYPE_SHORTCODE
|
||||||
);
|
);
|
||||||
return $processedLinks;
|
return $processedLinks;
|
||||||
|
@ -104,7 +104,7 @@ class SendingQueueTest extends \MailPoetTest {
|
|||||||
$this->newsletterLink = NewsletterLink::create();
|
$this->newsletterLink = NewsletterLink::create();
|
||||||
$this->newsletterLink->newsletterId = $this->newsletter->id;
|
$this->newsletterLink->newsletterId = $this->newsletter->id;
|
||||||
$this->newsletterLink->queueId = $this->queue->id;
|
$this->newsletterLink->queueId = $this->queue->id;
|
||||||
$this->newsletterLink->url = '[link:subscription_unsubscribe_url]';
|
$this->newsletterLink->url = '[link:subscription_instant_unsubscribe_url]';
|
||||||
$this->newsletterLink->hash = 'abcde';
|
$this->newsletterLink->hash = 'abcde';
|
||||||
$this->newsletterLink->save();
|
$this->newsletterLink->save();
|
||||||
$this->sendingErrorHandler = new SendingErrorHandler();
|
$this->sendingErrorHandler = new SendingErrorHandler();
|
||||||
|
@ -55,7 +55,7 @@ class LinksTest extends \MailPoetTest {
|
|||||||
expect($result['html'])->contains($newsletterLink->hash);
|
expect($result['html'])->contains($newsletterLink->hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItCanEnsureThatUnsubscribeLinkIsAlwaysPresent() {
|
public function testItCanEnsureThatInstantUnsubscribeLinkIsAlwaysPresent() {
|
||||||
$newsletter = Newsletter::create();
|
$newsletter = Newsletter::create();
|
||||||
$newsletter->type = Newsletter::TYPE_STANDARD;
|
$newsletter->type = Newsletter::TYPE_STANDARD;
|
||||||
$newsletter->save();
|
$newsletter->save();
|
||||||
@ -66,7 +66,7 @@ class LinksTest extends \MailPoetTest {
|
|||||||
$queue = (object)['id' => 2];
|
$queue = (object)['id' => 2];
|
||||||
Links::process($renderedNewsletter, $newsletter, $queue);
|
Links::process($renderedNewsletter, $newsletter, $queue);
|
||||||
$unsubscribeCount = NewsletterLink::where('newsletter_id', $newsletter->id)
|
$unsubscribeCount = NewsletterLink::where('newsletter_id', $newsletter->id)
|
||||||
->where('url', NewsletterLink::UNSUBSCRIBE_LINK_SHORT_CODE)->count();
|
->where('url', NewsletterLink::INSTANT_UNSUBSCRIBE_LINK_SHORT_CODE)->count();
|
||||||
expect($unsubscribeCount)->equals(1);
|
expect($unsubscribeCount)->equals(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,13 +246,13 @@ class LinksTest extends \MailPoetTest {
|
|||||||
'hash' => 'abcdfgh',
|
'hash' => 'abcdfgh',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
$links = Links::ensureUnsubscribeLink($links);
|
$links = Links::ensureInstantUnsubscribeLink($links);
|
||||||
expect(count($links))->equals(2);
|
expect(count($links))->equals(2);
|
||||||
expect($links[1]['link'])->equals(NewsletterLink::UNSUBSCRIBE_LINK_SHORT_CODE);
|
expect($links[1]['link'])->equals(NewsletterLink::INSTANT_UNSUBSCRIBE_LINK_SHORT_CODE);
|
||||||
expect($links[1]['type'])->equals(Links::LINK_TYPE_SHORTCODE);
|
expect($links[1]['type'])->equals(Links::LINK_TYPE_SHORTCODE);
|
||||||
expect($links[1])->hasKey('processed_link');
|
expect($links[1])->hasKey('processed_link');
|
||||||
expect($links[1])->hasKey('hash');
|
expect($links[1])->hasKey('hash');
|
||||||
$links = Links::ensureUnsubscribeLink($links);
|
$links = Links::ensureInstantUnsubscribeLink($links);
|
||||||
expect(count($links))->equals(2);
|
expect(count($links))->equals(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user