Skip to content

Commit b03cdb5

Browse files
authored
Filter migrated and processing subscriptions in Mollie subscription repository queries (#347)
2 parents 06c723b + e52bb44 commit b03cdb5

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

UPGRADE-3.3.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,17 @@
2424
```bash
2525
bin/console doctrine:migrations:migrate
2626
```
27+
28+
To support the transition to 4.0, two interfaces gained methods used by the migration process. If you provide
29+
your own implementations, add them (note that both interfaces are themselves deprecated and will be removed in
30+
4.0):
31+
32+
`Sylius\MolliePlugin\Repository\MollieSubscriptionRepositoryInterface`:
33+
- `findScheduledSubscriptionsForMigration(): array`
34+
- `iterateToMigrate(int $batchSize): iterable`
35+
- `findMigrated(int $limit): array`
36+
37+
`Sylius\MolliePlugin\Entity\MollieSubscriptionInterface`:
38+
- `getMigratedAt(): ?\DateTime`
39+
- `setMigratedAt(?\DateTimeInterface $migratedAt): void`
40+
- `isMigrated(): bool`

src/Repository/MollieSubscriptionRepository.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,21 @@ public function findScheduledSubscriptions(): array
7272
$qb->andWhere('s.scheduledDate < :date');
7373
$qb->setParameter('date', new \DateTime());
7474
$qb->andWhere('s.fulfilledDate IS NULL');
75+
$qb->andWhere('q.migratedAt IS NULL');
7576

7677
return $qb->getQuery()->getResult();
7778
}
7879

7980
public function findScheduledSubscriptionsForMigration(): array
8081
{
8182
$qb = $this->createQueryBuilder('q');
82-
$qb->andWhere('q.state IN (:states)');
83-
$qb->setParameter('states', [MollieSubscriptionInterface::STATE_ACTIVE, MollieSubscriptionInterface::STATE_PROCESSING]);
83+
$qb->andWhere('q.state = :state');
84+
$qb->setParameter('state', MollieSubscriptionInterface::STATE_ACTIVE);
8485
$qb->leftJoin('q.schedules', 's');
8586
$qb->andWhere('s.scheduledDate < :date');
8687
$qb->setParameter('date', new \DateTime());
8788
$qb->andWhere('s.fulfilledDate IS NULL');
89+
$qb->andWhere('q.migratedAt IS NULL');
8890

8991
return $qb->getQuery()->getResult();
9092
}
@@ -96,6 +98,7 @@ public function findProcessableSubscriptions(): array
9698
$qb->setParameter('state', MollieSubscriptionInterface::STATE_PROCESSING);
9799
$qb->andWhere('q.processingState = :processingState');
98100
$qb->setParameter('processingState', MollieSubscriptionInterface::PROCESSING_STATE_PENDING);
101+
$qb->andWhere('q.migratedAt IS NULL');
99102

100103
return $qb->getQuery()->getResult();
101104
}
@@ -104,8 +107,11 @@ public function iterateToMigrate(int $batchSize): iterable
104107
{
105108
$qb = $this->createQueryBuilder('q');
106109
$qb->andWhere('q.migratedAt IS NULL');
107-
$qb->andWhere('q.state != :paused');
108-
$qb->setParameter('paused', MollieSubscriptionInterface::STATE_PAUSED);
110+
$qb->andWhere('q.state NOT IN (:excludedStates)');
111+
$qb->setParameter('excludedStates', [
112+
MollieSubscriptionInterface::STATE_PAUSED,
113+
MollieSubscriptionInterface::STATE_PROCESSING,
114+
]);
109115
$qb->setMaxResults($batchSize);
110116

111117
return $qb->getQuery()->toIterable();

0 commit comments

Comments
 (0)