Publishing from the AfterPublish event yields strange results
Given a certain type of document, I want to publish its children once it itself is published. So I made class that inherits from ApplicationBase and wire up and event to Documet.AfterPublish from there I execute this code:
void Document_AfterPublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e) { if (sender.ParentId == templateStructuresNodeId) return; var templateNode = TemplateStructures.Children.SingleOrDefault(i => i.ContentType.Alias == sender.ContentType.Alias); if (templateNode != null) { foreach (var child in sender.Children) { if (!child.Published) { child.Publish(User.GetCurrent()); umbraco.library.UpdateDocumentCache(child.Id); } } } }
The problem is that once this code runs the children appear to be published, but if you examine them int he back office the Link to Document is listed as # If I take the publishing code and just run it as a the result of a button click on a test page everything works fine. The child items are published and their link url's are listed correctly. What could be the problem?
I once ran into a similar issue - to fix, try using umbraco.content.AfterUpdateDocumentCache instead of Document.AfterPublish. I think the document is not fully published in AfterPublish - it's not added to the cache yet, so the children have trouble publishing if you call them from here. Here's a thread that explains it a bit
Publishing from the AfterPublish event yields strange results
Given a certain type of document, I want to publish its children once it itself is published. So I made class that inherits from ApplicationBase and wire up and event to Documet.AfterPublish from there I execute this code:
The problem is that once this code runs the children appear to be published, but if you examine them int he back office the Link to Document is listed as # If I take the publishing code and just run it as a the result of a button click on a test page everything works fine. The child items are published and their link url's are listed correctly. What could be the problem?
Hi,
I once ran into a similar issue - to fix, try using umbraco.content.AfterUpdateDocumentCache instead of Document.AfterPublish. I think the document is not fully published in AfterPublish - it's not added to the cache yet, so the children have trouble publishing if you call them from here. Here's a thread that explains it a bit
Hope this helps,
Tom
is working on a reply...