Copied to clipboard

Flag this post as spam?

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


  • Ross 3 posts 73 karma points
    Oct 22, 2015 @ 18:22
    Ross
    0

    Prevent SaveAndPublishWithStatus from changing last edited date

    Hi,

    I am using the ContentService.Publishing event to update some fields in the parent node when the child node is published. This is working though I am finding that the Last Edited date on the parent is being updated automatically. Is there anyway I can avoid this happening? Snippet below:

    private void ContentServicePublished(IPublishingStrategy sender, PublishEventArgs<IContent> e)
            {
                foreach (var node in e.PublishedEntities)
                {
                    if (node.ContentType.Alias == "DiscussionReply")
                    {
                        var contentService = new Umbraco.Core.Services.ContentService();
                        var parentNode = contentService.GetById(node.ParentId);
    
                        int intSiblings = parentNode.Children().Count() + 1;
                        string strTitle = parentNode.Name;
    
                        if(parentNode.HasProperty("siblings"))
                        {
                            parentNode.SetValue("siblings", intSiblings);
                            contentService.SaveAndPublishWithStatus(parentNode);
                        }
                    }
                }
            }
    
  • Daniel Dewhurst 3 posts 72 karma points
    Oct 03, 2019 @ 08:42
    Daniel Dewhurst
    0

    Bump. I'm trying to work this out too.

  • Mila Pandurska 75 posts 354 karma points
    Oct 04, 2019 @ 12:24
    Mila Pandurska
    0

    Hi Ross,

    I had the same issue and I didn't find a way to prevent updateting the updateDate field of the parent node. From my previous research I understand that this system field is not supposed to be used for business logic. When you publish item via contentService.SaveAndPublishWithStatus(parentNode); a lot of thing happens behind - a new version of the node is created (see your versions) and a record is created in the Authid trail.

    In my case I change my business logic to not work with this date. If you have an option just create new custom field - myLastUpdateDate and work with this field instead of updateDate.

    Mila

Please Sign in or register to post replies

Write your reply to:

Draft