Add lifetime email counts to inactive subscribers criteria
[MAILPOET-4177]
This commit is contained in:
@ -15,6 +15,7 @@ use MailPoetVendor\Doctrine\ORM\EntityManager;
|
||||
class InactiveSubscribersController {
|
||||
|
||||
const UNOPENED_EMAILS_THRESHOLD = 3;
|
||||
const LIFETIME_EMAILS_THRESHOLD = 10;
|
||||
|
||||
private $processedTaskIdsTableCreated = false;
|
||||
|
||||
@ -100,6 +101,7 @@ class InactiveSubscribersController {
|
||||
// Select subscribers who received at least a number of emails after threshold date and subscribed before that
|
||||
$startId = (int)$startId;
|
||||
$endId = $startId + $batchSize;
|
||||
$lifetimeEmailsThreshold = self::LIFETIME_EMAILS_THRESHOLD;
|
||||
$inactiveSubscriberIdsTmpTable = 'inactive_subscriber_ids';
|
||||
$connection->executeQuery("
|
||||
CREATE TEMPORARY TABLE IF NOT EXISTS {$inactiveSubscriberIdsTmpTable}
|
||||
@ -111,6 +113,7 @@ class InactiveSubscribersController {
|
||||
AND s.status = :status
|
||||
AND s.id >= :startId
|
||||
AND s.id < :endId
|
||||
AND s.emails_count >= {$lifetimeEmailsThreshold}
|
||||
GROUP BY s.id
|
||||
HAVING count(s.id) >= :unopenedEmailsThreshold
|
||||
",
|
||||
|
@ -156,6 +156,19 @@ class InactiveSubscribersControllerTest extends \MailPoetTest {
|
||||
expect($subscriber->getStatus())->equals(SubscriberEntity::STATUS_SUBSCRIBED);
|
||||
}
|
||||
|
||||
public function testItDoesNotDeactivateSubscriberWithLessEmailsCountThanThreshold(): void {
|
||||
$subscriber1 = $this->createSubscriber('s1@email.com', 10, SubscriberEntity::STATUS_SUBSCRIBED, 9);
|
||||
$this->createCompletedSendingTasksForSubscriber($subscriber1, self::UNOPENED_EMAILS_THRESHOLD, 3);
|
||||
|
||||
$result = $this->controller->markInactiveSubscribers(self::INACTIVITY_DAYS_THRESHOLD, self::PROCESS_BATCH_SIZE);
|
||||
expect($result)->equals(0);
|
||||
$this->entityManager->clear();
|
||||
|
||||
$subscriber1 = $this->subscribersRepository->findOneById($subscriber1->getId());
|
||||
assert($subscriber1 instanceof SubscriberEntity);
|
||||
expect($subscriber1->getStatus())->equals(SubscriberEntity::STATUS_SUBSCRIBED);
|
||||
}
|
||||
|
||||
public function testItDoesNotDeactivatesSubscribersWhenMP2MigrationHappenedWithinInterval(): void {
|
||||
$this->createSetting(MP2Migrator::MIGRATION_COMPLETE_SETTING_KEY, true, (new Carbon())->subDays(3));
|
||||
|
||||
@ -257,11 +270,13 @@ class InactiveSubscribersControllerTest extends \MailPoetTest {
|
||||
private function createSubscriber(
|
||||
string $email,
|
||||
int $createdDaysAgo = 0,
|
||||
string $status = SubscriberEntity::STATUS_SUBSCRIBED
|
||||
string $status = SubscriberEntity::STATUS_SUBSCRIBED,
|
||||
int $emailsCount = InactiveSubscribersController::LIFETIME_EMAILS_THRESHOLD
|
||||
): SubscriberEntity {
|
||||
$createdAt = (new Carbon())->subDays($createdDaysAgo);
|
||||
$subscriber = new SubscriberEntity();
|
||||
$subscriber->setEmail($email);
|
||||
$subscriber->setEmailsCount($emailsCount);
|
||||
$subscriber->setStatus($status);
|
||||
$subscriber->setCreatedAt($createdAt);
|
||||
$this->entityManager->persist($subscriber);
|
||||
|
Reference in New Issue
Block a user