From 1281e1ddc869b3aad85e7b9d0598405aa459816a Mon Sep 17 00:00:00 2001 From: TomasHermanek Date: Mon, 2 Dec 2024 17:06:39 +0100 Subject: [PATCH] =?UTF-8?q?Added=20optimize=20author=20validation,=20handl?= =?UTF-8?q?e=20not=20found=20author=20in=20job=20proc=E2=80=A6=20(#97)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added optimize author validation handle not found author in job processor correctly --- .../Job/Processor/JobAuthorCurrentOptimizeProcessor.php | 7 ++++++- src/Entity/JobAuthorCurrentOptimize.php | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Domain/Job/Processor/JobAuthorCurrentOptimizeProcessor.php b/src/Domain/Job/Processor/JobAuthorCurrentOptimizeProcessor.php index bada1e3..bea2d33 100644 --- a/src/Domain/Job/Processor/JobAuthorCurrentOptimizeProcessor.php +++ b/src/Domain/Job/Processor/JobAuthorCurrentOptimizeProcessor.php @@ -73,8 +73,13 @@ private function processAll(JobAuthorCurrentOptimize $job): void private function processAuthor(JobAuthorCurrentOptimize $job): void { - /** @var Author $author */ + /** @var Author|null $author */ $author = $this->authorRepository->find($job->getAuthorId()); + if (null === $author) { + $this->finishFail($job, 'Author not found'); + + return; + } $lastId = $job->getLastBatchProcessedRecord(); $assets = $this->assetRepository->findByAuthor($author, $lastId, $this->bulkSize); diff --git a/src/Entity/JobAuthorCurrentOptimize.php b/src/Entity/JobAuthorCurrentOptimize.php index a63877a..48713eb 100644 --- a/src/Entity/JobAuthorCurrentOptimize.php +++ b/src/Entity/JobAuthorCurrentOptimize.php @@ -9,6 +9,7 @@ use AnzuSystems\SerializerBundle\Attributes\Serialize; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints as Assert; #[ORM\Entity(repositoryClass: JobAuthorCurrentOptimizeRepository::class)] class JobAuthorCurrentOptimize extends Job @@ -19,6 +20,12 @@ class JobAuthorCurrentOptimize extends Job #[ORM\Column(type: Types::STRING, length: 36, nullable: true)] #[Serialize] + #[Assert\When( + expression: 'false === this.isProcessAll()', + constraints: [ + new Assert\NotNull(), + ] + )] private ?string $authorId = null; public function isProcessAll(): bool