Copied to clipboard

Flag this post as spam?

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


  • Sivasamy 13 posts 33 karma points
    May 22, 2015 @ 12:07
    Sivasamy
    0

    During publish updating parent id on a node creates duplicate

    Hi,

    Writing a handler here that should move the content node under Archive node if the flag is selected on content. On handler code when I set parent ID of the current node to Archive node there is a copy/duplicate created for the current node under it. Node on the parent stays as is and it only gets removed when Umbraco.config is removed and recreated.

    I am handling Publishing event and updating the node that is getting published (work is on Umbraco 7.2.4).

    Tried calling following two lines as well but doesn't get the content tree refreshed as a whole.

    umbraco.library.UpdateDocumentCache(node.Id);

    umbraco.library.RefreshContent();

    Please give us your thoughts.

    Pasting the code that does the logic below.

     protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)

            {

                ContentService.Publishing += ContentServicePublished;

            }

     

     

            private void ContentServicePublished(IPublishingStrategy sender, PublishEventArgs e)

            {

                umbraco.BusinessLogic.Log.Add(LogTypes.Publish, 0, "Document_AfterPublish Executed in OnPublishContentHandler");

                foreach (var node in e.PublishedEntities)

                {

                    if (node.ContentType.Alias == "News")

                    {

                        //This process is for news article updated under news root.

                        int archiveNodeId = Convert.ToInt32(GetFromConfig("NewsArchiveNodeId"));

     

                        if (node.GetValue("setAsArchive").ToString() == "1")

                        {

                            //Setup parent as the Archive node and do publish

                            node.ParentId = archiveNodeId;

                        }

                        else if (node.ParentId == archiveNodeId)

                        {

                            //If already in archive and archive flag is removed move the node under news root instead of archive

                            int newsRootNodeId = Convert.ToInt32(GetFromConfig("NewsNodeId"));

                            node.ParentId = newsRootNodeId;

                        }

                    }

    }

Please Sign in or register to post replies

Write your reply to:

Draft