/**
  * Shows a specific asset
  *
  * @param string $identifier Specifies the asset to look up
  * @return string
  */
 public function showAction($identifier)
 {
     $asset = $this->assetRepository->findByIdentifier($identifier);
     if ($asset === null) {
         $this->throwStatus(404);
     }
     $this->view->assign('asset', $asset);
 }
 /**
  * Fetch an object from persistence layer.
  *
  * @param mixed $identity
  * @param string $targetType
  * @return object
  * @throws \TYPO3\Flow\Property\Exception\TargetNotFoundException
  * @throws \TYPO3\Flow\Property\Exception\InvalidSourceException
  */
 protected function fetchObjectFromPersistence($identity, $targetType)
 {
     if (is_string($identity)) {
         $object = $this->assetRepository->findByIdentifier($identity);
     } else {
         throw new \TYPO3\Flow\Property\Exception\InvalidSourceException('The identity property "' . $identity . '" is not a string.', 1415817618);
     }
     return $object;
 }
 /**
  * Fetch an object from persistence layer.
  *
  * @param mixed $identity
  * @param string $targetType
  * @return object
  * @throws \TYPO3\Flow\Property\Exception\TargetNotFoundException
  * @throws \TYPO3\Flow\Property\Exception\InvalidSourceException
  */
 protected function fetchObjectFromPersistence($identity, $targetType)
 {
     if ($targetType === 'TYPO3\\Media\\Domain\\Model\\Thumbnail') {
         $object = $this->persistenceManager->getObjectByIdentifier($identity, $targetType);
     } elseif (is_string($identity)) {
         $object = $this->assetRepository->findByIdentifier($identity);
     } else {
         throw new \TYPO3\Flow\Property\Exception\InvalidSourceException('The identity property "' . $identity . '" is not a string.', 1415817618);
     }
     return $object;
 }
 /**
  * Fetch an object from persistence layer.
  *
  * @param mixed $identity
  * @param string $targetType
  * @return object
  * @throws TargetNotFoundException
  * @throws InvalidSourceException
  */
 protected function fetchObjectFromPersistence($identity, $targetType)
 {
     if ($targetType === Thumbnail::class) {
         $object = $this->persistenceManager->getObjectByIdentifier($identity, $targetType);
     } elseif (is_string($identity)) {
         $object = $this->assetRepository->findByIdentifier($identity);
     } else {
         throw new InvalidSourceException('The identity property "' . $identity . '" is not a string.', 1415817618);
     }
     return $object;
 }
 /**
  * @param FluidView $view
  * @return void
  */
 public function initializeView(FluidView $view)
 {
     $assets = $this->tsValue('assets');
     $processedAssets = array();
     /** @var Asset $asset */
     if (is_array($assets)) {
         foreach ($assets as $asset) {
             if ($asset->getResource() === null) {
                 if ($asset instanceof Image) {
                     $processedAssets[] = $this->imageRepository->findByIdentifier($asset->getIdentifier());
                 } elseif ($asset instanceof Asset) {
                     $processedAssets[] = $this->assetRepository->findByIdentifier($asset->getIdentifier());
                 }
             } else {
                 $processedAssets[] = $asset;
             }
         }
     }
     $view->assign('assets', $processedAssets);
 }
 /**
  * Return the object the URI addresses or NULL.
  *
  * @param string|Uri $uri
  * @param NodeInterface $contextNode
  * @return NodeInterface|AssetInterface|NULL
  */
 public function convertUriToObject($uri, NodeInterface $contextNode = null)
 {
     if ($uri instanceof Uri) {
         $uri = (string) $uri;
     }
     if (preg_match(self::PATTERN_SUPPORTED_URIS, $uri, $matches) === 1) {
         switch ($matches[1]) {
             case 'node':
                 if ($contextNode === null) {
                     throw new \RuntimeException('node:// URI conversion requires a context node to be passed', 1409734235);
                 }
                 return $contextNode->getContext()->getNodeByIdentifier($matches[2]);
             case 'asset':
                 return $this->assetRepository->findByIdentifier($matches[2]);
         }
     }
     return null;
 }
 /**
  * Converts the given $objectXml to an AssetInterface instance and returns it
  *
  * @param \SimpleXMLElement $objectXml
  * @param string $className the concrete class name of the AssetInterface to create
  * @return AssetInterface
  * @throws NeosException
  */
 protected function importAsset(\SimpleXMLElement $objectXml, $className)
 {
     if (isset($objectXml['__identifier'])) {
         $asset = $this->assetRepository->findByIdentifier((string) $objectXml['__identifier']);
         if (is_object($asset)) {
             return $asset;
         }
     }
     $resourceHash = (string) $objectXml->resource->hash;
     $resourceData = trim((string) $objectXml->resource->content);
     if ((string) $objectXml->resource['__identifier'] !== '') {
         $resource = $this->persistenceManager->getObjectByIdentifier((string) $objectXml->resource['__identifier'], 'TYPO3\\Flow\\Resource\\Resource');
     }
     if (!isset($resource) || $resource === null) {
         $resource = $this->importResource((string) $objectXml->resource->filename, $resourceHash !== '' ? $resourceHash : null, !empty($resourceData) ? $resourceData : null, (string) $objectXml->resource['__identifier'] !== '' ? (string) $objectXml->resource['__identifier'] : null);
     }
     $asset = $this->objectManager->get($className);
     $asset->setResource($resource);
     $this->assetRepository->add($asset);
     return $asset;
 }
 /**
  * Change the property on the given node.
  *
  * @param NodeData $node
  * @return void
  */
 public function execute(NodeData $node)
 {
     foreach ($node->getNodeType()->getProperties() as $propertyName => $propertyConfiguration) {
         if (isset($propertyConfiguration['type']) && ($propertyConfiguration['type'] === 'TYPO3\\Media\\Domain\\Model\\ImageInterface' || preg_match('/array\\<.*\\>/', $propertyConfiguration['type']))) {
             if (!isset($nodeProperties)) {
                 $nodeRecordQuery = $this->entityManager->getConnection()->prepare('SELECT properties FROM typo3_typo3cr_domain_model_nodedata WHERE persistence_object_identifier=?');
                 $nodeRecordQuery->execute([$this->persistenceManager->getIdentifierByObject($node)]);
                 $nodeRecord = $nodeRecordQuery->fetch(\PDO::FETCH_ASSOC);
                 $nodeProperties = unserialize($nodeRecord['properties']);
             }
             if (!isset($nodeProperties[$propertyName]) || empty($nodeProperties[$propertyName])) {
                 continue;
             }
             if ($propertyConfiguration['type'] === 'TYPO3\\Media\\Domain\\Model\\ImageInterface') {
                 $adjustments = array();
                 $oldVariantConfiguration = $nodeProperties[$propertyName];
                 if (is_array($oldVariantConfiguration)) {
                     foreach ($oldVariantConfiguration as $variantPropertyName => $property) {
                         switch (substr($variantPropertyName, 3)) {
                             case 'originalImage':
                                 /**
                                  * @var $originalAsset \TYPO3\Media\Domain\Model\Image
                                  */
                                 $originalAsset = $this->assetRepository->findByIdentifier($this->persistenceManager->getIdentifierByObject($property));
                                 break;
                             case 'processingInstructions':
                                 $adjustments = $this->processingInstructionsConverter->convertFrom($property, 'array');
                                 break;
                         }
                     }
                     $nodeProperties[$propertyName] = NULL;
                     if (isset($originalAsset)) {
                         $stream = $originalAsset->getResource()->getStream();
                         if ($stream === FALSE) {
                             continue;
                         }
                         fclose($stream);
                         $newImageVariant = new \TYPO3\Media\Domain\Model\ImageVariant($originalAsset);
                         foreach ($adjustments as $adjustment) {
                             $newImageVariant->addAdjustment($adjustment);
                         }
                         $originalAsset->addVariant($newImageVariant);
                         $this->assetRepository->update($originalAsset);
                         $nodeProperties[$propertyName] = $this->persistenceManager->getIdentifierByObject($newImageVariant);
                     }
                 }
             } elseif (preg_match('/array\\<.*\\>/', $propertyConfiguration['type'])) {
                 if (is_array($nodeProperties[$propertyName])) {
                     $convertedValue = [];
                     foreach ($nodeProperties[$propertyName] as $entryValue) {
                         if (!is_object($entryValue)) {
                             continue;
                         }
                         $stream = $entryValue->getResource()->getStream();
                         if ($stream === FALSE) {
                             continue;
                         }
                         fclose($stream);
                         $existingObjectIdentifier = NULL;
                         try {
                             $existingObjectIdentifier = $this->persistenceManager->getIdentifierByObject($entryValue);
                             if ($existingObjectIdentifier !== NULL) {
                                 $convertedValue[] = $existingObjectIdentifier;
                             }
                         } catch (\Exception $exception) {
                         }
                     }
                     $nodeProperties[$propertyName] = $convertedValue;
                 }
             }
         }
     }
     if (isset($nodeProperties)) {
         $nodeUpdateQuery = $this->entityManager->getConnection()->prepare('UPDATE typo3_typo3cr_domain_model_nodedata SET properties=? WHERE persistence_object_identifier=?');
         $nodeUpdateQuery->execute([serialize($nodeProperties), $this->persistenceManager->getIdentifierByObject($node)]);
     }
 }