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.35k stars 2.37k forks source link

Add warning when renaming Media files that Media Pickers will break #7628

Open mariojsnunes opened 3 years ago

mariojsnunes commented 3 years ago

After renaming or moving media, the media pickers using that media are not updated and keep the old broken links.

Other CMSs like Umbraco have a virtual media library (I guess OC1 too) and do not allow physical renaming of files, so this is never an issue.

Some implementation thoughts:

If there is a reason not to do this, I think at least a warning when renaming media items should be added.

Skrypt commented 3 years ago

I think the "virtual media library" has been removed in OC because we did not want it to have a dependency on the SQL storage. Doing this also has it's own flaws. One that comes to my mind is that it is quite a lot less performant than using the storage directly. If some media items should not be renamed then I suggest using the Attached Media field which will store medias in a "managed" folder. We can't prevent people renaming those files and they should be able to do so. Something that could be done is a tool that would harvest all the content items that uses the renamed file and update them with the new name. Though, is it necessary if someone knows that he should not rename all these files knowing that it is currently used in some content items?

It's also about getting the best performance possible on renaming a file which should not be exponentially longer if you have more content items. Maybe an external tool to allow renaming medias in all content items would be more appropriate then.

SQL script is one ...

mariojsnunes commented 3 years ago

Yeah I undestand the performance implications. And I agree OC shouldn't have this enabled by default. I wouldn't mind having this implementation on my codebase, or maybe it could even be another OC module. I'll try my hand at it, then share the code for a possible OC module. Thanks for the inputs 👍

sebastienros commented 3 years ago

If there is a reason not to do this, I think at least a warning when renaming media items should be added.

That is something reasonable to do. And maybe suggest to do a copy of the media with the old name, or eventually create a redirection for the file. These could be action links in the notification. Like these "undo" link when you soft delete an email.