/** * Publishes the whole collection to this target * * @param CollectionInterface $collection The collection to publish * @param callable $callback Function called after each resource publishing * @return void */ public function publishCollection(CollectionInterface $collection, callable $callback = null) { $storage = $collection->getStorage(); if ($storage instanceof PackageStorage) { foreach ($storage->getPublicResourcePaths() as $packageKey => $path) { $this->publishDirectory($path, $packageKey); } } else { parent::publishCollection($collection, $callback); } }
/** * 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) { $sourceStream = $resource->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.', $resource->getFilename(), $resource->getSha1(), $collection->getName()), 1375258146); } $this->publishFile($sourceStream, $this->getRelativePublicationPathAndFilename($resource)); fclose($sourceStream); }
/** * Retrieve all Objects stored in this storage, filtered by the given collection name * * @param callable $callback Function called after each iteration * @param CollectionInterface $collection * @return \Generator<Object> */ public function getObjectsByCollection(CollectionInterface $collection, callable $callback = null) { $iterator = $this->resourceRepository->findByCollectionNameIterator($collection->getName()); $iteration = 0; foreach ($this->resourceRepository->iterate($iterator, $callback) as $resource) { /** @var PersistentResource $resource */ $object = new Object(); $object->setFilename($resource->getFilename()); $object->setSha1($resource->getSha1()); $object->setMd5($resource->getMd5()); $object->setFileSize($resource->getFileSize()); $object->setStream(function () use($resource) { return $this->getStreamByResource($resource); }); (yield $object); if (is_callable($callback)) { call_user_func($callback, $iteration, $object); } $iteration++; } }
/** * 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); } }
/** * Handle missing data notification * * @param CollectionInterface $collection * @param ResourceMetaDataInterface $resource */ protected function handleMissingData(ResourceMetaDataInterface $resource, CollectionInterface $collection) { $message = sprintf('Could not publish resource %s with SHA1 hash %s of collection %s because there seems to be no corresponding data in the storage.', $resource->getFilename(), $resource->getSha1(), $collection->getName()); $this->messageCollector->append($message); }
/** * Retrieve all Objects stored in this storage, filtered by the given collection name * * @param CollectionInterface $collection * @internal param string $collectionName * @return array<\TYPO3\Flow\Resource\Storage\Object> * @api */ public function getObjectsByCollection(CollectionInterface $collection) { $objects = array(); $that = $this; $bucketName = $this->bucketName; foreach ($this->resourceRepository->findByCollectionName($collection->getName()) as $resource) { /** @var \TYPO3\Flow\Resource\Resource $resource */ $object = new Object(); $object->setFilename($resource->getFilename()); $object->setSha1($resource->getSha1()); $object->setStream(function () use($that, $bucketName, $resource) { return fopen('s3://' . $bucketName . '/' . $this->keyPrefix . $resource->getSha1(), 'r'); }); $objects[] = $object; } return $objects; }
/** * 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 && $storage->getKeyPrefix() === $this->keyPrefix) { 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, with identical key prefixes. Either choose a different bucket or at least key prefix for the target.', $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 = $resource->getStream(); 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); } }
/** * Retrieve all Objects stored in this storage, filtered by the given collection name * * @param CollectionInterface $collection * @return array<\TYPO3\Flow\Resource\Storage\Object> */ public function getObjectsByCollection(CollectionInterface $collection) { $objects = array(); $that = $this; foreach ($this->resourceRepository->findByCollectionName($collection->getName()) as $resource) { /** @var \TYPO3\Flow\Resource\Resource $resource */ $object = new Object(); $object->setFilename($resource->getFilename()); $object->setSha1($resource->getSha1()); $object->setMd5($resource->getMd5()); $object->setFileSize($resource->getFileSize()); $object->setStream(function () use($that, $resource) { return $that->getStreamByResource($resource); }); $objects[] = $object; } return $objects; }
/** * Retrieve all Objects stored in this storage, filtered by the given collection name * * @param CollectionInterface $collection * @internal param string $collectionName * @return array<\TYPO3\Flow\Resource\Storage\Object> * @api */ public function getObjectsByCollection(CollectionInterface $collection) { if ($this->debug) { $this->systemLogger->log('storage ' . $this->name . ': getObjectsByCollection, $collection->getName(): ' . $collection->getName()); } $objects = array(); $that = $this; $containerName = $this->containerName; foreach ($this->resourceRepository->findByCollectionName($collection->getName()) as $resource) { /** @var \TYPO3\Flow\Resource\Resource $resource */ if ($this->debug) { $this->systemLogger->log('storage ' . $this->name . ': - getObjectsByCollection $resource->getFilename(): ' . $resource->getFilename()); } $object = new Object(); $object->setFilename($resource->getFilename()); $object->setSha1($resource->getSha1()); $object->setStream(function () use($that, $containerName, $resource) { return 'http://' . $this->zoneDomain . '/_' . $resource->getSha1(); }); $objects[] = $object; } return $objects; }