Neos2/Flow3 Best practice for creating/updating file resources

Hi all, I am looking for the best practice way for Neos 2 to create and update files at the back end using Flow3 Resources. Can anyone point me in the right direction? I’ve had a look at the documentation ( http://flowframework.readthedocs.org/en/stable/TheDefinitiveGuide/PartIII/ResourceManagement.html ) but looking for examples.

What I would like to do is create a CSV file as a back up for an enquiry form.

Many thanks

Hi Nick, sorry for the late reply …

What you basically need to do is using the ResourceManager to import a new Resource object from a file or content.

So, let’s assume you have a file somewhere which contains the CSV data, then you inject the ResourceManager as a property of your class (probably a controller) and then do:

$resource = $this->resourceManager->importResource('/tmp/yourfile.csv'');

Now you have a (persisted) Resource object, but you probably want to attach it to some other object (a domain model) in order to find it again, for example a Backup model:

$backup = new Backup;
$backup->setResource($resource);
$this->backupRepository->add($backup);

If you don’t have a CSV file but generated the data in memory, you can simply import the resource from content:

$resource = $this->resourceManager->importResourceFromnContent($myCsvData);

Does that help?

Hi Robert

thanks for getting back to me on this. I moved on, hence my late reply, and decided to use a model object to persist the data and update the data for now in the db. But I will come back to this and see if I can get it to work.
From what you have said I think I understand that if I connect the persistent resource to a model object I can reload it update it and save it again?

Thanks

Nick

yes, more specifically, what you would do is

  1. upload a new file, which results in a brand new resource object
  2. detach the old resource object from the model
  3. attach (add) the new resource object to the model
  4. make sure to persist the updated mode by calling update() on its repository

Flow will clean up all unused resource data and make sure to unpublish resources (even from a CDN) when they are not referenced by any resource object any more.