/** * 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()); }
/** * Called by MoveRemoteFileJob * * @param string $oldPath * @param string $newPath */ public function moveRemoteFile($oldPath, $newPath) { $s3Client = $this->getS3Client(); if ($s3Client->copyObject(['ACL' => $this->s3Access, 'Bucket' => $this->s3BucketName, 'CopySource' => "{$this->s3BucketName}/{$oldPath}", 'Expires' => $this->s3ExpiresHeader, 'Key' => $newPath])) { $result['remote'] = true; $s3Client->deleteMatchingObjects($this->s3BucketName, $oldPath); } $cacheManager = new CacheManager(); $cacheManager->purge($oldPath); $cacheManager->purge($newPath); }