Delete previous file when replacing

Created on 21 December 2021, almost 3 years ago
Updated 7 December 2023, about 1 year ago

Problem/Motivation

When replacing a file ( with the module opt-out option ), the previous file is not physically deleted.
The whole correct functionning of unused files and temporary files is blocked for years
https://www.drupal.org/project/drupal/issues/2821423 🌱 Dealing with unexpected file deletion due to incorrect file usage Active

Could the module delete the file on replacement, instead of only change its state to unused ?

Steps to reproduce

- When replacing a file and opt out the override
- the unused file is passed as temporary
- the file disappeared from the db after cron
- the file is not deleted physically after cron

changing the conf to $config['file.settings']['make_unused_managed_files_temporary'] = TRUE; has no effect

Proposed resolution

On the replacement submit button , delete physically the previous file

πŸ“Œ Task
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡«πŸ‡·France matoeil

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

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

    many users probably DO want the old file deleted immediately.

    Yes, πŸ’―

  • Status changed to Closed: won't fix over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    I'm concerned that the scope of this otherwise simple module being expanded too far. This issue is really about changing Drupal's behavior to immediately and automatically delete the old file, but that's only relevant when the functionality of this module is not used. I'd rather this be included in some other contrib module

  • Status changed to Needs review over 1 year ago
  • πŸ‡«πŸ‡·France matoeil

    As previously said on #7 though:

    - this module does not work as it should at the moment
    - when doing replacement , the old file is never deleted , which causes data protection issues
    - unless ['make_unused_managed_files_temporary'] = TRUE is set, which is highly not recommended because drupal core has issues with unmanaged files
    -these core bugs have been on for 6years so it might not been fixed exactly tomorrow.

    may i leave your reconsider as deleting the file immediately would fix the problem?

  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    I think there may just be a misunderstanding of this module's purpose. This module enhances the media entity edit form to add an optional feature that allows files to be replaced. This is available via a checkbox. If the checkbox is checked, the original file is replaced with the uploaded version. If the checkbox is not checked, this module does nothing. It preserve's core's original behavior. The module is not attempting to do any more than this. I think you're expecting that the module will delete the original file, even if the checkbox to replace it is not checked? That's not the intent of the module.

  • πŸ‡«πŸ‡·France matoeil

    Thnaks for taking that time to reply.
    I understand your point, but why absolutely wanting to preserve drupal core's behaviour when it is not working properly ?
    That module could fill a Drupal flaw.

    Unless you do settings that are not recommended in production, that sentence is wrong :
    "If unchecked, the filename of the replacement file will be used, and the original file may be deleted if no previous revision references it"

    The original file is never deleted !

    In other words, for sites in production, the media entity file replace module does not work as it says it should.

  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    I think I assume that most people have make_unused_managed_files_temporary enabled, but considering core doesn't do that by default, I understand there's probably a large number of sites without that enabled. I personally have it enabled on the sites I manage because the tradeoffs of not having it enabled are worse IMO.

    Can I ask, why are you not using the checkbox to overwrite the original file? If you did, then you wouldn't have a problem, right? The old file is replaced and there's nothing to delete.

  • πŸ‡«πŸ‡·France matoeil

    The problem is the module leave to content editors of the site, that are not Drupal experts, to choose one option or the other, from one media to another, without understanding fully the consequences of it ( and without knowing how the site has been configured )

    If the use of this module was to always overwrite the file , it would be better then to be configurable globally, and not left to the choice of the content editor on every media

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    3 pass
  • I've updated the patch from #16 to apply to version 1.2. Nothing has been changed except to make that patch work against the new version.

Production build 0.71.5 2024