add() 공개 메소드

public add ( Neos\Media\Domain\Model\AssetInterface $object )
$object Neos\Media\Domain\Model\AssetInterface
 /**
  * Upload a new image and return an image variant, a thumbnail and additional information like it would be
  * returned for the Neos backend.
  *
  * @param Image $image
  * @return string
  */
 public function uploadAction(Image $image)
 {
     $this->assetRepository->add($image);
     $imageVariant = new ImageVariant($image);
     $this->assetRepository->add($imageVariant);
     $thumbnail = $image->getThumbnail(100, 100);
     $this->response->setHeader('Content-Type', 'application/json');
     return json_encode(array('__identity' => $this->persistenceManager->getIdentifierByObject($image), '__resourceUri' => $this->resourceManager->getPublicPersistentResourceUri($image->getResource()), 'width' => $image->getWidth(), 'height' => $image->getHeight(), 'thumbnail' => array('__resourceUri' => $this->resourceManager->getPublicPersistentResourceUri($thumbnail->getResource()), 'width' => $thumbnail->getWidth(), 'height' => $thumbnail->getHeight()), 'variants' => array(array('__identity' => $this->persistenceManager->getIdentifierByObject($imageVariant), '__resourceUri' => $this->resourceManager->getPublicPersistentResourceUri($imageVariant->getResource()), 'width' => $imageVariant->getWidth(), 'height' => $imageVariant->getHeight()))));
 }
 /**
  * @return Asset
  * @throws \Neos\Flow\ResourceManagement\Exception
  */
 protected function buildAssetObject()
 {
     $resource = $this->resourceManager->importResourceFromContent('Test', 'test.txt');
     $asset = new Asset($resource);
     $this->assetRepository->add($asset);
     return $asset;
 }
 /**
  * Generate a new image variant from given data.
  *
  * @param ImageVariant $asset
  * @return string
  */
 public function createImageVariantAction(ImageVariant $asset)
 {
     if ($this->persistenceManager->isNewObject($asset)) {
         $this->assetRepository->add($asset);
     }
     $propertyMappingConfiguration = new PropertyMappingConfiguration();
     // This will not be sent as "application/json" as we need the JSON string and not the single variables.
     return json_encode($this->entityToIdentityConverter->convertFrom($asset, 'array', [], $propertyMappingConfiguration));
 }
 /**
  * Upload a new asset. No redirection and no response body, for use by plupload (or similar).
  *
  * @param Asset $asset
  * @return string
  */
 public function uploadAction(Asset $asset)
 {
     if (($tag = $this->browserState->get('activeTag')) !== null) {
         $asset->addTag($tag);
     }
     if ($this->persistenceManager->isNewObject($asset)) {
         $this->assetRepository->add($asset);
     } else {
         $this->assetRepository->update($asset);
     }
     if (($assetCollection = $this->browserState->get('activeAssetCollection')) !== null && $assetCollection->addAsset($asset)) {
         $this->assetCollectionRepository->update($assetCollection);
     }
     $this->addFlashMessage('assetHasBeenAdded', '', Message::SEVERITY_OK, [htmlspecialchars($asset->getLabel())]);
     $this->response->setStatus(201);
     return '';
 }
    /**
     * Import resources to asset management
     *
     * This command detects Flow "PersistentResource"s which are not yet available as "Asset" objects and thus don't appear
     * in the asset management. The type of the imported asset is determined by the file extension provided by the
     * PersistentResource.
     *
     * @param boolean $simulate If set, this command will only tell what it would do instead of doing it right away
     * @return void
     */
    public function importResourcesCommand($simulate = false)
    {
        $this->initializeConnection();
        $sql = '
			SELECT
				r.persistence_object_identifier, r.filename, r.mediatype
			FROM typo3_flow_resource_resource r
			LEFT JOIN typo3_media_domain_model_asset a
			ON a.resource = r.persistence_object_identifier
			LEFT JOIN typo3_media_domain_model_thumbnail t
			ON t.resource = r.persistence_object_identifier
			WHERE a.persistence_object_identifier IS NULL AND t.persistence_object_identifier IS NULL
		';
        $statement = $this->dbalConnection->prepare($sql);
        $statement->execute();
        $resourceInfos = $statement->fetchAll();
        if ($resourceInfos === array()) {
            $this->outputLine('Found no resources which need to be imported.');
            $this->quit();
        }
        foreach ($resourceInfos as $resourceInfo) {
            $mediaType = $resourceInfo['mediatype'];
            if (substr($mediaType, 0, 6) === 'image/') {
                $resource = $this->persistenceManager->getObjectByIdentifier($resourceInfo['persistence_object_identifier'], \Neos\Flow\ResourceManagement\PersistentResource::class);
                if ($resource === null) {
                    $this->outputLine('Warning: PersistentResource for file "%s" seems to be corrupt. No resource object with identifier %s could be retrieved from the Persistence Manager.', array($resourceInfo['filename'], $resourceInfo['persistence_object_identifier']));
                    continue;
                }
                if (!$resource->getStream()) {
                    $this->outputLine('Warning: PersistentResource for file "%s" seems to be corrupt. The actual data of resource %s could not be found in the resource storage.', array($resourceInfo['filename'], $resourceInfo['persistence_object_identifier']));
                    continue;
                }
                $image = new Image($resource);
                if ($simulate) {
                    $this->outputLine('Simulate: Adding new image "%s" (%sx%s px)', array($image->getResource()->getFilename(), $image->getWidth(), $image->getHeight()));
                } else {
                    $this->assetRepository->add($image);
                    $this->outputLine('Adding new image "%s" (%sx%s px)', array($image->getResource()->getFilename(), $image->getWidth(), $image->getHeight()));
                }
            }
        }
    }
 /**
  * @test
  */
 public function findBySearchTermAndTagsReturnsFilteredResult()
 {
     $tag = new Tag('home');
     $this->tagRepository->add($tag);
     $resource1 = $this->resourceManager->importResource(__DIR__ . '/../../Fixtures/Resources/license.txt');
     $resource2 = $this->resourceManager->importResource(__DIR__ . '/../../Fixtures/Resources/417px-Mihaly_Csikszentmihalyi.jpg');
     $asset1 = new Asset($resource1);
     $asset1->setTitle('asset for homepage');
     $asset2 = new Asset($resource2);
     $asset2->setTitle('just another asset');
     $asset2->addTag($tag);
     $this->assetRepository->add($asset1);
     $this->assetRepository->add($asset2);
     $this->persistenceManager->persistAll();
     $this->persistenceManager->clearState();
     $this->assertCount(2, $this->assetRepository->findBySearchTermOrTags('home', array($tag)));
     $this->assertCount(2, $this->assetRepository->findBySearchTermOrTags('homepage', array($tag)));
     $this->assertCount(1, $this->assetRepository->findBySearchTermOrTags('baz', array($tag)));
     // This is necessary to initialize all resource instances before the tables are deleted
     foreach ($this->assetRepository->findAll() as $asset) {
         $asset->getResource()->getSha1();
     }
 }