Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Marco Lusini 176 posts 1370 karma points
    Feb 10, 2018 @ 08:17
    Marco Lusini
    0

    Uninstall package and Media Types

    Hi,

    I am trying to uninstall the package and remove the media types that it creates from a production site. Is there a way to change media created as type File-Word, File-Pdf, etc. to the standard File type without other side effects?

    TIA Marco

  • Andy Robinson 9 posts 96 karma points c-trib
    Feb 11, 2018 @ 14:27
    Andy Robinson
    1

    Hi Marco, it seemed like a great idea at the time, but since then umbraco killed off the ability to access child media types

    here is a Gits that will set the mediatypes back to "File" when you save a media type

    https://gist.github.com/minirobbo/378a644aed6089d69f787c747b8da757

  • Marco Lusini 176 posts 1370 karma points
    Feb 13, 2018 @ 10:40
    Marco Lusini
    0

    Thanks! I used your example as a basis for a template that changes each media of type File-xxx to File (to be run after the package is uninstalled):

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @using Umbraco.Core;
    @using Umbraco.Core.Logging;
    @using Umbraco.Core.Models;
    @using Umbraco.Core.Services;
    
    @{
        Layout = null;
    
        IMediaService mediaService = ApplicationContext.Current.Services.MediaService;
        IContentTypeService contentTypeService = ApplicationContext.Current.Services.ContentTypeService;
    
        IMediaType fileMediaType = contentTypeService.GetMediaType("File");
    }
    <html>
    <head>
        <title>Media Type changer</title>
    </head>
    <body>
        <h1>Convert File children types to File type</h1>
        @foreach (IMediaType subFileType in contentTypeService.GetMediaTypeChildren(fileMediaType.Id))
        {
            <h2>Converting @subFileType.Name to @fileMediaType.Name</h2>
            IEnumerable<IMedia> filesToConvert = mediaService.GetMediaOfMediaType(subFileType.Id);
            int cnt = 0;
            foreach (IMedia file in filesToConvert)
            {
                file.ChangeContentType(fileMediaType);
                mediaService.Save(file);
                cnt++;
                <p>@cnt/@filesToConvert.Count() - @file.Name converted to @fileMediaType.Name</p>
            }
        }
    </body>
    </html>
    
Please Sign in or register to post replies

Write your reply to:

Draft