feat: add Import entity with batch tracking
This commit is contained in:
153
src/Entity/Import.php
Normal file
153
src/Entity/Import.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\ImportRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: ImportRepository::class)]
|
||||
class Import
|
||||
{
|
||||
public const string STATUS_PENDING = 'pending';
|
||||
public const string STATUS_PROCESSING = 'processing';
|
||||
public const string STATUS_COMPLETED = 'completed';
|
||||
public const string STATUS_FAILED = 'failed';
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: User::class)]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?User $user = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $filePath = null;
|
||||
|
||||
#[ORM\Column(length: 20)]
|
||||
private string $status = self::STATUS_PENDING;
|
||||
|
||||
#[ORM\Column]
|
||||
private int $totalBatches = 0;
|
||||
|
||||
#[ORM\Column]
|
||||
private int $processedBatches = 0;
|
||||
|
||||
#[ORM\Column]
|
||||
private int $totalFilms = 0;
|
||||
|
||||
#[ORM\Column]
|
||||
private int $failedFilms = 0;
|
||||
|
||||
#[ORM\Column]
|
||||
private \DateTimeImmutable $createdAt;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?\DateTimeImmutable $completedAt = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function setUser(?User $user): static
|
||||
{
|
||||
$this->user = $user;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFilePath(): ?string
|
||||
{
|
||||
return $this->filePath;
|
||||
}
|
||||
|
||||
public function setFilePath(string $filePath): static
|
||||
{
|
||||
$this->filePath = $filePath;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStatus(): string
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function setStatus(string $status): static
|
||||
{
|
||||
$this->status = $status;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTotalBatches(): int
|
||||
{
|
||||
return $this->totalBatches;
|
||||
}
|
||||
|
||||
public function setTotalBatches(int $totalBatches): static
|
||||
{
|
||||
$this->totalBatches = $totalBatches;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getProcessedBatches(): int
|
||||
{
|
||||
return $this->processedBatches;
|
||||
}
|
||||
|
||||
public function setProcessedBatches(int $processedBatches): static
|
||||
{
|
||||
$this->processedBatches = $processedBatches;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTotalFilms(): int
|
||||
{
|
||||
return $this->totalFilms;
|
||||
}
|
||||
|
||||
public function setTotalFilms(int $totalFilms): static
|
||||
{
|
||||
$this->totalFilms = $totalFilms;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFailedFilms(): int
|
||||
{
|
||||
return $this->failedFilms;
|
||||
}
|
||||
|
||||
public function setFailedFilms(int $failedFilms): static
|
||||
{
|
||||
$this->failedFilms = $failedFilms;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): \DateTimeImmutable
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
public function getCompletedAt(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->completedAt;
|
||||
}
|
||||
|
||||
public function setCompletedAt(?\DateTimeImmutable $completedAt): static
|
||||
{
|
||||
$this->completedAt = $completedAt;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
41
src/Repository/ImportRepository.php
Normal file
41
src/Repository/ImportRepository.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?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
|
||||
{
|
||||
$this->getEntityManager()->getConnection()->executeStatement(
|
||||
'UPDATE import SET processed_batches = processed_batches + 1 WHERE id = :id',
|
||||
['id' => $import->getId()]
|
||||
);
|
||||
|
||||
return (int) $this->getEntityManager()->getConnection()->fetchOne(
|
||||
'SELECT processed_batches FROM import WHERE id = :id',
|
||||
['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()]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user