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