feat: delete orphaned future snapshots after xml sync

This commit is contained in:
Björn Fromme
2026-03-25 15:35:12 +01:00
parent facd91375c
commit bca3610cff
4 changed files with 84 additions and 0 deletions
@@ -126,4 +126,31 @@ class TravelSnapshotRepository extends ServiceEntityRepository
->getQuery()
->execute();
}
/**
* Deletes future snapshots whose dateId is no longer present in the XML export.
*
* Only snapshots with dateFrom > today are removed; in-progress and past travels
* are intentionally left intact so the extended-availability fallback can still serve them.
*
* @param array<int> $activeXmlDateIds dateIds currently present in the XML file map
*/
public function deleteOrphanedFutureSnapshots(array $activeXmlDateIds, \DateTimeImmutable $today): int
{
// An empty list means the XML export is unavailable or empty — refuse to purge
// anything rather than deleting all future snapshots due to NOT IN ([]) = 1=1.
if ([] === $activeXmlDateIds) {
return 0;
}
return (int) $this->createQueryBuilder('s')
->delete()
->where('s.dateFrom IS NOT NULL')
->andWhere('s.dateFrom > :today')
->andWhere('s.dateId NOT IN (:activeXmlDateIds)')
->setParameter('today', $today)
->setParameter('activeXmlDateIds', $activeXmlDateIds)
->getQuery()
->execute();
}
}