I'm using Tridion 2011's Event System to perform some additional actions when un-publishing components. I'm using code found here to publish a related component.
I'm registering my event handler as follows:
EventSystem.Subscribe<Component, UnPublishEventArgs>(
RemoveAndRepublish, EventPhases.Initiated);
... and my handler method is as follows:
public void RemoveAndRepublish(Component cmp, UnPublishEventArgs args,
EventPhases phase)
{
// ... code to locate related component, and perform required actions...
var instruction = new PublishInstruction(cmp.Session)
{
DeployAt = DateTime.Now,
RenderInstruction = new RenderInstruction(cmp.Session)
{
RenderMode = RenderMode.Publish
},
ResolveInstruction = new ResolveInstruction(cmp.Session)
{
IncludeComponentLinks = true
},
RollbackOnFailure = true,
StartAt = DateTime.MinValue
};
var target = args.Targets.FirstOrDefault();
PublishEngine.Publish(new[] {related}, instruction, new[] {target});
}
My problem is that the UnPublishEventArgs.Targets
property is an IList<PublishingTarget>
, which at runtime turns out to be a List<TargetType>
, and I need to get a PublicationTarget
object to be able to call PublishEngine.Publish(...)
.
My question is: is there a way to get the current (un-)PublicationTarget from an UnPublish event?
Can anyone offer any help?
PublishEngine.Publish
method takes anIEnumerable<PublicationTarget>
notIEnumerable<PublishingTarget>
. – Aveyron