Reactivate subscribers created before recent MP2 migration

[MAILPOET-2040]
This commit is contained in:
Rostislav Wolny
2019-05-14 10:08:42 +02:00
committed by M. Shull
parent 279289cb34
commit 02ead5bedc
2 changed files with 36 additions and 8 deletions

View File

@ -125,14 +125,24 @@ class InactiveSubscribersController {
$subscribers_table = Subscriber::$_table;
$stats_opens_table = StatisticsOpens::$_table;
$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'")
->whereLt("$subscribers_table.created_at", $threshold_date)
->where("$subscribers_table.status", Subscriber::STATUS_INACTIVE)
->whereRaw("$stats_opens_table.id IS NOT NULL")
->limit($batch_size)
->groupByExpr("$subscribers_table.id")
->findArray();
$mp2_migration_date = $this->getMP2MigrationDate();
if ($mp2_migration_date && $mp2_migration_date > $threshold_date) {
// If MP2 migration occurred during detection interval re-activate all subscribers created before migration
$ids_to_activate = \ORM::forTable($subscribers_table)->select("$subscribers_table.id")
->whereLt("$subscribers_table.created_at", $mp2_migration_date)
->where("$subscribers_table.status", Subscriber::STATUS_INACTIVE)
->limit($batch_size)
->findArray();
} else {
$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'")
->whereLt("$subscribers_table.created_at", $threshold_date)
->where("$subscribers_table.status", Subscriber::STATUS_INACTIVE)
->whereRaw("$stats_opens_table.id IS NOT NULL")
->limit($batch_size)
->groupByExpr("$subscribers_table.id")
->findArray();
}
$ids_to_activate = array_map(
function($id) {

View File

@ -208,6 +208,24 @@ class InactiveSubscribersControllerTest extends \MailPoetTest {
expect($subscriber->status)->equals(Subscriber::STATUS_INACTIVE);
}
function testItActivatesSubscribersWhenMP2MigrationHappenedWithinInterval() {
list($task) = $this->createCompletedSendingTaskWithOneOpen(3);
$migration_complete_setting = Setting::createOrUpdate([
'name' => MP2Migrator::MIGRATION_COMPLETE_SETTING_KEY,
'created_at' => (new Carbon())->subDays(3),
]);
$subscriber = $this->createSubscriber('s1@email.com', 10, Subscriber::STATUS_INACTIVE);
$this->addSubcriberToTask($subscriber, $task);
$result = $this->controller->markActiveSubscribers(5, 100);
expect($result)->equals(1);
$subscriber = Subscriber::findOne($subscriber->id);
expect($subscriber->status)->equals(Subscriber::STATUS_SUBSCRIBED);
$migration_complete_setting->delete();
}
function testItDoesReactivateInactiveSubscribers() {
list($task) = $this->createCompletedSendingTask(2);
$subscriber = $this->createSubscriber('s1@email.com', 10, Subscriber::STATUS_INACTIVE);