Remove the notification system entirely and show import progress directly in the user dropdown menu. Block new imports while one is already running. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
60 lines
1.8 KiB
PHP
60 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\Import;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<Import>
|
|
*/
|
|
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;
|
|
}
|
|
}
|