Add functionality to immediately delete files and override usage check

Created on 21 February 2020, over 4 years ago
Updated 6 September 2024, 2 months ago

In some scenarios it would be useful to immediately delete a file without waiting for the cron to run. Similarly it would be useful to skip the usages check, for example, in the situation where you really need to remove a file, but have a node with many revisions that would need to be deleted first.

Items to do

  • Todo: Add a clear waning, making the usages known to the end user when deleting usages
  • To Answer: Should usages be deleted alongside the file? This is because the usage will no longer have a file to reference
Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom spencer95@gmail.com Swansea/Cardiff

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.

  • 🇳🇿New Zealand magunz

    I have modified the #25 to implement a 3rd option to delete ALL the related / referring "Media Entities" too.

  • 🇬🇧United Kingdom kiwimind

    Having added the patch from #26, there are a couple of warnings showing.

    Warning: Undefined array key "file" in Drupal\file_delete\Form\FileDeleteForm->submitForm() (line 167 of modules/contrib/file_delete/src/Form/FileDeleteForm.php).

    Warning: foreach() argument must be of type array|object, null given in Drupal\file_delete\Form\FileDeleteForm->submitForm() (line 167 of modules/contrib/file_delete/src/Form/FileDeleteForm.php).

    I can't see any reason (yet) why some files cause this and others don't, but thought I'd mention it.

  • 🇬🇧United Kingdom kiwimind

    Have amended the previous patch to include an extra check to avoid the warning, as well as a little code style clean up and amending the text being output about the reference being deleted.

    I'm not 100% sure on whether $usage['file'] is enough or whether we should be looking at what else is passed, e.g. $usage['editor'], however this does remove the warning.

  • 🇨🇭Switzerland ayalon

    Thanks for the updated patch. I was not able to apply it via composer agains 2.0.0. So I have created a rerolled version that applies.

  • 🇨🇦Canada phjou Vancouver 🇨🇦 🇪🇺

    The option "Do you want to delete the referring media entities?" is misleading and should be renamed for something more like
    "Do you want to delete the referring entities?". If a node was referring that file then it would be deleted and it's not a media.

  • 🇨🇦Canada phjou Vancouver 🇨🇦 🇪🇺

    Changed misleading option that delete all entity types, not only media.

    Patch #29 doesn't apply towards the dev branch, so the interdiff is with #28

  • 🇫🇷France flocondetoile Lyon

    Patchs 26 and above are wrong because the ymiss the FileDeleteSettingsForm Class.

    InvalidArgumentException: Class "\Drupal\file_delete\Form\FileDeleteSettingsForm" does not exist.

    Nevermind I think we should go with MR8 (or patch 25), and discuss about this third option about deleting referencing entities in another dedicated issue. Consequences are potentially hugh, it's not only deleting media referencing the file deleted, but also any other content entities which reference this file (node, term, etc.) in any of its field.

  • 🇫🇷France flocondetoile Lyon

    Still having error "InvalidArgumentException: Class "\Drupal\file_delete\Form\FileDeleteSettingsForm" does not exist." with MR8. Investigating. I don't understand the Class form is well here and the namespace is correct and there is no typo...

Production build 0.71.5 2024