/**
  * Publishes the whole collection to this target
  *
  * @param \TYPO3\Flow\Resource\Collection $collection The collection to publish
  * @return void
  * @throws Exception
  */
 public function publishCollection(Collection $collection)
 {
     if ($this->debug) {
         $this->systemLogger->log('target ' . $this->name . ': publishCollection');
     }
     if (!isset($this->existingObjectsInfo)) {
         $this->existingObjectsInfo = array();
     }
     $obsoleteObjects = array_fill_keys(array_keys($this->existingObjectsInfo), TRUE);
     $storage = $collection->getStorage();
     if ($storage instanceof KeyCDNStorage) {
         if ($this->debug) {
             $this->systemLogger->log('target ' . $this->name . ': - publishCollection instanceof: KeyCDNStorage');
         }
         $storageContainerName = $storage->getContainerName();
         if ($storageContainerName === $this->containerName) {
             throw new Exception(sprintf('Could not publish collection %s because the source and target container is the same.', $collection->getName()), 1375348241);
         }
         foreach ($collection->getObjects() as $object) {
             /** @var \TYPO3\Flow\Resource\Storage\Object $object */
             $temporaryTargetPathAndFilename = $this->environment->getPathToTemporaryDirectory() . uniqid('TYPO3_Flow_ResourceImport_');
             $this->downloadFile($temporaryTargetPathAndFilename, '_' . $object->getSha1());
             $this->uploadFile($temporaryTargetPathAndFilename, $this->getRelativePublicationPathAndFilename($object));
             unset($obsoleteObjects[$this->getRelativePublicationPathAndFilename($object)]);
         }
     } else {
         if ($this->debug) {
             $this->systemLogger->log('target ' . $this->name . ': - publishCollection');
         }
         foreach ($collection->getObjects() as $object) {
             /** @var \TYPO3\Flow\Resource\Storage\Object $object */
             $this->publishFile($object->getStream(), $this->getRelativePublicationPathAndFilename($object), $object);
             unset($obsoleteObjects[$this->getRelativePublicationPathAndFilename($object)]);
         }
     }
     foreach (array_keys($obsoleteObjects) as $relativePathAndFilename) {
         $this->deleteFile($relativePathAndFilename);
     }
 }
예제 #2
0
 /**
  * Publishes the whole collection to this target
  *
  * @param \TYPO3\Flow\Resource\Collection $collection The collection to publish
  * @return void
  * @throws Exception
  */
 public function publishCollection(Collection $collection)
 {
     foreach ($collection->getObjects() as $object) {
         /** @var \TYPO3\Flow\Resource\Storage\Object $object */
         $sourceStream = $object->getStream();
         if ($sourceStream === FALSE) {
             throw new Exception(sprintf('Could not publish resource %s with SHA1 hash %s of collection %s because there seems to be no corresponding data in the storage.', $object->getFilename(), $object->getSha1(), $collection->getName()), 1417168142);
         }
         $this->publishFile($sourceStream, $this->getRelativePublicationPathAndFilename($object));
         fclose($sourceStream);
     }
 }
예제 #3
0
 /**
  * Publishes the whole collection to this target
  *
  * @param \TYPO3\Flow\Resource\Collection $collection The collection to publish
  * @return void
  * @throws Exception
  */
 public function publishCollection(Collection $collection)
 {
     if (!isset($this->existingObjectsInfo)) {
         $this->existingObjectsInfo = array();
         $requestArguments = array('Bucket' => $this->bucketName, 'Delimiter' => '/', 'Prefix' => $this->keyPrefix);
         do {
             $result = $this->s3Client->listObjects($requestArguments);
             $this->existingObjectsInfo[] = $result->get('Contents');
             if ($result->get('IsTruncated')) {
                 $requestArguments['marker'] = $result->get('NextMarker');
             }
         } while ($result->get('IsTruncated'));
     }
     $obsoleteObjects = array_fill_keys(array_keys($this->existingObjectsInfo), true);
     $storage = $collection->getStorage();
     if ($storage instanceof S3Storage) {
         $storageBucketName = $storage->getBucketName();
         if ($storageBucketName === $this->bucketName && $storage->getKeyPrefix() === $this->keyPrefix) {
             throw new Exception(sprintf('Could not publish collection %s because the source and target S3 bucket is the same, with identical key prefixes. Either choose a different bucket or at least key prefix for the target.', $collection->getName()), 1428929137);
         }
         foreach ($collection->getObjects() as $object) {
             /** @var \TYPO3\Flow\Resource\Storage\Object $object */
             $objectName = $this->keyPrefix . $this->getRelativePublicationPathAndFilename($object);
             $options = array('ACL' => 'public-read', 'Bucket' => $this->bucketName, 'CopySource' => urlencode($storageBucketName . '/' . $storage->getKeyPrefix() . $object->getSha1()), 'ContentType' => $object->getMediaType(), 'MetadataDirective' => 'REPLACE', 'Key' => $objectName);
             try {
                 $this->s3Client->copyObject($options);
             } catch (S3Exception $e) {
                 throw new Exception(sprintf('Could not copy resource with SHA1 hash %s of collection %s from bucket %s to %s: %s', $object->getSha1(), $collection->getName(), $storageBucketName, $this->bucketName, $e->getMessage()), 1431009234);
             }
             $this->systemLogger->log(sprintf('Successfully copied resource as object "%s" (MD5: %s) from bucket "%s" to bucket "%s"', $objectName, $object->getMd5() ?: 'unknown', $storageBucketName, $this->bucketName), LOG_DEBUG);
             unset($obsoleteObjects[$this->getRelativePublicationPathAndFilename($object)]);
         }
     } else {
         foreach ($collection->getObjects() as $object) {
             /** @var \TYPO3\Flow\Resource\Storage\Object $object */
             $this->publishFile($object->getStream(), $this->getRelativePublicationPathAndFilename($object), $object);
             unset($obsoleteObjects[$this->getRelativePublicationPathAndFilename($object)]);
         }
     }
     foreach (array_keys($obsoleteObjects) as $relativePathAndFilename) {
         $this->s3Client->deleteObject(array('Bucket' => $this->bucketName, 'Key' => $this->keyPrefix . $relativePathAndFilename));
     }
 }