Neos.Media/Classes/Command/MediaCommandController.php
public function importResourcesCommand($simulate = false)
    {
        $this->initializeConnection();

        $sql = '
			SELECT
				r.persistence_object_identifier, r.filename, r.mediatype
			FROM neos_flow_resourcemanagement_persistentresource r
			LEFT JOIN neos_media_domain_model_asset a
			ON a.resource = r.persistence_object_identifier
			LEFT JOIN neos_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 === []) {
            $this->outputLine('Found no resources which need to be imported.');
            $this->quit();
        }

        foreach ($resourceInfos as $resourceInfo) {
            $resource = $this->persistenceManager->getObjectByIdentifier($resourceInfo['persistence_object_identifier'], 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.', [$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.', [$resourceInfo['filename'], $resourceInfo['persistence_object_identifier']]);
                continue;
            }

            $className = $this->mappingStrategy->map($resource, $resourceInfos);
            $resourceObj = new $className($resource);

            if ($simulate) {
                $this->outputLine('Simulate: Adding new resource "%s" (type: %s)', [$resourceObj->getResource()->getFilename(), $className]);
            } else {
                $this->assetRepository->add($resourceObj);
                $this->outputLine('Simulate: Adding new resource "%s" (type: %s)', [$resourceObj->getResource()->getFilename(), $className]);
            }
        }
    }
public function importResourcesCommand($simulate = false)
    {
        $this->initializeConnection();

        $sql = '
			SELECT
				r.persistence_object_identifier, r.filename, r.mediatype
			FROM neos_flow_resourcemanagement_persistentresource r
			LEFT JOIN neos_media_domain_model_asset a
			ON a.resource = r.persistence_object_identifier
			LEFT JOIN neos_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 === []) {
            $this->outputLine('Found no resources which need to be imported.');
            $this->quit();
        }

        foreach ($resourceInfos as $resourceInfo) {
            $resource = $this->persistenceManager->getObjectByIdentifier($resourceInfo['persistence_object_identifier'], 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.', [$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.', [$resourceInfo['filename'], $resourceInfo['persistence_object_identifier']]);
                continue;
            }

            $className = $this->mappingStrategy->map($resource, $resourceInfos);
            $resourceObj = new $className($resource);

            if ($simulate) {
                $this->outputLine('Simulate: Adding new resource "%s" (type: %s)', [$resourceObj->getResource()->getFilename(), $className]);
            } else {
                $this->assetRepository->add($resourceObj);
                $this->outputLine('Simulate: Adding new resource "%s" (type: %s)', [$resourceObj->getResource()->getFilename(), $className]);
            }
        }
    }
public function importResourcesCommand ( $ simulate = false ) { $ this -> initializeConnection ( ) ; $ sql = '
			SELECT
				r.persistence_object_identifier, r.filename, r.mediatype
			FROM neos_flow_resourcemanagement_persistentresource r
			LEFT JOIN neos_media_domain_model_asset a
			ON a.resource = r.persistence_object_identifier
			LEFT JOIN neos_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 === [ ] ) { $ this -> outputLine ( 'Found no resources which need to be imported.' ) ; $ this -> quit ( ) ; } foreach ( $ resourceInfos as $ resourceInfo ) { $ resource = $ this -> persistenceManager -> getObjectByIdentifier ( $ resourceInfo [ 'persistence_object_identifier' ] , 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.' , [ $ 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.' , [ $ resourceInfo [ 'filename' ] , $ resourceInfo [ 'persistence_object_identifier' ] ] ) ; continue ; } $ className = $ this -> mappingStrategy -> map ( $ resource , $ resourceInfos ) ; $ resourceObj = new $ className ( $ resource ) ; if ( $ simulate ) { $ this -> outputLine ( 'Simulate: Adding new resource "%s" (type: %s)' , [ $ resourceObj -> getResource ( ) -> getFilename ( ) , $ className ] ) ; } else { $ this -> assetRepository -> add ( $ resourceObj ) ; $ this -> outputLine ( 'Simulate: Adding new resource "%s" (type: %s)' , [ $ resourceObj -> getResource ( ) -> getFilename ( ) , $ className ] ) ; } } }
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
Import resources to asset management