Copied to clipboard

Flag this post as spam?

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


  • Mike Chambers 636 posts 1253 karma points c-trib
    Jun 13, 2017 @ 11:48
    Mike Chambers
    0

    update to 7.6.2/3 and core property value convertors, id to uid aka mediaPicker to mediaPicker2

    So having to sort the stored Id on a mediaPicker once datatype updated to mediapicker2 property

    RIght click publish all child nodes of root, doesn't udpate the old ids stored to uids. With several thousand news stories with a picked thumbnail individual save and publish wasn't an option..

    So came up with a dirty one off update via a template.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    
    @{
        Layout = null;
    }
    
    
    @{
    
    
        var cs = ApplicationContext.Current.Services.ContentService;
        var ms = ApplicationContext.Current.Services.MediaService;
    
        var collection = cs.GetDescendants(cs.GetRootContent().First().Id);
    
    
    foreach (var item in collection.Where(x => x.ContentType.Name == "Item Dated"))
    {<ul>
            <li>
                <strong>@(item.Name) @("::") @(item.ContentType.Name)</strong>
                <ul>
                    <li>@updatePropertyToUDI(item, "itemThumbnail")</li>
                </ul>
            </li>
        </ul>
        }
    }
    
    
    @helper updatePropertyToUDI(IContent item, string propAlias)
    {
        try
        {
            var cs = ApplicationContext.Current.Services.ContentService;
            var ms = ApplicationContext.Current.Services.MediaService;
            var existing = item.GetValue(propAlias);
            @("["+existing+"]")
            var thumb = item.GetValue<int>(propAlias);        
            if (thumb > 0)
            {
                var mThumb = ms.GetById(thumb);
                    @(" --> umb://media/" + mThumb.Key)
                item.SetValue(propAlias, "umb://media/" + mThumb.Key);
                cs.Publish(item);
            }    
        }
        catch (Exception e)
        {
                @(e.Message)
        }
    }
    

    However, this doesn't fit for when a page is saved, eg edited and not ready for publish... is there any way to republish the published version of a content node?

  • Mike Chambers 636 posts 1253 karma points c-trib
    Jun 13, 2017 @ 12:15
    Mike Chambers
    0

    Thought I might be able to do this with the

    var PubVersionOfItem = cs.GetPublishedVersion(item); and published that IContent Item...

    But whilst this republishes the previously published version.. it also then overwrites any saved but not published changes to the node.

  • Sumesh KP 35 posts 108 karma points c-trib
    Sep 08, 2017 @ 09:26
    Sumesh KP
    0

    Perfect, It Works fine.

    Thanks you @mistyn8

Please Sign in or register to post replies

Write your reply to:

Draft