*/ class ImportRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) { parent::__construct($registry, Import::class); } public function incrementProcessedBatches(Import $import): int { return (int) $this->getEntityManager()->getConnection()->fetchOne( 'UPDATE import SET processed_batches = processed_batches + 1 WHERE id = :id RETURNING processed_batches', ['id' => $import->getId()] ); } public function incrementFailedFilms(Import $import): void { $this->getEntityManager()->getConnection()->executeStatement( 'UPDATE import SET failed_films = failed_films + 1 WHERE id = :id', ['id' => $import->getId()] ); } public function findLatestForUser(\App\Entity\User $user): ?Import { return $this->createQueryBuilder('i') ->andWhere('i.user = :user') ->setParameter('user', $user) ->orderBy('i.createdAt', 'DESC') ->setMaxResults(1) ->getQuery() ->getOneOrNullResult(); } public function hasActiveImport(\App\Entity\User $user): bool { return (int) $this->createQueryBuilder('i') ->select('COUNT(i.id)') ->andWhere('i.user = :user') ->andWhere('i.status IN (:statuses)') ->setParameter('user', $user) ->setParameter('statuses', [Import::STATUS_PENDING, Import::STATUS_PROCESSING]) ->getQuery() ->getSingleScalarResult() > 0; } }