Reputation: 10234
In Tridion 2011 SP1 I'm trying to implement an event that will publish items automatically whenever the editor presses Save & Close (but not Save).
Under normal conditions this could be handled in a CheckIn event, but because this item will probably be in workflow, there is no CheckIn event (yet).
In COM Events we had a flag (doneEditing) to tell us if the editor had pressed save & close vs Save. I don't seem to be able to find a similar option in TOM.NET Events.
For reference - here's the code so far:
[TcmExtension("Publish to Wip Events")]
public class PublishToWip : TcmExtension
{
public PublishToWip()
{
EventSystem.SubscribeAsync<VersionedItem, SaveEventArgs>(PublishItemToWip, EventPhases.TransactionCommitted);
}
private void PublishItemToWip(VersionedItem item, SaveEventArgs args, EventPhases phases)
{
// Magic goes here
}
}
I've looked at the options for SaveEventArgs, but haven't found anything that would provide me this information. Any tips?
Upvotes: 6
Views: 490
Reputation: 10234
Alright, with some help from the CM team I got the right answer to this.
Use the CheckInEvent instead of save. Even if the item is in workflow it will still invoke this event when you click Save & Close (and only if you click Save & Close, not when you click Save).
Something like this will get me going:
[TcmExtension("Publish to Wip Events")]
public class PublishToWip : TcmExtension
{
public PublishToWip()
{
EventSystem.Subscribe<VersionedItem, CheckInEventArgs>
(PublishItemToWip, EventPhases.Processed);
}
private void PublishItemToWip(VersionedItem item,
CheckInEventArgs args, EventPhases phases)
{
if (!item.LockType.HasFlag(LockType.InWorkflow)) return;
if (!item.IsCheckedOut) return;
// do something now
Upvotes: 5
Reputation: 21
In order to catch item finished workflow you need to subscribe to FinishProcess event on the Process, not on the component:
EventSystem.SubscribeAsync<Process, FinishProcessEventArgs>(FinishProcessHandler, EventPhases.TransactionCommitted, EventSubscriptionOrder.Late);
In the event handler Process instance will contain list of Subjects with the versioned item finished workflow - the one you want to publish:
private static void FinishProcessHandler(Process process, FinishProcessEventArgs e, EventPhases phase)
{
foreach (var itemInWorkflow in process.Subjects)
{
//publish
}
}
Upvotes: -1
Reputation: 2407
I was looking at this in the past, but I couldn't find a suitable solution. In the end I gave up.
The idea I had was to have a GUI extension to intercept the Save and as such write an AppData entry for that item saying it was a Save or a SaveClose. Then your event system would read the AppData and act accordingly.
Don't forget to clean up the AppData in your event code.
Upvotes: 2