Limit number of confirmation emails sent to one email
MAILPOET-1734
This commit is contained in:
@ -199,6 +199,7 @@ class Migrator {
|
||||
'deleted_at TIMESTAMP NULL,',
|
||||
'unconfirmed_data longtext,',
|
||||
'source ENUM("form", "imported", "administrator", "api", "wordpress_user", "unknown") DEFAULT "unknown",',
|
||||
'count_confirmations int(11) unsigned NOT NULL DEFAULT 0,',
|
||||
'PRIMARY KEY (id),',
|
||||
'UNIQUE KEY email (email),',
|
||||
'KEY wp_user_id (wp_user_id),',
|
||||
|
@ -14,6 +14,10 @@ class SubscriberSegment extends Model {
|
||||
static function unsubscribeFromSegments($subscriber, $segment_ids = array()) {
|
||||
if($subscriber === false) return false;
|
||||
|
||||
// Reset confirmation emails count, so user can resubscribe
|
||||
$subscriber->count_confirmations = 0;
|
||||
$subscriber->save();
|
||||
|
||||
$wp_segment = Segment::getWPSegment();
|
||||
$wc_segment = Segment::getWooCommerceSegment();
|
||||
|
||||
|
@ -10,6 +10,8 @@ use MailPoet\Util\Helpers;
|
||||
|
||||
class ConfirmationEmailMailer {
|
||||
|
||||
const MAX_CONFIRMATION_EMAILS = 3;
|
||||
|
||||
/** @var Mailer */
|
||||
private $mailer;
|
||||
|
||||
@ -29,6 +31,12 @@ class ConfirmationEmailMailer {
|
||||
return false;
|
||||
}
|
||||
|
||||
$subscriber->count_confirmations++;
|
||||
$subscriber->save();
|
||||
if(!is_user_logged_in() && $subscriber->count_confirmations > self::MAX_CONFIRMATION_EMAILS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$segments = $subscriber->segments()->findMany();
|
||||
$segment_names = array_map(function($segment) {
|
||||
return $segment->name;
|
||||
|
@ -117,6 +117,7 @@ class SubscriberSegmentTest extends \MailPoetTest {
|
||||
expect($subscriber->subscriptions[2]['segment_id'])->equals($segment_3->id);
|
||||
|
||||
// verify that subscriber is not subscribed only to the non-WP segment (#2)
|
||||
$subscriber = $this->subscriber;
|
||||
SubscriberSegment::unsubscribeFromSegments($subscriber, array($segment_1->id, $segment_2->id, $segment_3->id));
|
||||
$subscriber = Subscriber::findOne($subscriber->id)->withSubscriptions();
|
||||
|
||||
|
Reference in New Issue
Block a user