Example #1
9
 /**
  * Imports the given temporary file into the storage and creates the new resource object.
  *
  * @param string $temporaryPathAndFilename Path and filename leading to the temporary file
  * @param string $collectionName Name of the collection to import into
  * @return Resource The imported resource
  */
 protected function importTemporaryFile($temporaryPathAndFilename, $collectionName)
 {
     $sha1Hash = sha1_file($temporaryPathAndFilename);
     $md5Hash = md5_file($temporaryPathAndFilename);
     $resource = new Resource();
     $resource->setFileSize(filesize($temporaryPathAndFilename));
     $resource->setCollectionName($collectionName);
     $resource->setSha1($sha1Hash);
     $resource->setMd5($md5Hash);
     $objectName = $this->keyPrefix . $sha1Hash;
     $options = array('Bucket' => $this->bucketName, 'Body' => fopen($temporaryPathAndFilename, 'rb'), 'ContentLength' => $resource->getFileSize(), 'ContentType' => $resource->getMediaType(), 'Key' => $objectName);
     if (!$this->s3Client->doesObjectExist($this->bucketName, $this->keyPrefix . $sha1Hash)) {
         $this->s3Client->putObject($options);
         $this->systemLogger->log(sprintf('Successfully imported resource as object "%s" into bucket "%s" with MD5 hash "%s"', $objectName, $this->bucketName, $resource->getMd5() ?: 'unknown'), LOG_INFO);
     } else {
         $this->systemLogger->log(sprintf('Did not import resource as object "%s" into bucket "%s" because that object already existed.', $objectName, $this->bucketName), LOG_INFO);
     }
     return $resource;
 }
 /**
  * Map the given resource to a media model class.
  *
  * @param Resource $resource
  * @param array $additionalProperties Optional properties that can be taken into account for deciding the model class. what you get here can depend on the caller, so you should always fallback to something based on the resource.
  * @return string
  */
 public function map(Resource $resource, array $additionalProperties = array())
 {
     $mediaType = MediaTypes::getMediaTypeFromFilename($resource->getFilename());
     foreach ($this->settings['patterns'] as $pattern => $mappingInformation) {
         if (preg_match($pattern, $mediaType)) {
             return $mappingInformation['className'];
         }
     }
     return $this->settings['default'];
 }
 /**
  * @test
  */
 public function getMediaTypeReturnsMediaTypeBasedOnFileExtension()
 {
     $resource = new Resource();
     $resource->setFilename('file.jpg');
     $this->assertSame('image/jpeg', $resource->getMediaType());
     $resource = new Resource();
     $resource->setFilename('file.zip');
     $this->assertSame('application/zip', $resource->getMediaType());
     $resource = new Resource();
     $resource->setFilename('file.someunknownextension');
     $this->assertSame('application/octet-stream', $resource->getMediaType());
 }
 /**
  * @param FlowResource $flowResource
  * @return array
  */
 protected function findSuitableExtractorAdaptersForResource(FlowResource $flowResource)
 {
     $extractorAdapters = $this->getExtractorAdapters();
     $mediaType = $flowResource->getMediaType();
     $suitableAdapterClasses = [];
     foreach ($extractorAdapters as $extractorAdapterClass => $compatibleMediaTypes) {
         if (in_array($mediaType, $compatibleMediaTypes)) {
             $suitableAdapterClasses[] = $extractorAdapterClass;
         }
     }
     return $suitableAdapterClasses;
 }
 /**
  * @param FlowResource $resource
  * @param MetaDataCollection $metaDataCollection
  * @throws \TYPO3\Flow\Resource\Exception
  */
 public function extractMetaData(FlowResource $resource, MetaDataCollection $metaDataCollection)
 {
     $manager = new ImageManager(['driver' => 'gd']);
     $image = $manager->make($resource->createTemporaryLocalCopy());
     $iptcData = $image->iptc();
     if (is_array($iptcData)) {
         $metaDataCollection->set('iptc', $this->buildIptcDto($iptcData));
     }
     $exifData = $image->exif();
     if (is_array($exifData)) {
         $metaDataCollection->set('exif', $this->buildExifDto($exifData));
     }
 }
 public function initializeOrUpdate()
 {
     $localCopyForCsvFile = $this->sourceFile->createTemporaryLocalCopy();
     $csvReader = Reader::createFromPath($localCopyForCsvFile);
     $csvReader->setDelimiter(';');
     $csv = $csvReader->fetchAssoc();
     $output = array();
     foreach ($csv as $row) {
         $output[] = json_encode($row);
     }
     Files::createDirectoryRecursively(dirname($this->getSourceFileName()));
     file_put_contents($this->getSourceFileName(), implode("\n", $output));
     parent::initializeOrUpdate();
 }
 /**
  * Render the URI to the resource. The filename is used from child content.
  *
  * @param string $path The location of the resource, can be either a path relative to the Public resource directory of the package or a resource://... URI
  * @param Resource $resource If specified, this resource object is used instead of the path and package information
  * @return string The content of the specified file
  * @throws InvalidVariableException
  */
 public function render($path = null, Resource $resource = null)
 {
     $data = '';
     if ($resource !== null) {
         $dataStream = $resource->getStream();
         if ($dataStream) {
             $data = $dataStream->read($dataStream->getSize());
         }
     } else {
         if ($path === null) {
             throw new InvalidVariableException('The ResourceViewHelper did neither contain a valuable "resource" nor "path" argument.', 1457673112);
         }
         $data = file_get_contents($path);
     }
     return $data;
 }
Example #8
0
 /**
  * The given $value is valid if it is an \TYPO3\Flow\Resource\Resource of the configured resolution
  * Note: a value of NULL or empty string ('') is considered valid
  *
  * @param \TYPO3\Flow\Resource\Resource $resource The resource object that should be validated
  * @return void
  * @api
  */
 protected function isValid($resource)
 {
     if (!$resource instanceof \TYPO3\Flow\Resource\Resource) {
         $this->addError('The given value was not a Resource instance.', 1327865587);
         return;
     }
     $fileExtension = $resource->getFileExtension();
     if ($fileExtension === null || $fileExtension === '') {
         $this->addError('The file has no file extension.', 1327865808);
         return;
     }
     if (!in_array($fileExtension, $this->options['allowedExtensions'])) {
         $this->addError('The file extension "%s" is not allowed.', 1327865764, array($resource->getFileExtension()));
         return;
     }
 }
 /**
  * Converts the given string or array to a ResourcePointer object.
  *
  * If the input format is an array, this method assumes the resource to be a
  * fresh file upload and imports the temporary upload file through the
  * resource manager.
  *
  * @param array $source The upload info (expected keys: error, name, tmp_name)
  * @param string $targetType
  * @param array $convertedChildProperties
  * @param \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration
  * @return \TYPO3\Flow\Resource\Resource|TYPO3\Flow\Error\Error if the input format is not supported or could not be converted for other reasons
  */
 public function convertFrom($source, $targetType, array $convertedChildProperties = array(), \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration = NULL)
 {
     if (!isset($source['error']) || $source['error'] === \UPLOAD_ERR_NO_FILE) {
         if (isset($source['submittedFile']) && isset($source['submittedFile']['filename']) && isset($source['submittedFile']['resourcePointer'])) {
             $resourcePointer = $this->persistenceManager->getObjectByIdentifier($source['submittedFile']['resourcePointer'], 'TYPO3\\Flow\\Resource\\ResourcePointer');
             if ($resourcePointer) {
                 $resource = new Resource();
                 $resource->setFilename($source['submittedFile']['filename']);
                 $resource->setResourcePointer($resourcePointer);
                 return $resource;
             }
         }
         return NULL;
     }
     if ($source['error'] !== \UPLOAD_ERR_OK) {
         switch ($source['error']) {
             case \UPLOAD_ERR_INI_SIZE:
             case \UPLOAD_ERR_FORM_SIZE:
             case \UPLOAD_ERR_PARTIAL:
                 return new \TYPO3\Flow\Error\Error(\TYPO3\Flow\Utility\Files::getUploadErrorMessage($source['error']), 1264440823);
             default:
                 $this->systemLogger->log(sprintf('A server error occurred while converting an uploaded resource: "%s"', \TYPO3\Flow\Utility\Files::getUploadErrorMessage($source['error'])), LOG_ERR);
                 return new \TYPO3\Flow\Error\Error('An error occurred while uploading. Please try again or contact the administrator if the problem remains', 1340193849);
         }
     }
     if (isset($this->convertedResources[$source['tmp_name']])) {
         return $this->convertedResources[$source['tmp_name']];
     }
     $resource = $this->resourceManager->importUploadedResource($source);
     if ($resource === FALSE) {
         return new \TYPO3\Flow\Error\Error('The resource manager could not create a Resource instance.', 1264517906);
     } else {
         $this->convertedResources[$source['tmp_name']] = $resource;
         return $resource;
     }
 }
Example #10
0
 /**
  * Calculates image width, height and type from the image resource
  * The getimagesize() method may either return FALSE; or throw a Warning
  * which is translated to a \TYPO3\Flow\Error\Exception by Flow. In both
  * cases \TYPO3\Media\Exception\ImageFileException should be thrown.
  *
  * @throws \TYPO3\Media\Exception\ImageFileException
  * @return void
  */
 protected function initialize()
 {
     try {
         $imageSize = getimagesize('resource://' . $this->originalResource->getResourcePointer()->getHash());
         if ($imageSize === FALSE) {
             throw new \TYPO3\Flow\Exception('The given resource was not a valid image file', 1336662898);
         }
         $this->width = (int) $imageSize[0];
         $this->height = (int) $imageSize[1];
         $this->type = (int) $imageSize[2];
     } catch (\TYPO3\Flow\Exception $exception) {
         throw $exception;
     } catch (\TYPO3\Flow\Exception $exception) {
         $exceptionMessage = 'An error with code "' . $exception->getCode() . '" occured when trying to read the image: "' . $exception->getMessage() . '"';
         throw new \TYPO3\Flow\Exception($exceptionMessage, 1336663970);
     }
 }
 /**
  * Returns the IANA media type of this asset
  *
  * @return string
  */
 public function getMediaType()
 {
     return $this->resource->getMediaType();
 }
 /**
  * {@inheritDoc}
  */
 public function shutdownObject()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'shutdownObject', array());
     return parent::shutdownObject();
 }
 /**
  * Returns the web accessible URI pointing to the specified persistent resource
  *
  * @param Resource $resource Resource object
  * @return string The URI
  * @throws Exception
  */
 public function getPublicPersistentResourceUri(Resource $resource)
 {
     $resourceData = array('resourceIdentifier' => $resource->getSha1());
     if ($this->shouldIncludeSecurityContext()) {
         $resourceData['securityContextHash'] = $this->securityContext->getContextHash();
     } elseif (!empty($this->options['tokenLifetime'])) {
         $expirationDateTime = clone $this->now;
         $expirationDateTime = $expirationDateTime->modify(sprintf('+%d seconds', $this->options['tokenLifetime']));
         $resourceData['expirationDateTime'] = $expirationDateTime->format(\DateTime::ISO8601);
     }
     $encodedResourceData = base64_encode(json_encode($resourceData));
     $signedResourceData = $this->hashService->appendHmac($encodedResourceData);
     return $this->detectResourcesBaseUri() . '?__protectedResource=' . $signedResourceData;
 }
 /**
  * Get the size of a Flow Resource object that contains an image file.
  *
  * @param FlowResource $resource
  * @return array width and height as keys
  * @throws ImageFileException
  */
 public function getImageSize(FlowResource $resource)
 {
     $cacheIdentifier = $resource->getCacheEntryIdentifier();
     $imageSize = $this->imageSizeCache->get($cacheIdentifier);
     if ($imageSize !== false) {
         return $imageSize;
     }
     // TODO: Special handling for SVG should be refactored at a later point.
     if ($resource->getMediaType() === 'image/svg+xml') {
         $imageSize = ['width' => null, 'height' => null];
     } else {
         try {
             $imagineImage = $this->imagineService->read($resource->getStream());
             $sizeBox = $imagineImage->getSize();
             $imageSize = array('width' => $sizeBox->getWidth(), 'height' => $sizeBox->getHeight());
         } catch (\Exception $e) {
             throw new ImageFileException(sprintf('The given resource was not an image file your choosen driver can open. The original error was: %s', $e->getMessage()), 1336662898);
         }
     }
     $this->imageSizeCache->set($cacheIdentifier, $imageSize);
     return $imageSize;
 }
 /**
  * Finds other resources which are referring to the same resource data and filename
  *
  * @param Resource $resource The resource used for finding similar resources
  * @return QueryResultInterface The result, including the given resource
  */
 public function findSimilarResources(Resource $resource)
 {
     $query = $this->createQuery();
     $query->matching($query->logicalAnd($query->equals('sha1', $resource->getSha1()), $query->equals('filename', $resource->getFilename())));
     return $query->execute();
 }
 /**
  * Imports the given temporary file into the storage and creates the new resource object.
  *
  * Note: the temporary file is (re-)moved by this method.
  *
  * @param string $temporaryPathAndFileName
  * @param string $collectionName
  * @return PersistentResource
  * @throws StorageException
  */
 protected function importTemporaryFile($temporaryPathAndFileName, $collectionName)
 {
     $this->fixFilePermissions($temporaryPathAndFileName);
     $sha1Hash = sha1_file($temporaryPathAndFileName);
     $targetPathAndFilename = $this->getStoragePathAndFilenameByHash($sha1Hash);
     if (!is_file($targetPathAndFilename)) {
         $this->moveTemporaryFileToFinalDestination($temporaryPathAndFileName, $targetPathAndFilename);
     } else {
         unlink($temporaryPathAndFileName);
     }
     $resource = new PersistentResource();
     $resource->setFileSize(filesize($targetPathAndFilename));
     $resource->setCollectionName($collectionName);
     $resource->setSha1($sha1Hash);
     $resource->setMd5(md5_file($targetPathAndFilename));
     return $resource;
 }
 /**
  * Imports the given temporary file into the storage and creates the new resource object.
  *
  * @param string $temporaryFile
  * @param string $collectionName
  * @return Resource
  * @throws Exception
  */
 protected function importTemporaryFile($temporaryFile, $collectionName)
 {
     $this->fixFilePermissions($temporaryFile);
     $sha1Hash = sha1_file($temporaryFile);
     $finalTargetPathAndFilename = $this->getStoragePathAndFilenameByHash($sha1Hash);
     if (!file_exists(dirname($finalTargetPathAndFilename))) {
         Files::createDirectoryRecursively(dirname($finalTargetPathAndFilename));
     }
     if (rename($temporaryFile, $finalTargetPathAndFilename) === FALSE) {
         unlink($temporaryFile);
         throw new Exception(sprintf('The temporary file of the file import could not be moved to the final target "%s".', $finalTargetPathAndFilename), 1381156103);
     }
     $this->fixFilePermissions($finalTargetPathAndFilename);
     $resource = new Resource();
     $resource->setFileSize(filesize($finalTargetPathAndFilename));
     $resource->setCollectionName($collectionName);
     $resource->setSha1($sha1Hash);
     $resource->setMd5(md5_file($finalTargetPathAndFilename));
     return $resource;
 }
 /**
  * Returns a stream handle which can be used internally to open / copy the given resource
  * stored in this storage.
  *
  * @param PersistentResource $resource The resource stored in this storage
  * @return resource | boolean The resource stream or FALSE if the stream could not be obtained
  */
 public function getStreamByResource(PersistentResource $resource)
 {
     $pathAndFilename = $this->getStoragePathAndFilenameByHash($resource->getSha1());
     return file_exists($pathAndFilename) ? fopen($pathAndFilename, 'rb') : false;
 }
Example #19
0
 /**
  * @ORM\PreFlush
  */
 public function writeUnsubscribeFile()
 {
     if ($this->unsubscribeFile) {
         rename($this->unsubscribeFile->createTemporaryLocalCopy(), $this->getUnsubscribeFileName());
     }
 }
 /**
  * @param array $source
  * @param PropertyMappingConfigurationInterface $configuration
  * @return Resource|Error
  */
 protected function handleHashAndData(array $source, PropertyMappingConfigurationInterface $configuration = NULL)
 {
     $hash = NULL;
     $resource = FALSE;
     $givenResourceIdentity = NULL;
     if (isset($source['__identity'])) {
         $givenResourceIdentity = $source['__identity'];
         unset($source['__identity']);
         $resource = $this->persistenceManager->getObjectByIdentifier($givenResourceIdentity, 'TYPO3\\Flow\\Resource\\Resource');
         if ($resource instanceof \TYPO3\Flow\Resource\Resource) {
             return $resource;
         }
         if ($configuration->getConfigurationValue('TYPO3\\Flow\\Resource\\ResourceTypeConverter', self::CONFIGURATION_IDENTITY_CREATION_ALLOWED) !== TRUE) {
             throw new \TYPO3\Flow\Property\Exception\InvalidPropertyMappingConfigurationException('Creation of resource objects with identity not allowed. To enable this, you need to set the PropertyMappingConfiguration Value "CONFIGURATION_IDENTITY_CREATION_ALLOWED" to TRUE');
         }
     }
     if (isset($source['hash']) && preg_match('/[0-9a-f]{40}/', $source['hash'])) {
         $hash = $source['hash'];
     }
     if ($hash !== NULL) {
         $resourcePointer = $this->persistenceManager->getObjectByIdentifier($hash, 'TYPO3\\Flow\\Resource\\ResourcePointer');
         if ($resourcePointer) {
             $resource = new Resource();
             $resource->setFilename($source['filename']);
             $resource->setResourcePointer($resourcePointer);
         }
     }
     if ($resource === NULL) {
         if (isset($source['data'])) {
             $resource = $this->resourceManager->createResourceFromContent($source['data'], $source['filename']);
         } elseif ($hash !== NULL) {
             $resource = $this->resourceManager->importResource($configuration->getConfigurationValue('TYPO3\\Flow\\Resource\\ResourceTypeConverter', self::CONFIGURATION_RESOURCE_LOAD_PATH) . '/' . $hash);
             if (is_array($source) && isset($source['filename'])) {
                 $resource->setFilename($source['filename']);
             }
         }
     }
     if ($resource instanceof \TYPO3\Flow\Resource\Resource) {
         if ($givenResourceIdentity !== NULL) {
             $this->setIdentity($resource, $givenResourceIdentity);
         }
         return $resource;
     } else {
         return new Error('The resource manager could not create a Resource instance.', 1404312901);
     }
 }
 /**
  * Returns the private path to the source of the given resource.
  *
  * @param \TYPO3\Flow\Resource\Resource $resource
  * @return mixed The full path and filename to the source of the given resource or FALSE if the resource file doesn't exist
  */
 protected function getPersistentResourceSourcePathAndFilename(\TYPO3\Flow\Resource\Resource $resource)
 {
     $pathAndFilename = FLOW_PATH_DATA . 'Persistent/Resources/' . $resource->getResourcePointer()->getHash();
     return file_exists($pathAndFilename) ? $pathAndFilename : FALSE;
 }
Example #22
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)
 {
     $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);
     }
 }
 /**
  * Returns the web accessible URI for the given resource object
  *
  * @param Resource $resource The resource object
  * @return string | boolean A URI as a string or FALSE if the collection of the resource is not found
  * @api
  */
 public function getPublicPersistentResourceUri(Resource $resource)
 {
     if (!isset($this->collections[$resource->getCollectionName()])) {
         return FALSE;
     }
     /** @var TargetInterface $target */
     $target = $this->collections[$resource->getCollectionName()]->getTarget();
     return $target->getPublicPersistentResourceUri($resource);
 }
 /**
  * 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) {
         $this->handleMissingData($resource, $collection);
         return;
     }
     $this->publishFile($sourceStream, $this->getRelativePublicationPathAndFilename($resource));
     fclose($sourceStream);
 }
 /**
  * Update the resource on an asset.
  *
  * @param AssetInterface $asset
  * @param FlowResource $resource
  * @param array $options
  * @throws InvalidArgumentValueException
  * @return void
  */
 public function updateAssetResourceAction(AssetInterface $asset, FlowResource $resource, array $options = [])
 {
     $sourceMediaType = MediaTypes::parseMediaType($asset->getMediaType());
     $replacementMediaType = MediaTypes::parseMediaType($resource->getMediaType());
     // Prevent replacement of image, audio and video by a different mimetype because of possible rendering issues.
     if (in_array($sourceMediaType['type'], ['image', 'audio', 'video']) && $sourceMediaType['type'] !== $replacementMediaType['type']) {
         $this->addFlashMessage('Resources of type "%s" can only be replaced by a similar resource. Got type "%s"', '', Message::SEVERITY_WARNING, [$sourceMediaType['type'], $resource->getMediaType()], 1462308179);
         $this->redirect('index');
     }
     parent::updateAssetResourceAction($asset, $resource, $options);
 }
Example #26
0
 /**
  * @param \TYPO3\Flow\Resource\Resource $photo
  * return void
  */
 public function setPhoto(\TYPO3\Flow\Resource\Resource $photo = null)
 {
     if ($photo && $this->photo && $photo->getResourcePointer() == $this->photo->getResourcePointer()) {
         return;
     }
     $this->photo = $photo;
 }
 /**
  * Returns the publish path and filename to be used to publish the specified persistent resource
  *
  * @param \TYPO3\Flow\Resource\Resource $resource The resource to build the publish path and filename for
  * @param boolean $returnFilename FALSE if only the directory without the filename should be returned
  * @return string The publish path and filename
  */
 protected function buildPersistentResourcePublishPathAndFilename(\TYPO3\Flow\Resource\Resource $resource, $returnFilename)
 {
     $publishPath = $this->resourcesPublishingPath . 'Persistent/';
     if ($returnFilename === TRUE) {
         return $publishPath . $resource->getResourcePointer()->getHash() . '.' . $resource->getFileExtension();
     }
     return $publishPath;
 }
 /**
  * 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);
     }
 }
Example #29
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)
 {
     $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);
 }
 /**
  * Returns a stream handle which can be used internally to open / copy the given resource
  * stored in this storage.
  *
  * @param \TYPO3\Flow\Resource\Resource $resource The resource stored in this storage
  * @return resource | boolean A URI (for example the full path and filename) leading to the resource file or FALSE if it does not exist
  * @api
  */
 public function getStreamByResource(Resource $resource)
 {
     if ($this->debug) {
         $this->systemLogger->log('storage ' . $this->name . ': getStreamByResource');
     }
     if ($this->ftpService->fileExists('_' . $resource->getSha1())) {
         if ($this->debug) {
             $this->systemLogger->log('storage ' . $this->name . ': - getStreamByResource ' . 'http://' . $this->zoneDomain . '/_' . $resource->getSha1());
         }
         return fopen('http://' . $this->zoneDomain . '/_' . $resource->getSha1(), 'r');
     } else {
         if ($this->debug) {
             $this->systemLogger->log('storage ' . $this->name . ': - getStreamByResource file _' . $resource->getSha1() . ' not exists');
         }
         return FALSE;
     }
 }