Copied to clipboard

Flag this post as spam?

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


  • Bear 40 posts 129 karma points
    Sep 12, 2013 @ 13:35
    Bear
    0

    V6 Events : Saving, Moving and raiseEvents?

    I'm trying to move a node via the following code.

    public class RegisterUmbracoEvents : ApplicationEventHandler
        {
    
            public RegisterUmbracoEvents()
            {
                ContentService.Saved += Save;
            }
    
            private void Save(IContentService contentService, SaveEventArgs<IContent> saveEventArgs)
            {
    
                foreach (var node in saveEventArgs.SavedEntities)
                {
                    // is the item pending?
                    if (node.Pending())
                    {
                        // is it already in the pending folder?
                        if (node.ParentId != (int)FolderNodeIds.Pending)
                        {
    
                            // no, so move it to the pending folder
                            contentService.Move(node, (int)FolderNodeIds.Pending);
                        }
    
                    }
                    else
                    {
                        // otherwise, move to other known folder
                        contentService.Move(node, 2459);
                    }
                }
            }
    
        }
    

    The last line contentService.Move(node, 2459); keeps raising the event causing a stack overflow.

    I could check on the second time if the parent node id is 2459, but is there any way to say "stop raising these events now"?

  • John Walker 41 posts 136 karma points
    Sep 12, 2013 @ 14:12
    John Walker
    0

    Could you not set the ParentId to the new folder '2459' instead of using the move and then call save without rasing events contentService.Save(node, 0, false);

    John

  • Bear 40 posts 129 karma points
    Sep 12, 2013 @ 14:19
    Bear
    0

    Thanks John,

    That seems to be a better way. I'll have a further play, but this works for now! Cheers.

    else
    {
        // otherwise, move to other known folder
        node.ParentId = 2459;
        contentService.Save(node, 0, false);
    }
    
  • John Walker 41 posts 136 karma points
    Sep 12, 2013 @ 14:24
    John Walker
    0

    No problem, let me know if you find a better way.

Please Sign in or register to post replies

Write your reply to:

Draft