/** * Execute the job. * * @param FileManager $fileRepository * @param CacheManager $cacheManager * * @throws Exception */ public function handle(FileManager $fileRepository, CacheManager $cacheManager) { $this->logger = $this->getJobLogger(); $this->logger->debug("Optimizing file {$this->imageFile->getId()} {$this->imageFile->getPath()} attempt {$this->attempts()}", $this->imageFile->toArray()); // Get a fresh copy from the DB (checks if it's deleted) if (!($this->imageFile = $this->imageFile->fresh())) { throw new Exception("ImageFile no longer exists."); } $this->optimize(); $fileRepository->copyToRemote($this->imageFile); $cacheManager->purge($this->imageFile->getPath()); }