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.
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;
}
}
}
is working on a reply...