From 7be4de696729b3ed43ef5a9f96233bdade55cf49 Mon Sep 17 00:00:00 2001 From: thibaud-leclere Date: Sun, 29 Mar 2026 10:11:30 +0200 Subject: [PATCH] feat: add Import entity with batch tracking --- migrations/Version20260329000002.php | 36 +++++++ src/Entity/Import.php | 153 +++++++++++++++++++++++++++ src/Repository/ImportRepository.php | 41 +++++++ 3 files changed, 230 insertions(+) create mode 100644 migrations/Version20260329000002.php create mode 100644 src/Entity/Import.php create mode 100644 src/Repository/ImportRepository.php diff --git a/migrations/Version20260329000002.php b/migrations/Version20260329000002.php new file mode 100644 index 0000000..1247da6 --- /dev/null +++ b/migrations/Version20260329000002.php @@ -0,0 +1,36 @@ +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'); + } +} diff --git a/src/Entity/Import.php b/src/Entity/Import.php new file mode 100644 index 0000000..2e6c88b --- /dev/null +++ b/src/Entity/Import.php @@ -0,0 +1,153 @@ +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; + } +} diff --git a/src/Repository/ImportRepository.php b/src/Repository/ImportRepository.php new file mode 100644 index 0000000..d154f27 --- /dev/null +++ b/src/Repository/ImportRepository.php @@ -0,0 +1,41 @@ + + */ +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()] + ); + } +}