Assuming you are using 2011, you can bind an event handler to the Save publication event and check the status. Then, when the component is not published, you can execute the necessary logic.
public sealed class PublishedToEventHandler: TcmExtension { public PublishedToEventHandler() { EventSystem.SubscribeAsync<PublishTransaction, SaveEventArgs>( (subject, args, phase) => { if (!PublishStransactionStateIsSuccessfullyCompleted(subject)) return; }, EventPhases.TransactionCommitted ); } static bool PublishStransactionStateIsSuccessfullyCompleted(PublishTransaction transaction) { return transaction.State == PublishTransactionState.Success || transaction.State == PublishTransactionState.Warning; } }
Before anything is processed in this event, you can check the Instruction.ResolveInstruction.Purpose property for the transaction to see if you publish the publication when you publish it.
The transaction has a collection of ProcessedItems , each of which contains a page or component in the ResolvedItem.Item property of the ProcessedItem object. When you need a page, you need to get the Components embedded in the page to do something with them.
Let me know if you have more questions.
source share