public importResource ( string | resource $source, string $collectionName = ResourceManager::DEFAULT_PERSISTENT_COLLECTION_NAME, string $forcedPersistenceObjectIdentifier = null ) : |
||
$source | string | resource | A URI (can therefore also be a path and filename) or a PHP resource stream(!) pointing to the PersistentResource to import |
$collectionName | string | Name of the collection this new resource should be added to. By default the standard collection for persistent resources is used. |
$forcedPersistenceObjectIdentifier | string | INTERNAL: Force the object identifier for this resource to the given UUID |
return | A resource object representing the imported resource |
public function importResource($source, $collectionName = ResourceManager::DEFAULT_PERSISTENT_COLLECTION_NAME, $forcedPersistenceObjectIdentifier = null)
{
$this->initialize();
if (!isset($this->collections[$collectionName])) {
throw new Exception(sprintf('Tried to import a file into the resource collection "%s" but no such collection exists. Please check your settings and the code which triggered the import.', $collectionName), 1375196643);
}
/* @var CollectionInterface $collection */
$collection = $this->collections[$collectionName];
try {
$resource = $collection->importResource($source);
if ($forcedPersistenceObjectIdentifier !== null) {
ObjectAccess::setProperty($resource, 'Persistence_Object_Identifier', $forcedPersistenceObjectIdentifier, true);
}
if (!is_resource($source)) {
$pathInfo = UnicodeFunctions::pathinfo($source);
$resource->setFilename($pathInfo['basename']);
}
} catch (Exception $exception) {
throw new Exception(sprintf('Importing a file into the resource collection "%s" failed: %s', $collectionName, $exception->getMessage()), 1375197120, $exception);
}
$this->resourceRepository->add($resource);
$this->systemLogger->log(sprintf('Successfully imported file "%s" into the resource collection "%s" (storage: %s, a %s. SHA1: %s)', $source, $collectionName, $collection->getStorage()->getName(), get_class($collection), $resource->getSha1()), LOG_DEBUG);
return $resource;
}
/** * Imports a new image and persists it, including one variant * * @param string $importUri * @return string */ public function importAction($importUri) { $imageResource = $this->resourceManager->importResource($importUri); $image = new Image($imageResource); $imageVariant = new ImageVariant($image); $this->assetRepository->add($image); $this->assetRepository->add($imageVariant); $this->response->setHeader('X-ImageVariantUuid', $this->persistenceManager->getIdentifierByObject($imageVariant)); return 'ok'; }