Skip to content

Instantly share code, notes, and snippets.

@willprice76
Created March 19, 2014 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willprice76/9639405 to your computer and use it in GitHub Desktop.
Save willprice76/9639405 to your computer and use it in GitHub Desktop.
SDL Tridion Event handler to allow you to publish in child publications without publishing from the parent. Note that this approach can lead to Warning messages in the event log, if this is a problem then you need a combined event/resolver solution: see https://gist.github.com/willprice76/9664092
using System;
using System.Collections.Generic;
using Tridion.ContentManager.Extensibility;
using Tridion.ContentManager.Extensibility.Events;
using Tridion.ContentManager.Publishing;
namespace Example.Events
{
[TcmExtension("Publish Events Example")]
public class Events : TcmExtension
{
public Events()
{
EventSystem.Subscribe<PublishTransaction, SaveEventArgs>(DeleteMasterPublishTransaction, EventPhases.TransactionCommitted);
}
/// <summary>
/// Delete publish transactions in master publications. This enables you to have publish in child publications
/// functionality for parent publication(s) which are not normally publishable. Simply configure a target for
/// the parent publication(s), and this event will make sure that nothing is ever published there from the parent
/// By deleting the transaction before it is resolved/rendered
/// </summary>
private void DeleteMasterPublishTransaction(PublishTransaction transaction, SaveEventArgs args, EventPhases phases)
{
List<int> masterPublications = new List<int> { 18, 20 };//Load your master publication ids in from config however you like
foreach (var context in transaction.PublishContexts)
{
if (masterPublications.Contains(context.Publication.Id.ItemId))
{
transaction.Delete();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment