Copied to clipboard

Flag this post as spam?

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


  • pantryfight 60 posts 84 karma points
    May 05, 2016 @ 02:09
    pantryfight
    0

    Changing templateID after import

    I know this package hasn't been touched in a while, however I just found it and it has been very useful for migrating some content between an old Umbraco 6 install and Umbraco 7 for us.

    One thing I was wondering however is if it's possible to automate a change to the template for selected document types after your import.

    It's my understanding that the new nodes created by uMirror are created with the document type's default template. Is it possible for these nodes to somehow be set to a different template instead?

    I've tried using a proxy to change the template ID but it seems that template ID gets ignored during the import... and fair enough since the ID would almost certainly be different between umbraco versions...

  • pantryfight 60 posts 84 karma points
    May 05, 2016 @ 05:35
    pantryfight
    0

    It's alright, I worked it out! Found the Syncronizer.change_sync event was being fired on import and switched the template there. yay.

    protected override void ApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            Lecoati.uMirror.Core.Synchronizer.change_sync += Synchronizer_change_sync;
            base.ApplicationInitialized(umbracoApplication, applicationContext);
        }
    
        private void Synchronizer_change_sync(Lecoati.uMirror.Core.Synchronizer.operationType operation, object item)
        {
            if(item != null)
            {
                var cs = ApplicationContext.Current.Services.ContentService;
                var nonRespTemplate = ApplicationContext.Current.Services.FileService.GetTemplate("NonResponsivePage");
    
                if (item is IContent && nonRespTemplate != null)
                {
                    var content = item as IContent;
                    content.Template = nonRespTemplate;
                    cs.Save(content);                    
                }
            }
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft