Delete uploaded files with no references

Stephan-H

Member
Hi,
I'd like to have uploaded files deleted automatically if I delete records where they are referenced (and of course only if no other references are left). How would I do that?
Thanks,
Stephan
 

juergen_mueller

DaDaBIK Guru
There's a setting in the config file which should do that (so far I did not use it yet):
Code:
// when a record is deleted, delete also the uploaded files related to that record (0|1)
$delete_files_when_delete_record = 1;

Have a look at lines 448 and 449 in the config file
 

Stephan-H

Member
Hi Jürgen,

Thanks a lot! I overlooked that config option.

What if a file is referenced in several tables - is this checked before deleting?
 

eugenio

Administrator
Staff member
If you use DaDaBIK to manage the uploads, a file cannot be referenced in several tables, even if you upload twice the same file it got two different names.
 

Stephan-H

Member
I see. So if I have an existing database with more than one reference to the same file I have to handle this by myself.
 

eugenio

Administrator
Staff member
Yes, when DaDaBIK deletes the file, it doesn't perform any check.
You could use a before delete hook, do manually the check and return "dont_delete" in case you have multiple references, but this also prevents the deletion of the record, not only the file.
 
Top