OrchardCMS / Orchard

Orchard is a free, open source, community-focused Content Management System built on the ASP.NET MVC platform.
https://orchardproject.net
BSD 3-Clause "New" or "Revised" License
2.38k stars 1.12k forks source link

Orchard 1.7 - MediaPicker to MediaLibraryPicker Migration Bug on Missing Files (fix included) #3747

Closed orchardbot closed 9 years ago

orchardbot commented 11 years ago

@jeffolmstead created: https://orchard.codeplex.com/workitem/19919

This is bug is caused by having a media picker pointing to a file which is no longer in the physical file system. In this circumstance, running the "Migrating Media Picker Fields" in the Upgrade module will cause these files to not be found AND the old url will remain. This will cause an error as the new MediaLibraryPicker is expecting integers in the Data column, not strings.

Here is the code which will fix this.

File: Upgrade.Controllers.MediaController Method: MediaPicker (HttpPost) Code Change: if (media != null) { contentField.Url = "{" + media.Id + "}"; } else { // We don't want "broken" links left behind so instead want them converted to empty fields as broken links cause the page to crash // Because this might be run "twice", don't override already valid contentField Url's string contentFieldUrl = contentField.Url; if (!contentFieldUrl.StartsWith("{")) { contentField.Url = ""; } }

In a "normal" circumstance it would never be run "twice" but I perform the check just in case their are others out there who modify the database to be able to run through this upgrade two times.

orchardbot commented 11 years ago

@sebastienros commented:

Fixed in changeset 18cd049690d879c64d16b6f108d2cf3b38493be7