Reset engagement score for inactive subscribers

If someone hasn't received at least 3 emails in the last year, we can't
trust that their level of engagement would be the same now as it was
over a year ago.

MAILPOET-5410
This commit is contained in:
John Oleksowicz
2023-07-21 14:55:32 -05:00
committed by Aschepikov
parent f8e0ba118c
commit 99630f85aa
2 changed files with 14 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ class StatisticsOpensRepository extends Repository {
->getQuery()
->getSingleScalarResult();
if ($newslettersSentCount < 3) {
$subscriber->setEngagementScore(null);
$this->entityManager->flush();
return;
}

View File

@@ -78,6 +78,19 @@ class StatisticsOpensRepositoryTest extends \MailPoetTest {
expect($averageScoreUpdatedAt->isAfter((new CarbonImmutable())->subMinutes(5)))->true();
}
public function testItResetsSubscriberScoreIfNotEnoughNewsletters() {
$subscriber = $this->createSubscriber();
$segment = $this->createSegment();
$this->createSubscriberSegment($subscriber, $segment);
$subscriber->setEngagementScore(5);
$this->entityManager->flush();
$this->entityManager->refresh($subscriber);
expect($subscriber->getEngagementScore())->equals(5);
$this->repository->recalculateSubscriberScore($subscriber);
$this->entityManager->refresh($subscriber);
expect($subscriber->getEngagementScore())->null();
}
public function testItUpdatesScore() {
$subscriber = $this->createSubscriber();
$segment = $this->createSegment();