Manage TTL of temporary files via variable get instead of DRUPAL_MAXIMUM_TEMP_FILE_AGE defined, defaults to previous value.

Constant is kept for compatibility with contrib and core code.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

escuriola’s picture

Status: Active » Needs review
FileSize
6.71 KB
David_Rothstein’s picture

What is the use case for making this configurable - giving people more than 6 hours between uploading a file attachment and submitting the form?

There was some discussion of this in #1399846: Make unused file 'cleanup' configurable and I think people felt it wouldn't be that useful to make this configurable without changing other more complicated things also, but perhaps there's still a use case for it. I'll cross-link this issue there too.

escuriola’s picture

Hello David.

We just want to generate files from a custom module. These files are useful during a limited time (one month) and past it them should be garbage collected. We are using file API for managed it automatically deleted by cron to save time to our sys admins. And also we think that this is useful and harmful and we prefer to use the drupal native system to manage files instead of write custom code and store files outside drupal management.

amontero’s picture

I +1 to the proposal. I've stumbled on this while writing a custom module that creates temporary, short lived (but not as short as 6hrs) files. I want the files to be managed by Drupal, but they have an expiry time and since I'm not using them attached to any node, I'm not worried about missing node linked files. What worries me most is capping the 'expirable files' disk usage and keeping tabs on 'file_managed' table record growth.
Drupal's File API is almost as good for temp files as it is for permanent ones. I would like to take advantage of Drupal core's cron janitor to forget about temp file cleanup, since I don't want external dependencies on sysadmin stuff. I'm OK with temp uploads living 'drupal_max_file_age', specially if I change the setting knowingly (well, in my case I don't have form uploads). However, I admit that this behaviour should be clearly stated in docs/comments due to the possible side effect David pointed out (help text/comment suggestions welcome).
As of now, my only option is to write custom, duplicated code imitating core behaviour, but it feels redundant/weird, since it's *almost* built in core.
This patch coupled with this other issue I'm working on core would enhance Drupal File API for temporary files management (reviewers welcome):
#1659116: Define FILE_STATUS_TEMPORARY and expose $status in file_save_data
I've linked both issues.