Use last_subscribed_at for inactive subscribers detection
[MAILPOET-1993]
This commit is contained in:
committed by
M. Shull
parent
0b40475e7a
commit
1aa03dc80e
@ -94,9 +94,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.confirmed_at IS NULL OR s.confirmed_at < ?) AND s.status = ? AND so.id IS NULL
|
WHERE s.last_subscribed_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, $threshold_date_iso, Subscriber::STATUS_SUBSCRIBED, $batch_size]
|
[$threshold_date_iso, $threshold_date_iso, Subscriber::STATUS_SUBSCRIBED, $batch_size]
|
||||||
)->findArray();
|
)->findArray();
|
||||||
|
|
||||||
$ids_to_deactivate = array_map(
|
$ids_to_deactivate = array_map(
|
||||||
@ -136,7 +136,7 @@ class InactiveSubscribersController {
|
|||||||
} else {
|
} else {
|
||||||
$ids_to_activate = \ORM::forTable($subscribers_table)->select("$subscribers_table.id")
|
$ids_to_activate = \ORM::forTable($subscribers_table)->select("$subscribers_table.id")
|
||||||
->leftOuterJoin($stats_opens_table, "$subscribers_table.id = $stats_opens_table.subscriber_id AND $stats_opens_table.created_at > '$threshold_date'")
|
->leftOuterJoin($stats_opens_table, "$subscribers_table.id = $stats_opens_table.subscriber_id AND $stats_opens_table.created_at > '$threshold_date'")
|
||||||
->whereLt("$subscribers_table.created_at", $threshold_date)
|
->whereLt("$subscribers_table.last_subscribed_at", $threshold_date)
|
||||||
->where("$subscribers_table.status", Subscriber::STATUS_INACTIVE)
|
->where("$subscribers_table.status", Subscriber::STATUS_INACTIVE)
|
||||||
->whereRaw("$stats_opens_table.id IS NOT NULL")
|
->whereRaw("$stats_opens_table.id IS NOT NULL")
|
||||||
->limit($batch_size)
|
->limit($batch_size)
|
||||||
|
@ -93,11 +93,11 @@ class InactiveSubscribersControllerTest extends \MailPoetTest {
|
|||||||
expect($subscriber->status)->equals(Subscriber::STATUS_SUBSCRIBED);
|
expect($subscriber->status)->equals(Subscriber::STATUS_SUBSCRIBED);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItDoesNotDeactivateNewlyConfirmedSubscriberWithUnopenedEmail() {
|
function testItDoesNotDeactivateNewlyResubscribedSubscriberWithUnopenedEmail() {
|
||||||
list($task) = $this->createCompletedSendingTaskWithOneOpen($completed_days_ago = 3);
|
list($task) = $this->createCompletedSendingTaskWithOneOpen($completed_days_ago = 3);
|
||||||
|
|
||||||
$subscriber = $this->createSubscriber('s1@email.com', $created_days_ago = 10);
|
$subscriber = $this->createSubscriber('s1@email.com', $created_days_ago = 10);
|
||||||
$subscriber->confirmed_at = (new Carbon())->subDays(2)->toDateTimeString();
|
$subscriber->last_subscribed_at = (new Carbon())->subDays(2)->toDateTimeString();
|
||||||
$subscriber->save();
|
$subscriber->save();
|
||||||
$this->addSubcriberToTask($subscriber, $task);
|
$this->addSubcriberToTask($subscriber, $task);
|
||||||
|
|
||||||
@ -250,6 +250,7 @@ class InactiveSubscribersControllerTest extends \MailPoetTest {
|
|||||||
$created_at = (new Carbon())->subDays($created_days_ago)->toDateTimeString();
|
$created_at = (new Carbon())->subDays($created_days_ago)->toDateTimeString();
|
||||||
$subscriber = Subscriber::createOrUpdate(['email' => $email, 'status' => $status]);
|
$subscriber = Subscriber::createOrUpdate(['email' => $email, 'status' => $status]);
|
||||||
$subscriber->created_at = $created_at;
|
$subscriber->created_at = $created_at;
|
||||||
|
$subscriber->last_subscribed_at = $created_at;
|
||||||
$subscriber->save();
|
$subscriber->save();
|
||||||
return $subscriber;
|
return $subscriber;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user