Copied to clipboard

Flag this post as spam?

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


  • Neil Chapman 42 posts 169 karma points
    Aug 03, 2021 @ 08:51
    Neil Chapman
    0

    Multi language doc type always IsDirty when updated through ContentService

    Hi all,

    I have 2 languages set up, English (default) and Chinese.

    I have a service which processes a daily feed and creates/updates node data accordingly via the ContentService.

    I am only interested in updating/publishing the English version through the Content Service. Most properties are invariant but there are some variant properties.

    I'm creating a new node for the default culture, like below, or getting the existing node if it already exists:

    node = new Content("name", parentId, contentType, "en-US");
    

    I am setting my invariant properties like so:

    node.SetValue("propertyAlias", "propertyValue");
    

    I am defining the culture on my variant properties like so:

    node.SetValue("propertyAlias", "propertyValue", "en-US");
    

    Because the service runs daily, I only want to save/publish a node if it is dirty for performance.

    If I do node.IsDirty();, it's always true, even when no properties have changed, and CultureInfos is always the only dirty property. Inspecting node.CultureInfos it just returns an array ["Umbraco.Core.Models.ContentCultureInfos"] which doesn't feel correct. Even using node.IsCultureEdited("en-US"); also always returns true.

    I don't know how to get around this IsDirty() always being true. Am I setting my values wrong for invariant cultures, or missing something?

    Any help/advice would be greatly appreciated.

    Thanks

  • Neil Chapman 42 posts 169 karma points
    Aug 03, 2021 @ 14:16
    Neil Chapman
    0

    Further to this, inspecting the raw node data in the database, the only change is to this dt value in the cd property, which i'm assuming is something to do with the CultureInfos property.

    First update:

    "cd":{"en-us":{"nm":"Node name","us":"node-slug","dt":"2021-08-03T15:00:42.6583768+01:00","isd":true}},"us":"node-slug"
    

    Second update:

    "cd":{"en-us":{"nm":"Node name","us":"node-slug","dt":"2021-08-03T15:01:51.7902586+01:00","isd":true}},"us":"node-slug"
    

    The dt value can't be set on every save/publish otherwise nodes would always be dirty...

  • Mats Stam 61 posts 210 karma points
    Aug 16, 2021 @ 14:39
    Mats Stam
    0

    You could mayhaps try the IRememberBeingDirty interface?

    var test = (IRememberBeingDirty)node;
    var testDirty = test.IsDirty(); //This should be true if a property is dirty, and false if nothing has changed...
    

    I do not know why there is a need for IRememberBeingDirty though. Since it seems kind of strange to keep an IsDirty() on IContent that doesn't do what it appears it's supposed to do...

    Anyways, hope this helps :)

Please Sign in or register to post replies

Write your reply to:

Draft