Пример #1
0
 /**
  * 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());
 }
Пример #2
0
 public function testNginxCachePurge()
 {
     $image = $this->getImage();
     $filename = 'tests/' . $this->fileRepository->savePicture($image, 'tests');
     $path = $this->dataDir . $filename;
     $s3Url = $this->s3Url . $filename;
     $cloudflareUrl = $this->cloudflareDataUrl . $filename;
     $directUrl = $this->directDataUrl . $filename;
     // Test that it is first served by nginx from the local filesystem
     $headers = $this->getHttpHeaders($directUrl);
     $this->assertNotContains('x-amz-request-id', $headers);
     $this->assertNotContains('X-Cache-Status', $headers);
     // Delete from local filesystem
     unlink($path);
     // Test that it is served from AWS via Nginx
     $headers = $this->getHttpHeaders($directUrl);
     $this->assertContains('x-amz-request-id', $headers);
     $this->assertContains('X-Cache-Status: MISS', $headers);
     sleep(1);
     // Test that it is cached by Nginx now
     $headers = $this->getHttpHeaders($directUrl);
     $this->assertContains('x-amz-request-id', $headers);
     $this->assertContains('X-Cache-Status: HIT', $headers);
     // Delete from remote
     $this->fileRepository->deleteRemoteFile($filename);
     $this->assertNotEquals(200, $this->getHttpResponseCode($s3Url), $s3Url);
     // Test that it is still cached by Nginx
     $headers = $this->getHttpHeaders($directUrl);
     $this->assertContains('HTTP/1.1 200', $headers);
     $this->assertContains('X-Cache-Status: HIT', $headers);
     // Purge nginx cache
     $this->assertEquals(true, $this->cacheManager->purgeNginx($directUrl));
     // Test it's no longer being served
     $this->assertNotEquals(200, $this->getHttpResponseCode($directUrl), $directUrl);
     $this->fileRepository->deleteFile($filename);
 }
Пример #3
0
 /**
  * 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);
 }