Copied to clipboard

Flag this post as spam?

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


  • ReneRam 21 posts 186 karma points
    Jan 18, 2022 @ 18:20
    ReneRam
    0

    node.IsDraft() is always False

    Hi. I'm trying to execute an action from the ModelsBuider only when a node (document) is published and not having execute when the Editor Unpublishes it. When I check the status I always get that IsDraft() is false.

    How can I check if the node is been set in Draft.

    Thanks

  • ReneRam 21 posts 186 karma points
    Jan 19, 2022 @ 08:47
    ReneRam
    0

    Further on... this is dummy code I'm testing trying to figure out what's wrong:

            private static void ExecWhenUnpublished(IPublishedContent node)
        {
    
            // write only visible nodes
            bool published = node.IsPublished();    //always true
            bool drafted = node.IsDraft();          //always false even if node is Draft
            bool visible = node.IsVisible();        //always true even if node is Draft
    
            if (published && drafted == false && visible)
            {
                   // whatever
                }
            }
        }
    
            public class SubscribeToUnpublishedEventComponent : IComponent
        {
            /// <summary>
            /// Initialize: runs once when Umbraco starts
            /// </summary>
            public void Initialize()
            {
                ContentService.Unpublished += ContentService_Unpublished;
            }
    
    
            /// <summary>
            /// Terminate: runs once when Umbraco stops
            /// </summary>
            public void Terminate()
            {
                ContentService.Unpublished -= ContentService_Unpublished;
            }
    
            /// <summary>
            /// Write sitemap.xml in Media\_sitemap
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void ContentService_Unpublished(IContentService sender, PublishEventArgs<IContent> e)
            {
                // whatever
    
            }
    
        }
    

    Any help areciated

  • ReneRam 21 posts 186 karma points
    Apr 07, 2022 @ 06:59
    ReneRam
    100

    Found a workaround without checking the node status. Issue not solved but closed for me.

Please Sign in or register to post replies

Write your reply to:

Draft