1

Resolved

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

description

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.

comments

sebastienros wrote Aug 16, 2013 at 6:49 PM

Fixed in changeset 18cd049690d879c64d16b6f108d2cf3b38493be7