Copied to clipboard

Flag this post as spam?

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


  • Luke 110 posts 256 karma points
    Mar 16, 2016 @ 14:10
    Luke
    0

    Bulk Updates

    Hi All,

    I have a particular Document Type with certain properties that I need to update as a bulk operation - what is the best and most efficient way?

    Regards, L

  • Greg Fyans 140 posts 342 karma points
    Mar 16, 2016 @ 14:35
    Greg Fyans
    0

    You can use a package like CMS Import to do it all via the UI, or programmatically you can do something like this:

    IContentService cs = ApplicationContext.Services.ContentService;
    
    IEnumerable<IContent> affectedContent = cs.GetContentOfContentType(1234);
    
    foreach (IContent content in affectedContent)
    {
        foreach (PropertyType pt in content.PropertyTypes)
        {
            switch (pt.Alias)
            {
                case "propertyAlias1":
                    foreach (Property p in content.Properties.Where(x => x.PropertyType.Id == pt.Id))
                    {
                        content.SetValue(p.Alias, "New value");
                    }
    
                    break;
                case "propertyAlias2":
                    foreach (Property p in content.Properties.Where(x => x.PropertyType.Id == pt.Id))
                    {
                        content.SetValue(p.Alias, "New value");
                    }
    
                    break;
            }
        }
    
        if (content.Published)
        {
            cs.SaveAndPublishWithStatus(content, 0, false);
        }
        else
        {
            cs.Save(content, 0, false);
        }
    }
    
  • Simon Dingley 1474 posts 3431 karma points c-trib
    Apr 21, 2017 @ 13:08
    Simon Dingley
    0

    Is this really the most efficient way?

    I've been giving this quite a bit of thought recently as I have a large load balanced site that imports around 1000 nodes at a time from a SalesForce instance and this approach is slow and costly but I can see no other way around it at the moment. It massively impacts the site because each publish action drops the cache and triggers all of the required event handlers (this is required but would rather it were performed in a single hit)!

    What I would like to do is perform the updates and save changes then pass all Id's to a method that would bulk publish them but on last check this was not possible?

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Apr 21, 2017 @ 16:27
    Simon Dingley
    0

    Further to my previous post and having read Stephen's comments here https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/75657-deadlocks-and-disappearing-content - I am of the opinion that there is no safe way currently to bulk publish documents.

    ...but there is hope yet, I want to give Publication Queue a chance to see if it can help:

    https://our.umbraco.org/projects/backoffice-extensions/publication-queue/

    Simon

Please Sign in or register to post replies

Write your reply to:

Draft