Update:
*Note that, I didn't get a chance to execute it. So the code is Un-TestedToday I got a chance to test my code. After testing the code, I realised that where I have done the mistake.
To delete the PublishTransaction
, you need to Subscribe
an Event
in Processed
Phase.
Below is modified code, which works perfectly:
public EventSystemHandler()
{
EventSystem.Subscribe<Page, UnPublishEventArgs>(StopUnPublishing, EventPhases.Processed);
EventSystem.Subscribe<Component, UnPublishEventArgs>(StopUnPublishing, EventPhases.Processed);
}
public void StopUnPublishing(IdentifiableObject mIdentifiableObject, UnPublishEventArgs mUnPublishEventArgs, EventPhases mEventPhases)
{
List<IdentifiableObject> mListIdentifiableObject = new List<IdentifiableObject>();
List<PublishTransaction> mPublishTransactionList = mUnPublishEventArgs.PublishTransactions.ToList();
foreach (PublishTransaction mPublishTransaction in mPublishTransactionList)
{
foreach (IdentifiableObject identifiableObject in mPublishTransaction.Items)
{
mListIdentifiableObject.Add(identifiableObject);
}
mPublishTransaction.Delete();
}
// Create Bundle and Starts the workflow
StartBundleWorkFlow("tcm:26-172-8192", mListIdentifiableObject);
}