Consider also confirmed_at for subscribers deactivation

[MAILPOET-1791]
This commit is contained in:
Rostislav Wolny
2019-04-19 13:27:32 +02:00
committed by M. Shull
parent 8e46f12a0e
commit a8584523d3
2 changed files with 18 additions and 4 deletions

View File

@ -74,9 +74,9 @@ class InactiveSubscribersController {
JOIN $scheduled_task_subcribres_table as sts ON s.id = sts.subscriber_id JOIN $scheduled_task_subcribres_table as sts ON s.id = sts.subscriber_id
JOIN ($scheduled_task_ids_query) task_ids ON task_ids.id = sts.task_id JOIN ($scheduled_task_ids_query) task_ids ON task_ids.id = sts.task_id
LEFT OUTER JOIN $statistics_opens_table as so ON s.id = so.subscriber_id AND so.created_at > ? LEFT OUTER JOIN $statistics_opens_table as so ON s.id = so.subscriber_id AND so.created_at > ?
WHERE s.created_at < ? AND s.status = ? AND so.id IS NULL WHERE s.created_at < ? AND (s.confirmed_at IS NULL OR s.confirmed_at < ?) AND s.status = ? AND so.id IS NULL
GROUP BY s.id LIMIT ?", GROUP BY s.id LIMIT ?",
[$threshold_date_iso, $threshold_date_iso, Subscriber::STATUS_SUBSCRIBED, $batch_size] [$threshold_date_iso, $threshold_date_iso, $threshold_date_iso, Subscriber::STATUS_SUBSCRIBED, $batch_size]
)->findArray(); )->findArray();
$ids_to_deactivate = array_map( $ids_to_deactivate = array_map(

View File

@ -76,7 +76,7 @@ class InactiveSubscribersControllerTest extends \MailPoetTest {
} }
function testItDoesNotDeactivateNewSubscriberWithUnopenedEmail() { function testItDoesNotDeactivateNewSubscriberWithUnopenedEmail() {
list($task) = $this->createCompletedSendingTaskWithOneOpen(1); list($task) = $this->createCompletedSendingTaskWithOneOpen(3);
$subscriber = $this->createSubscriber('s1@email.com', 2); $subscriber = $this->createSubscriber('s1@email.com', 2);
$this->addSubcriberToTask($subscriber, $task); $this->addSubcriberToTask($subscriber, $task);
@ -87,8 +87,22 @@ class InactiveSubscribersControllerTest extends \MailPoetTest {
expect($subscriber->status)->equals(Subscriber::STATUS_SUBSCRIBED); expect($subscriber->status)->equals(Subscriber::STATUS_SUBSCRIBED);
} }
function testItDoesNotDeactivateNewlyConfirmedSubscriberWithUnopenedEmail() {
list($task) = $this->createCompletedSendingTaskWithOneOpen(3);
$subscriber = $this->createSubscriber('s1@email.com', 10);
$subscriber->confirmed_at = (new Carbon())->subDays(2)->toDateTimeString();
$subscriber->save();
$this->addSubcriberToTask($subscriber, $task);
$result = $this->controller->markInactiveSubscribers(5, 100);
expect($result)->equals(0);
$subscriber = Subscriber::findOne($subscriber->id);
expect($subscriber->status)->equals(Subscriber::STATUS_SUBSCRIBED);
}
function testItDoesNotDeactivateSubscriberWithoutSentEmail() { function testItDoesNotDeactivateSubscriberWithoutSentEmail() {
$this->createCompletedSendingTaskWithOneOpen(1); $this->createCompletedSendingTaskWithOneOpen(3);
$subscriber = $this->createSubscriber('s1@email.com', 10); $subscriber = $this->createSubscriber('s1@email.com', 10);
$result = $this->controller->markInactiveSubscribers(5, 100); $result = $this->controller->markInactiveSubscribers(5, 100);
expect($result)->equals(0); expect($result)->equals(0);