Reactivate subscribers created before recent MP2 migration
[MAILPOET-2040]
This commit is contained in:
committed by
M. Shull
parent
279289cb34
commit
02ead5bedc
@ -125,6 +125,15 @@ class InactiveSubscribersController {
|
|||||||
$subscribers_table = Subscriber::$_table;
|
$subscribers_table = Subscriber::$_table;
|
||||||
$stats_opens_table = StatisticsOpens::$_table;
|
$stats_opens_table = StatisticsOpens::$_table;
|
||||||
|
|
||||||
|
$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")
|
$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.created_at", $threshold_date)
|
||||||
@ -133,6 +142,7 @@ class InactiveSubscribersController {
|
|||||||
->limit($batch_size)
|
->limit($batch_size)
|
||||||
->groupByExpr("$subscribers_table.id")
|
->groupByExpr("$subscribers_table.id")
|
||||||
->findArray();
|
->findArray();
|
||||||
|
}
|
||||||
|
|
||||||
$ids_to_activate = array_map(
|
$ids_to_activate = array_map(
|
||||||
function($id) {
|
function($id) {
|
||||||
|
@ -208,6 +208,24 @@ class InactiveSubscribersControllerTest extends \MailPoetTest {
|
|||||||
expect($subscriber->status)->equals(Subscriber::STATUS_INACTIVE);
|
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() {
|
function testItDoesReactivateInactiveSubscribers() {
|
||||||
list($task) = $this->createCompletedSendingTask(2);
|
list($task) = $this->createCompletedSendingTask(2);
|
||||||
$subscriber = $this->createSubscriber('s1@email.com', 10, Subscriber::STATUS_INACTIVE);
|
$subscriber = $this->createSubscriber('s1@email.com', 10, Subscriber::STATUS_INACTIVE);
|
||||||
|
Reference in New Issue
Block a user