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?
Below is the whole list of properties you have in PublishEndRemoteEventArgs
class.
Publish End remote event usually is fired on CD servers. And they should not have any connection to master
database, so it should not be possible to do any other publishing there.
public bool CompareRevisions { get; protected set; }
public bool Deep { get; protected set; }
public DateTime FromDate { get; protected set; }
public string LanguageName { get; protected set; }
public PublishMode Mode { get; protected set; }
public DateTime PublishDate { get; protected set; }
public List<string> PublishingTargets { get; protected set; }
public bool RepublishAll { get; protected set; }
public Guid RootItemId { get; protected set; }
public string SourceDatabaseName { get; protected set; }
public string TargetDatabaseName { get; protected set; }