I have created an event system which creates a page when a component is created, and publishes that page. I want to publish it from the publication where the page is created, with the IncludeChildPublications setting set to true. I have 18 child publications, and I have verified that publishing works for all of them.
This is my code:
RenderInstruction renderInstruction = new RenderInstruction(component.Session) { RenderMode = RenderMode.Publish };
ResolveInstruction resolveInstruction = new ResolveInstruction(component.Session) { IncludeChildPublications = true, OnlyPublishedItems = false };
PublishInstruction publishInstruction = new PublishInstruction(component.Session) { ResolveInstruction = resolveInstruction, RenderInstruction = renderInstruction };
PublishEngine.Publish(new[] { page }, publishInstruction, new[] { "Staging" });
Note that I publish to the PublishPurpose 'Staging', which is - I guess - the way to go with SDL Web 8. I don't use the legacy mode so the overloads of the Publish method that use PublishingTargets or TargetTypes are presumably not working.
What I find is that the page gets published for one of my child publications, but not for the other 17. When I go to the GUI and publish the page manually (with the 'publish in child publications' setting turned on), the page gets published for all 18 child publications. Clearly something is wrong in the event system.
The Windows event log shows the following warnings when the event system tried to publish the page in all child publications:
No Publish Transactions created for (un-)publish action for Publication 'tcm:0-37-1'. Reason: unable to resolve Target Types for purposes: Staging.
There is one warning for each of the 17 child publications where the item fails to publish.
What's going on here? Should I change my code for publishing the page? Why does it work for this 1 page?