コード例 #1
0
 /**
  * Publishes the given persistent resource from the given storage
  *
  * @param \TYPO3\Flow\Resource\Resource $resource The resource to publish
  * @param CollectionInterface $collection The collection the given resource belongs to
  * @return void
  * @throws Exception
  */
 public function publishResource(Resource $resource, CollectionInterface $collection)
 {
     if ($this->debug) {
         $this->systemLogger->log('target ' . $this->name . ': publishResource');
     }
     $storage = $collection->getStorage();
     if ($storage instanceof KeyCDNStorage) {
         if ($storage->getContainerName() === $this->containerName) {
             throw new Exception(sprintf('Could not publish resource with SHA1 hash %s of collection %s because the source and target container is the same.', $resource->getSha1(), $collection->getName()), 1375348223);
         }
         $temporaryTargetPathAndFilename = $this->environment->getPathToTemporaryDirectory() . uniqid('TYPO3_Flow_ResourceImport_');
         $this->downloadFile($temporaryTargetPathAndFilename, '_' . $resource->getSha1());
         $this->uploadFile($temporaryTargetPathAndFilename, $this->getRelativePublicationPathAndFilename($resource));
     } else {
         $sourceStream = $collection->getStreamByResource($resource);
         if ($sourceStream === FALSE) {
             throw new Exception(sprintf('Could not publish resource with SHA1 hash %s of collection %s because there seems to be no corresponding data in the storage.', $resource->getSha1(), $collection->getName()), 1375342304);
         }
         $this->publishFile($sourceStream, $this->getRelativePublicationPathAndFilename($resource), $resource);
     }
 }
コード例 #2
0
ファイル: S3Target.php プロジェクト: revsbech/flow-aws-s3
 /**
  * Publishes the given persistent resource from the given storage
  *
  * @param \TYPO3\Flow\Resource\Resource $resource The resource to publish
  * @param CollectionInterface $collection The collection the given resource belongs to
  * @return void
  * @throws Exception
  */
 public function publishResource(Resource $resource, CollectionInterface $collection)
 {
     $storage = $collection->getStorage();
     if ($storage instanceof S3Storage) {
         if ($storage->getBucketName() === $this->bucketName) {
             throw new Exception(sprintf('Could not publish resource with SHA1 hash %s of collection %s because the source and target S3 bucket is the same.', $resource->getSha1(), $collection->getName()), 1428929563);
         }
         try {
             $sourceObjectArn = $storage->getBucketName() . '/' . $storage->getKeyPrefix() . $resource->getSha1();
             $objectName = $this->keyPrefix . $this->getRelativePublicationPathAndFilename($resource);
             $options = array('ACL' => 'public-read', 'Bucket' => $this->bucketName, 'CopySource' => urlencode($sourceObjectArn), 'ContentType' => $resource->getMediaType(), 'MetadataDirective' => 'REPLACE', 'Key' => $objectName);
             $this->s3Client->copyObject($options);
             $this->systemLogger->log(sprintf('Successfully published resource as object "%s" (MD5: %s) by copying from bucket "%s" to bucket "%s"', $objectName, $resource->getMd5() ?: 'unknown', $storage->getBucketName(), $this->bucketName), LOG_DEBUG);
         } catch (S3Exception $e) {
             throw new Exception(sprintf('Could not publish resource with SHA1 hash %s of collection %s (source object: %s) through "CopyObject" because the S3 client reported an error: %s', $resource->getSha1(), $collection->getName(), $sourceObjectArn, $e->getMessage()), 1428999574);
         }
     } else {
         $sourceStream = $collection->getStreamByResource($resource);
         if ($sourceStream === FALSE) {
             throw new Exception(sprintf('Could not publish resource with SHA1 hash %s of collection %s because there seems to be no corresponding data in the storage.', $resource->getSha1(), $collection->getName()), 1428929649);
         }
         $this->publishFile($sourceStream, $this->getRelativePublicationPathAndFilename($resource), $resource);
     }
 }