Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
try the following.
- define a new CCK content type with a filefield, which is set to be required
- create a new node of this content type and upload a file
- edit the node, remove the uploaded file and try to delete the node
---> It will say that a file must be uploaded, because the filefield is required.
- upload a new file and hit delete of the node again
---> Node gets deleted, but the newly uploaded file is not deleted.
Comment | File | Size | Author |
---|---|---|---|
#4 | filefield_delete_temporary.patch | 2.24 KB | quicksketch |
Comments
Comment #1
quicksketchHi there, yes what you say is true, but the file is not "abandoned", it's recorded in the database as "temporary" and will be deleted after 6 hours if the file is not made permanent. You're right though in that it should be possible to make a record of temporary files that were created while editing the node, then delete them immediately when the node is saved or when the file is removed from the form.
Comment #2
advseb CreditAttribution: advseb commentedAh ok, I see. Does that mean the file gets automatically deleted after 6 hours also from the harddisk or is just the entry in the files table removed? In the first case (file gets deleted from the harddisk), I think this is fine and I suggest to close this report.
Comment #3
quicksketchThe file is deleted both from disk and from the database. Of course this requires cron to be running in order for the cleanup to occur. See the system_cron() function for details of the delete.
Comment #4
quicksketchTurns out this task was much easier than I thought it was going to be. Since we have the convenience of the temporary status and FileField's reference counting, it's a piece of cake to simply check if the file is in use when the "Remove" button is clicked. This patch immediately deletes files when they're not needed.
Comment #5
quicksketchCommitted. Please reopen if this change has caused any problems.