Delete images which are replaced on edit
tgoeminne opened this issue · 3 comments
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.
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?
This feels like something you could implement into your own Writer class, or implement into an afterSave
callback. At least in the meantime.