I'm adding a publish:end method in order to publish particular related items when a items of a certain type are published. I have the OnPublishEnd and the OnPublishEndRemote methods, but I need to make sure to publish to the same publishing targets as the item that was just published. I already have the publisher in the OnPublishEnd event, but I'm not sure how to get it in the remote event:
public void OnPublishEnd(object sender, EventArgs args)
{
var sitecoreArgs = args as Sitecore.Events.SitecoreEventArgs;
if (sitecoreArgs == null)
{
return;
}
var publisher = sitecoreArgs.Parameters[0] as Publisher;
if (publisher == null)
{
return;
}
var rootItem = publisher.Options.RootItem;
if (rootItem.TemplateID == IEventConstants.TemplateId)
{
PublishEventParent(rootItem, publisher);
}
}
public void OnPublishEndRemote(object sender, EventArgs args)
{
var args2 = args as PublishEndRemoteEventArgs;
if (args2 == null)
{
return;
}
Item rootItem = Factory.GetDatabase("web").GetItem(new ID(args2.RootItemId));
if (rootItem.TemplateID == IEventConstants.TemplateId)
{
PublishEventParent(rootItem, ???publisher???);
}
}
public void PublishEventParent(Item item, Publisher publisher)
{
var adHocPage =
item.Axes.GetAncestors().FirstOrDefault(x => x.TemplateID == IAd_Hoc_PageConstants.TemplateId);
if (adHocPage != null)
{
publisher.Publish();
}
}
How can I get the publisher/publishing options/publishing targets in the remote event?