feat: add Import entity with batch tracking
This commit is contained in:
36
migrations/Version20260329000002.php
Normal file
36
migrations/Version20260329000002.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20260329000002 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('CREATE TABLE import (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, user_id INT NOT NULL, file_path VARCHAR(255) NOT NULL, status VARCHAR(20) NOT NULL, total_batches INT NOT NULL, processed_batches INT NOT NULL, total_films INT NOT NULL, failed_films INT NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, completed_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY (id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_9D4ECE1DA76ED395 ON import (user_id)');
|
||||||
|
$this->addSql('COMMENT ON COLUMN import.created_at IS \'(DC2Type:datetime_immutable)\'');
|
||||||
|
$this->addSql('COMMENT ON COLUMN import.completed_at IS \'(DC2Type:datetime_immutable)\'');
|
||||||
|
$this->addSql('ALTER TABLE import ADD CONSTRAINT FK_9D4ECE1DA76ED395 FOREIGN KEY (user_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE import DROP CONSTRAINT FK_9D4ECE1DA76ED395');
|
||||||
|
$this->addSql('DROP TABLE import');
|
||||||
|
}
|
||||||
|
}
|
||||||
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