I've had a site administrator say that they added some files via "file/add" and they are reporting that less than a week later the files are gone. To me, this brings up a question.
There seems to be something in the code to do with cron deleting files. In what cases are files deleted? I tried to look into the code a bit, but I still haven't been able to wrap my head around cron queues completely and it looks like it's somewhat related to core file management, maybe? I get the idea of files which had been used in content being deleted, but what about files just uploaded and then a menu item created that links directly to them, for example? Or content linked to in the WYSIWYG? How can I ensure those files are not deleted if they are being deleted?
Thanks for your help.
Dan Ficker
Comments
Comment #1
gmclelland CreditAttribution: gmclelland commentedIt is a core issue. Files with no usage are deleted by cron after a certain amount of time(I think 6 hours).
Here is two issues to give you some background information.
Hope that helps
Comment #2
Devin Carlson CreditAttribution: Devin Carlson commentedSee @gmclelland's great explanation and related links. :)
Comment #3
gmclelland CreditAttribution: gmclelland commentedThanks Devin - I should make it more clear that it is Temporary files with no usage in the file_managed table that are cleaned up automatically by cron if those files are older than 6 hours.
Permanent files which have no file_usage are not deleted, however.
Comment #4
dandaman CreditAttribution: dandaman commentedBut with this File Entity module, if someone adds a file via the URL
/file/add
is that file considered Temporary or Permanent by default?Comment #5
gmclelland CreditAttribution: gmclelland commentedPermanent
Comment #6
Dave ReidThe other thing to remember is that permanent does not actually mean permanent (thanks Drupal core!). If you somehow add a permanent file on a file, image or media field, save the content, and then un-select or remove it, and re-save the content, if that file is not used anywhere else, it gets converted from permanent to temporary and will be deleted soon.
Comment #8
.jch CreditAttribution: .jch as a volunteer commentedThis issue is not fixed an persists through d8.3.3. After swapping out logos, in Content ~> Files they are listed as temporary and used in 0 places. In Configuration ~> Media ~> File System orphaned files are set to delete after 6 hours. After waiting I ran cron with no effect. I physically deleted all occurrences of the files, ran cron again and flushed all caches with no effect in the listing Content ~> Files. The files in the listing now point to nothing. I ran update.php with no effect.
If you really want to cleanup the listing you must do SQL queries on the database and delete the entries manually. (Note: To protect files from being deleted from persistent bugs set "Delete orphaned files after" to "Never" in Configuration ~> Media ~> File System).
Comment #9
.jch CreditAttribution: .jch as a volunteer commentedd8.5.3 Revisited the cleanup issue and thought I would post a simple manual cleanup procedure for anyone running across the issue of orphaned files. YourSite/admin/content/files is basically a view of the database table: file_managed. There is no functionality for changing status or deleting directly from here ...so... For files you want to remove from your site...
1) The nice way ~> Using phpMyAdmin or other SQL query method - edit/change field: status in table: file_managed from 1(permanent) to 0(temporary) for the files you want to remove. Note: Used In reference should be 0.
Next:: Manually run cron. The files are now gone and their associated entries have been removed from table: file_managed.
2) Not so nice ~> Delete records from table: file_managed for unwanted files and then manually delete files from their locations.
In: web\core\modules\file\config\install\file.settings.yml >> make_unused_managed_files_temporary: false ...is set to mark all files as permanent. I believe this was done in order to override remarking no longer used files as temporary to avoid any bugs mistakenly deleting wanted files when cron runs.
A simple custom module could be done in order to control this switch or better yet, a helper module / view mod to allow editing the file status field.
Don't have time now, but If I do one will try to remember to come back and update here.
Comment #10
kruser CreditAttribution: kruser commented@.jch Thanks, your "Nice" way worked for me.