Change cron scheduling for SubscribersEngagementScore

[MAILPOET-3585]
This commit is contained in:
Jan Lysý
2021-04-29 11:16:23 +02:00
committed by Veljko V
parent 43058ce38a
commit cfa29c9df1
2 changed files with 30 additions and 6 deletions

View File

@ -8,6 +8,7 @@ use MailPoet\Entities\SubscriberCustomFieldEntity;
use MailPoet\Entities\SubscriberEntity;
use MailPoet\Entities\SubscriberSegmentEntity;
use MailPoet\WP\Functions as WPFunctions;
use MailPoetVendor\Carbon\Carbon;
use MailPoetVendor\Doctrine\DBAL\Connection;
use MailPoetVendor\Doctrine\ORM\EntityManager;
use MailPoetVendor\Doctrine\ORM\Query\Expr\Join;
@ -292,4 +293,17 @@ class SubscribersRepository extends Repository {
}
return $this->findOneBy(['wpUserId' => $wpUser->ID]);
}
public function findByUpdatedScoreNotInLastMonth(int $limit): array {
$dateTime = (new Carbon())->subMonths(1);
return $this->entityManager->createQueryBuilder()
->select('s')
->from(SubscriberEntity::class, 's')
->where('s.engagementScoreUpdatedAt IS NULL')
->orWhere('s.engagementScoreUpdatedAt < :dateTime')
->setParameter('dateTime', $dateTime)
->getQuery()
->setMaxResults($limit)
->getResult();
}
}