Copied to clipboard

Flag this post as spam?

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


  • Jay 425 posts 652 karma points
    Mar 31, 2016 @ 13:04
    Jay
    0

    SaveAndPublishWithStatus set to false but still raised Publishing event

    Hi All,

    I'm running Umbraco V7.3.1 and I'm detecting the ContentService.Published event on Content Node.

    All I need is to detect the publishing event on specific DocTypes. Make some properties changes and then save and publish it. But It ended up in a loop of event publishing detection even when i have my .SaveAndPublishWithStatus raiseEvent set to false. Any idea anyone?

    Thanks

    public class RegisterEvents : ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase httpApplicationBase, ApplicationContext applicationContext)
            {            
                    ContentService.Published += Proj_ContentServicePublished;            
            }
    
            private static void Proj_ContentServicePublished(IPublishingStrategy sender, PublishEventArgs<IContent> args)
            {
            var contentService = ApplicationContext.Current.Services.ContentService;
    
            foreach (var projNode in args.PublishedEntities.Where(node => node.ContentType.Alias == "something"))
                    {
                // Update some properties
                projNode.SetValue("booleanValue", true);
    
                // Then save and publish
                contentService.SaveAndPublishWithStatus(projNode, 0, false);
            }
        }
    }
    
  • Marc Goodson 2149 posts 14377 karma points MVP 9x c-trib
    Apr 02, 2016 @ 11:33
    Marc Goodson
    1

    Hi Jlon

    Having a quick look at the source for the content service, I think setting RaiseEvents to false only prevents the raising of Saving events, so it seems the publish events still fire... (so do you check to see if the property is set before setting it again as a work around ?)

    or what you are trying to achieve, would it work if you moved the code to the Saving event ?

       void ContentService_Saving(IContentService sender, Umbraco.Core.Events.SaveEventArgs<IContent> e)
            {
       foreach (var projNode in e.SavedEntities.Where(node => node.ContentType.Alias == "something"))
                {
                    projNode.SetValue("booleanValue", true);
                }
    }
    

    Because then you wouldn't need to call SaveAndPublishWithStatus from within the Published event.

Please Sign in or register to post replies

Write your reply to:

Draft