Do not deactivate subscribers when mp2 migration completed recently
[MAILPOET-2040]
This commit is contained in:
committed by
M. Shull
parent
1f3a9278d2
commit
279289cb34
@ -3,9 +3,11 @@
|
||||
namespace MailPoet\Subscribers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use MailPoet\Config\MP2Migrator;
|
||||
use MailPoet\Models\ScheduledTask;
|
||||
use MailPoet\Models\ScheduledTaskSubscriber;
|
||||
use MailPoet\Models\SendingQueue;
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\Models\StatisticsOpens;
|
||||
use MailPoet\Models\Subscriber;
|
||||
|
||||
@ -79,6 +81,13 @@ class InactiveSubscribersController {
|
||||
$threshold_date_iso, $threshold_date_iso, $day_ago_iso
|
||||
);
|
||||
|
||||
// If MP2 migration occurred during detection interval we can't deactivate subscribers
|
||||
// because they are imported with original subscription date but they were not present in a list for whole period
|
||||
$mp2_migration_date = $this->getMP2MigrationDate();
|
||||
if ($mp2_migration_date && $mp2_migration_date > $threshold_date) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Select subscribers who received a recent tracked email but didn't open it
|
||||
$ids_to_deactivate = \ORM::forTable($subscribers_table)->rawQuery("
|
||||
SELECT s.id FROM $subscribers_table as s
|
||||
@ -140,4 +149,12 @@ class InactiveSubscribersController {
|
||||
));
|
||||
return count($ids_to_activate);
|
||||
}
|
||||
|
||||
private function getMP2MigrationDate() {
|
||||
$migration_complete = Setting::where('name', MP2Migrator::MIGRATION_COMPLETE_SETTING_KEY)->findOne();
|
||||
if ($migration_complete === false) {
|
||||
return null;
|
||||
}
|
||||
return new Carbon($migration_complete->created_at);
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,12 @@
|
||||
namespace MailPoet\Subscribers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use MailPoet\Config\MP2Migrator;
|
||||
use MailPoet\Models\Newsletter;
|
||||
use MailPoet\Models\ScheduledTask;
|
||||
use MailPoet\Models\ScheduledTaskSubscriber;
|
||||
use MailPoet\Models\SendingQueue;
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\Models\StatisticsOpens;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Tasks\Sending;
|
||||
@ -143,6 +145,24 @@ class InactiveSubscribersControllerTest extends \MailPoetTest {
|
||||
expect($subscriber->status)->equals(Subscriber::STATUS_SUBSCRIBED);
|
||||
}
|
||||
|
||||
function testItDoesNotDeactivatesSubscribersWhenMP2MigrationHappenedWithinInterval() {
|
||||
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);
|
||||
$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);
|
||||
$migration_complete_setting->delete();
|
||||
}
|
||||
|
||||
function testItActivatesSubscriberWhoRecentlyOpenedEmail() {
|
||||
list($task, $queue) = $this->createCompletedSendingTask(2);
|
||||
$subscriber = $this->createSubscriber('s1@email.com', 10, Subscriber::STATUS_INACTIVE);
|
||||
|
Reference in New Issue
Block a user