getCollection() public method

Returns a Collection instance by the given name
public getCollection ( string $collectionName ) : Neos\Flow\ResourceManagement\CollectionInterface
$collectionName string Name of the collection as defined in the settings
return Neos\Flow\ResourceManagement\CollectionInterface or NULL
示例#1
0
 /**
  * Copy resources
  *
  * This command copies all resources from one collection to another storage identified by name.
  * The target storage must be empty and must not be identical to the current storage of the collection.
  *
  * This command merely copies the binary data from one storage to another, it does not change the related
  * PersistentResource objects in the database in any way. Since the PersistentResource objects in the database refer to a
  * collection name, you can use this command for migrating from one storage to another my configuring
  * the new storage with the name of the old storage collection after the resources have been copied.
  *
  * @param string $sourceCollection The name of the collection you want to copy the assets from
  * @param string $targetCollection The name of the collection you want to copy the assets to
  * @param boolean $publish If enabled, the target collection will be published after the resources have been copied
  * @return void
  */
 public function copyCommand($sourceCollection, $targetCollection, $publish = false)
 {
     $sourceCollectionName = $sourceCollection;
     $sourceCollection = $this->resourceManager->getCollection($sourceCollectionName);
     if ($sourceCollection === null) {
         $this->outputLine('The source collection "%s" does not exist.', array($sourceCollectionName));
         $this->quit(1);
     }
     $targetCollectionName = $targetCollection;
     $targetCollection = $this->resourceManager->getCollection($targetCollection);
     if ($targetCollection === null) {
         $this->outputLine('The target collection "%s" does not exist.', array($targetCollectionName));
         $this->quit(1);
     }
     if (!empty($targetCollection->getObjects())) {
         $this->outputLine('The target collection "%s" is not empty.', array($targetCollectionName));
         $this->quit(1);
     }
     $sourceObjects = $sourceCollection->getObjects();
     $this->outputLine('Copying resource objects from collection "%s" to collection "%s" ...', [$sourceCollectionName, $targetCollectionName]);
     $this->outputLine();
     $this->output->progressStart(count($sourceObjects));
     foreach ($sourceCollection->getObjects() as $resource) {
         /** @var \Neos\Flow\ResourceManagement\Storage\StorageObject $resource */
         $this->output->progressAdvance();
         $targetCollection->importResource($resource->getStream());
     }
     $this->output->progressFinish();
     $this->outputLine();
     if ($publish) {
         $this->outputLine('Publishing copied resources to the target "%s" ...', [$targetCollection->getTarget()->getName()]);
         $targetCollection->getTarget()->publishCollection($sourceCollection);
     }
     $this->outputLine('Done.');
     $this->outputLine('Hint: If you want to use the target collection as a replacement for your current one, you can now modify your settings accordingly.');
 }
 /**
  * Returns the base URI for static resources
  *
  * IMPORTANT: This method merely exists in order to simplify migration from earlier versions of Flow which still
  * provided this method. This method has never been part of the public API and will be removed in the future.
  *
  * Note that, depending on your Resource Collection setup, this method will not always return the correct base URI,
  * because as of now there can be multiple publishing targets for static resources and URIs of the respective
  * target might not work by simply concatenating a base URI with the relative file name.
  *
  * This method will work for the default Flow setup using only the local file system.
  *
  * Make sure to refactor your client code to use the new resource management API instead. There is no direct
  * replacement for this method in the new API, but if you are dealing with static resources, use the resource stream
  * wrapper instead (through URLs like "resource://Neos.Flow/Public/Error/Debugger.css") or use
  * ResourceManager->getPublicPackageResourceUri() if you know the package key and relative path.
  *
  * Don't use this method. Ne pas utiliser cette méthode. No utilice este método. Finger weg!
  * U bent gewaarschuwd! You have been warned! Mēs jūs brīdinām! Mir hams euch fei gsagd! ;-)
  *
  * @return mixed Either the web URI of the published resource or FALSE if the resource source file doesn't exist or the resource could not be published for other reasons
  * @deprecated since Flow 3.0. You cannot retrieve a base path for static resources anymore, please use resource://* instead or call ResourceManager->getPublicPackageResourceUri()
  */
 public function getStaticResourcesWebBaseUri()
 {
     $this->systemLogger->log('The deprecated method ResourcePublisher->getStaticResourcesWebBaseUri() has been called' . $this->getCallee() . '. You cannot retrieve a base path for static resources anymore, please use resource://* instead or call ResourceManager->getPublicPackageResourceUri().', LOG_WARNING);
     return preg_replace('/\\/Packages\\/$/', '/', $this->resourceManager->getCollection(ResourceManager::DEFAULT_STATIC_COLLECTION_NAME)->getTarget()->getPublicStaticResourceUri(''));
 }
 /**
  * Get the collection name this resource will be stored in. Default will be ResourceManager::DEFAULT_PERSISTENT_COLLECTION_NAME
  * The propertyMappingConfiguration CONFIGURATION_COLLECTION_NAME will directly override the default. Then if CONFIGURATION_ALLOW_COLLECTION_OVERRIDE is TRUE
  * and __collectionName is in the $source this will finally be the value.
  *
  * @param array $source
  * @param PropertyMappingConfigurationInterface $configuration
  * @return string
  * @throws InvalidPropertyMappingConfigurationException
  */
 protected function getCollectionName($source, PropertyMappingConfigurationInterface $configuration = null)
 {
     if ($configuration === null) {
         return ResourceManager::DEFAULT_PERSISTENT_COLLECTION_NAME;
     }
     $collectionName = $configuration->getConfigurationValue(ResourceTypeConverter::class, self::CONFIGURATION_COLLECTION_NAME) ?: ResourceManager::DEFAULT_PERSISTENT_COLLECTION_NAME;
     if (isset($source['__collectionName']) && $source['__collectionName'] !== '') {
         $collectionName = $source['__collectionName'];
     }
     if ($this->resourceManager->getCollection($collectionName) === null) {
         throw new InvalidPropertyMappingConfigurationException(sprintf('The selected resource collection named "%s" does not exist, a resource could not be imported.', $collectionName), 1416687475);
     }
     return $collectionName;
 }
 /**
  * Doctrine lifecycle event callback which is triggered on "postPersist" events.
  * This method triggers the publication of this resource.
  *
  * @return void
  * @ORM\PostPersist
  */
 public function postPersist()
 {
     if ($this->lifecycleEventsActive) {
         $collection = $this->resourceManager->getCollection($this->collectionName);
         $collection->getTarget()->publishResource($this, $collection);
     }
 }