Migrate Media File Delete Contrib to Core

Created on 16 June 2023, about 2 years ago

Problem/Motivation

@larowlan's β†’ Media file delete contrib module ...

...gives content editors the option to delete the associated file when deleting a media entity.

It's a relatively new module so the number of reported installs (4,987 as of 7/16/23) IMO isn't a deciding factor as to whether or not the functionality of this module should be migrated to Core, but I'll never build a site (personal or professional) without this module installed as it makes it much easier for content/media editors to do just want the module says. The functionality of this module also saves space over time by eliminating unnecessary files from the file system as many editors might not understand the relationship between media and files and might not know that deleting the media item does not automatically delete the associated file. All that to say, should the functionality of the Media file delete contrib module be migrated to core? Go ...

Without Media File Delete module installed a content/media editor would have to:

  1. Install the views_bulk_operations module (or similar) to add a delete operation at /admin/content/files
  2. Navigate to /admin/content/media
  3. Search for the media item
  4. Edit the media item
  5. Copy the file name
  6. Delete the media item
  7. Navigate to /admin/content/files
  8. Paste the file name in the Filename field
  9. Click filter
  10. Select the file
  11. And finally, at long last, delete the file

WITH the Media File Delete module installed a content/media editor would have to:

  1. Navigate to /admin/content/media
  2. Search for the media item
  3. Delete the media item AND delete the file at the same time

Features

  • Give content editors the option to delete the associated file when deleting a media entity
  • Prevents deletion if the file is in use in other locations
  • Prevents deletion if the user does not have access
  • Adds a new 'delete any file' permission, allowing power-users to bypass core's You can only delete files you own behavior
  • Optional support for the Entity Usage module when determining if the file is in use. Enable the Media File Delete Entity Usage sub-module to turn this functionality on. This will allow you to prevent deletion if there are uses of the file not tracked by core's File usage API e.g. direct links in body fields to the file.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component
MediaΒ  β†’

Last updated about 19 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States Chris Matthews

Live updates comments and jobs are added and updated live.

Missing content requested by

πŸ‡¦πŸ‡ΊAustralia dpi
over 1 year ago
Sign in to follow issues

Comments & Activities

  • Issue created by @Chris Matthews
  • πŸ‡ΊπŸ‡ΈUnited States Chris Matthews

    There is also File Delete β†’ with 14,312 reported installs

    The File Delete module adds the ability to easily delete files β€”both private and publicβ€” within Drupal administration.

    It changes files from the "Permanent" status to the "Temporary" status. These files will be deleted by Drupal during its cron runs.

    If a file is registered as being used somewhere, the Module will not allow it to be deleted.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    +1 from me, it has good test coverage and very little code

  • πŸ‡ΊπŸ‡ΈUnited States Chris Matthews

    I suppose the 'Media File Delete settings' that live in the contrib module at /admin/config/media/media_file_delete/settings would live in core at /admin/config/media/media-settings

  • πŸ‡ΊπŸ‡ΈUnited States Chris Matthews

    Moving to Drupal core ideas queue for consensus as to whether or not to move forward with the proposed idea to merge the functionality of the Media File Delete contrib module into Core.

  • πŸ‡¬πŸ‡§United Kingdom AaronMcHale Edinburgh, Scotland

    Big +1 from me.

    I would have assumed that deleting a media entity would also delete the files that were uploaded into that entity, and I think that is probably what a lot of content editors and site builders would have expected.

    Think about the workflow from the point of view of a content editor who receives a request to delete an image:

    1. We need to remove this image because (for instance) a person in it has withdrawn their consent.
    2. We go to the media library and delete the image (aka the media entity, but editors don't think in terms of entities they just think about the thing they are deleting).
    3. The editor think that's it done, they go back to the person and say that it's been deleted; But then, either: the editor check (just to be safe) and get confused when they find the image still actually exists, or they don't check and the person that originally requested the deletion sends a follow-up request asking why it was not actually deleted even though the editor said it was.

    So, yes I'm 100% to this.

  • +1 from me, too. The lack of this functionality is really the only reason I'm hesitant about using Media for images. I don't want to accrue lots of orphan files over time.

  • πŸ‡¬πŸ‡§United Kingdom catch

    Broadly +1 to this too, but we also need to resolve 🌱 Dealing with unexpected file deletion due to incorrect file usage Active . Potentially this could be the answer - make file deletion not automatic, but explicit and opt-in, and then assume that people aren't re-using the same file across media items and in other random places and deleting it without checking. Then just drop the entire file_usage system with no replacement.

  • πŸ‡ΊπŸ‡ΈUnited States Chris Matthews

    -

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Fwiw The current module doesn't show the option if file usage detects has a record of another usage

    It also integrates with entity usage if that is available

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    +1 from me. This feels like table stakes for any file-based media type. I think deleting the associated file should be the default behavior; if it's not in the CMS, it doesn't make sense (from my own personal user perspective) for it to persist in the filesystem.

  • πŸ‡³πŸ‡ΏNew Zealand quietone

    The Ideas project is being deprecated. As discussed in a core committer meeting issues that are adding modules are being moved to the Drupal CMS project for discussion.

  • πŸ‡ΊπŸ‡ΈUnited States tim.plunkett Philadelphia
  • πŸ‡¦πŸ‡ΊAustralia pameeela

    I'm not sure why this didn't make it into 1.0.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    With my Media maintainer hat on:

    I don't even think we should add this to Drupal CMS. This should be converted to a core issue and the functionality should be merged into core directly. It's mind-boggling that it's not there already.

  • πŸ‡ΊπŸ‡ΈUnited States Chris Matthews

    With my Site Builder hat on, +1000 to #17 ✨ Migrate Media File Delete Contrib to Core Active (FWIW :) )

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Let's do that. I'm gonna jump the gun a bit and assume this should be a priority for 11.3.0. It's kind of nuts that core doesn't already support this, and it shouldn't be a heavy lift at all to merge the module into the main Media module.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Linking a known bug with i18n in the contrib module

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    All our projects have file deletion on usage 0 enabled and it works generally well, especially when files are mostly used on media entities.

    Instead of a manual option, what I'd consider to restore is the old behavior of file usage removal, which didn't mark it as temporary to then remove it hours later but delete it immediately. Far less confusing IMHO and doesn't require a decision by the editor. Could be both as well, only show the manual option if automatic deletion isn't enabled.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Wasn't file usage kind of deprecated as a concept because it has never really worked? That's what I heard a few DrupalCons ago, anyway.

  • @phenaproxima opened merge request.
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    This will need framework manager review for the proposed changes to extant core APIs and subsystem maintainer sign-off (I would qualify except I wrote the patch).

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    It was disabled, yes. And I think there are some remaining issues with editor and revisions, but we don't use that. The last issue that affected us (when using file exclusively through media entities) was 🌱 Dealing with unexpected file deletion due to incorrect file usage Active . See the issue that @catch linked.

    We've had it enabled for years and haven't seen a file deletion related to a bug in a long time. We sometimes have cases where editors link directly to files and that can break, that could possibly be prevented by better tooling.

  • πŸ‡¬πŸ‡§United Kingdom catch

    🌱 Add a reliable entity-usage system to core Active is where we ended up on the file_usage issue - trying to bring entity_usage into core and deprecate file_usage. It is not really moving but I don't see another way to make it work.

    I have a site that was experiencing missing files, this site has been around since Drupal 4.5, there is no way to rebuild the file_usage table, so it likely has examples of every file_usage bug since it was introduced and no matter how many we fix it's never corrected retrospectively.

Production build 0.71.5 2024