Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete files as media items are deleted #252

Open
willguv opened this issue Sep 25, 2024 · 4 comments
Open

Delete files as media items are deleted #252

willguv opened this issue Sep 25, 2024 · 4 comments

Comments

@willguv
Copy link
Member

willguv commented Sep 25, 2024

Mentioned at the PG on 25th September

As media items are deleted, the attached files are left behind - this is causing a problem for a few councils

@andybroomfield identified 'media file delete' which might be in the default LGD install already

Image

Originally posted by @andybroomfield in #220 (comment)

@mccrodp
Copy link

mccrodp commented Sep 30, 2024

Hey folks (cc @willguv). Just looking to understand this issue as it's not clear the intention yet. I read the linked thread and will take a stab at it:

Problem / Solution

Problem

  • As media items are deleted, the attached files are left behind - this is causing a problem for a few councils.

Context

  • The default behaviour in Drupal is for files attached to deleted entities to be flagged for removal "later" and hence are kept temporarily in the interim.

Outcome

  • Some councils may want this default behaviour (see context) and some would like to delete files instantly.

Solution

???

Questions

  1. How far away is "later" for when files are actually deleted? Is it eg. on next cron run?
  2. There was a mention in the other thread of a "setting for how long temporary files are kept", any details on that?
  3. Do councils that want instant delete of attached files, want that to be a global setting, or a setting per deleted entity?

There was a suggestion to use https://www.drupal.org/project/media_file_delete if it was already in use in LGD, but I don't see it in contrib folder. Also, that adds an adds an additional module dependency which may not be what councils are looking for (see Q3 above). The suggested module seems to provide a per entity setting to delete the attached files instantly, rather than a global setting.

Please correct any of the above where I have misunderstood things. I also gathered that some councils may want to default behaviour, so please confirm that. If every council just wanted instant delete of files attached to deleted media entities, it'd be simpler to just use hook_entity_delete and if ($file) $file->delete(), but I presume that's not the hardline solution that all councils want 🤔

@willguv
Copy link
Member Author

willguv commented Sep 30, 2024

Hi @mccrodp thanks for this detail.

What I've heard from councils is that "old files are left lying around taking up space" or words to that effect. I'm not clear on how often this happens, or by what cause. If the default behavior eventually clears away old files, then it feels like there's not much of a problem.

If this prompts more thoughts, please do post them. I think I need to understand the issue a little better!

@mccrodp
Copy link

mccrodp commented Sep 30, 2024

If the default behavior eventually clears away old files, then it feels like there's not much of a problem.

Right, that is getting us/me closer to something I think, thanks @willguv. So, if I understand the actions needed then, they are:

  1. Surface / detail the default behaviour so that everyone has a clear understanding of files associated to deleted media entities
  2. Get to the bottom of whether the default behaviour clears away these old files eventually, specifically highlighting:
    -- what conditions trigger this clearing
    -- how often it happens
    -- if there's anyway to trigger it or make it happen more regularly

I can take a closer look at this tomorrow Didn't get time for this.

@MariosORION
Copy link
Contributor

@mccrodp @willguv I've spent some time looking into this and here are my findings:

How Drupal handles files by default (also see https://www.drupal.org/docs/administering-a-drupal-site/uploaded-file-management). The key points are:

  • Files will be saved as "permanent" by default. It is possible that some Councils might have implemented custom logic that leads to files marked as "temporary" present in the codebase.
  • Temporary files get deleted (on the first Cron run) after 6 hours by default. This is a configuration setting under /admin/config/media/file-system and Councils will be able to change this if they need more/less time before temporary files get permanently deleted.
  • Media file delete acts upon the delete action of Media entities and gives editors the ability to delete the accompanying file immediately.
  • File Delete offers the ability to add a "Delete file" option on the Files screen (this has to be added to the related View's configuration). These files will be turned into temporary files and deleted after 6 hours (by default as described above) on a Cron run. There is also a "Delete files" permission this module adds that Councils can use based on how their roles are configured.

The File Delete module seems to be closer to what you describe @willguv.
Hope that helps @mccrodp ?

@MariosORION MariosORION changed the title Delete fles as media items are deleted Delete files as media items are deleted Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

3 participants