OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.37k stars 2.38k forks source link

Prevent deleting media file if it is in use #8710

Open JoshTango opened 3 years ago

JoshTango commented 3 years ago

If a user tries to delete a media file but that file is used in a piece of content then it should:

  1. Not allow it.
  2. give a warning

These both should be in the settings.

This can be put on the backlog, I'm just documenting it for now.

Skrypt commented 3 years ago

This would add a lot of overhead on the process of removing a file. I can't agree.

JoshTango commented 3 years ago

Well data integrity would trump performance I think.

JoshTango commented 3 years ago

If I add an image to my html that's the same as a foreign key to an image table.

JoshTango commented 3 years ago

Again this should be a SETTING and I personally would set it to true.

Skrypt commented 3 years ago

You can create an indexing provider that does that but we use these images also with shortcodes and in Liquid views where it would be required to parse the templates to make sure we don't remove a media file that is currently in use. I'm not sure this would be reasonable...

What you probably need is to use a "Media attached field" so that it be associated with a Content Item and then you would just need to never remove these files contained in the /media/mediafields folder. What you want is a "managed image".

Here if we are talking about images that are added in Liquid Templates then it is a different scenario.

JoshTango commented 3 years ago

Orchard is different. I have seen some systems where you upload your assets per content item and they are owned by the content item and sometimes you even create a row in a MediaInfo table. So, in those systems it would be easy.

Skrypt commented 3 years ago

Use a "Media attached field". One feature here that could be added is that we could secure this folder better in the Media browser though.

JoshTango commented 3 years ago

This also ties into the approval process. If a content item has received approval to be published then the creator should not be able to delete the associated media files.

Skrypt commented 3 years ago

Maybe then we are missing a functionality in the Workflows. We copy the data in the workflow but we don't copy the assets. Maybe one thing here could be done and it is to keep the assets in a temp folder waiting for this approval.

JoshTango commented 3 years ago

Actually I was thinking of after approval but you just opend up a new issue which is waiting for approval.

Maybe the solution is to copy a set of assets once the content item has been approved.

BUT then comes the subject of Azure Media encoding for large video files which could eat of lots of space with duplication