FriendsOfCake / cakephp-upload

CakePHP: Handle file uploading sans ridiculous automagic
https://cakephp-upload.readthedocs.io/
MIT License
551 stars 255 forks source link

Delete images which are replaced on edit #527

Closed tgoeminne closed 2 years ago

tgoeminne commented 4 years ago

I was looking at the plugin and noticed that 'keepFilesOnDelete' => false, only works when you actually delete the file. Can you make it so that when there is only one upload attached to a record; that when you edit the field that the old file gets deleted?

eg as in the following

$this->addBehavior('Josegonzalez/Upload.Upload', [ 'logo' => [ 'path' => 'webroot{DS}files{DS}Articles{DS}logos{DS}', 'keepFilesOnDelete' => false, ]

When you edit the logo field, the old logo does not get removed it seems.

tgoeminne commented 4 years ago

It's also like when you edit an attachment record so that the attachment becomes a new file. Then it should be considered a delete of the old file? Maybe have a setting like "keepFilesOnEdit" and check if the value isDirty when existing records get updated?

davidyell commented 4 years ago

This feels like something you could implement into your own Writer class, or implement into an afterSave callback. At least in the meantime.

saeideng commented 2 years ago

duplicate of #493