dustin10 / VichUploaderBundle

A simple Symfony bundle to ease file uploads with ORM entities and ODM documents.
MIT License
1.85k stars 519 forks source link

Cloning an Uploadable entity #494

Closed belendel closed 8 years ago

belendel commented 8 years ago

Hi,

Perhaps you already have a solution for this, or could guide me into the right direction. In our application some entities can be cloned. At the moment when we clone an object the fileName property is copied.

We want the files to be removed when an image is updated or deleted. This is causing issues with the duplicated entities because the original entity will lose its image as well. The best solution would be if the file was copied with a newly generated name.

Any help would be really appreciated!

KernelFolla commented 8 years ago

Usually, best way is to reduce duplicate files is to create a custom entity for media and manage it with relations, for example sonatamediabundle does that, but same concept can be used easily in similar circumstances using a custom image entity.

anyway if you can't do that, you can stop using delete_on_remove and delete_on_update, write your own doctrine listeners and remove files there if needed

to remove the file you just need to replicate logic of Vich\UploaderBundle\EventListener\Doctrine\RemoveListener, injecting the service vich_uploader.upload_handler etc.

belendel commented 8 years ago

Thanks @KernelFolla !