Make method more clear
[MAILPOET-2439]
This commit is contained in:
committed by
Jack Kitterhing
parent
f1934ff880
commit
5b6b21b23f
@ -65,7 +65,7 @@ class Scheduler {
|
|||||||
if (!in_array($newsletter->getType(), $this->supported_types)) {
|
if (!in_array($newsletter->getType(), $this->supported_types)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($this->isTaskScheduled($newsletter->getId())) {
|
if ($this->hasTaskBeenScheduled($newsletter->getId())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -91,9 +91,9 @@ class Scheduler {
|
|||||||
return !(bool)$settings['enabled'];
|
return !(bool)$settings['enabled'];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function isTaskScheduled($newsletter_id) {
|
private function hasTaskBeenScheduled($newsletter_id) {
|
||||||
$existing = $this->repository->findByNewsletterId($newsletter_id);
|
$existing = $this->repository->findByNewsletterId($newsletter_id);
|
||||||
return count($existing) > 0;
|
return $existing instanceof StatsNotificationEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getNextRunDate() {
|
private function getNextRunDate() {
|
||||||
|
@ -15,20 +15,17 @@ class StatsNotificationsRepository extends Repository {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $newsletter_id
|
* @param int $newsletter_id
|
||||||
* @return StatsNotificationEntity[]
|
* @return StatsNotificationEntity|null
|
||||||
*/
|
*/
|
||||||
public function findByNewsletterId($newsletter_id) {
|
public function findByNewsletterId($newsletter_id) {
|
||||||
return $this->doctrine_repository
|
return $this->doctrine_repository
|
||||||
->createQueryBuilder('stn')
|
->createQueryBuilder('stn')
|
||||||
->join('stn.task', 'tasks')
|
|
||||||
->join('stn.newsletter', 'n')
|
->join('stn.newsletter', 'n')
|
||||||
->addSelect('tasks')
|
|
||||||
->where('tasks.type = :taskType')
|
|
||||||
->setParameter('taskType', Worker::TASK_TYPE)
|
|
||||||
->andWhere('n.id = :newsletterId')
|
->andWhere('n.id = :newsletterId')
|
||||||
->setParameter('newsletterId', $newsletter_id)
|
->setParameter('newsletterId', $newsletter_id)
|
||||||
|
->setMaxResults(1)
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->getOneOrNullResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -232,7 +232,7 @@ class SchedulerTest extends \MailPoetUnitTest {
|
|||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('findByNewsletterId')
|
->method('findByNewsletterId')
|
||||||
->with($newsletter_id)
|
->with($newsletter_id)
|
||||||
->willReturn([new ScheduledTaskEntity()]);
|
->willReturn(new StatsNotificationEntity(new NewsletterEntity(), new ScheduledTaskEntity()));
|
||||||
$this->entityManager
|
$this->entityManager
|
||||||
->expects($this->never())
|
->expects($this->never())
|
||||||
->method('persist');
|
->method('persist');
|
||||||
|
Reference in New Issue
Block a user