diff --git a/src/Orchard.Web/Modules/Orchard.Workflows/Activities/ContentActivity.cs b/src/Orchard.Web/Modules/Orchard.Workflows/Activities/ContentActivity.cs index eb69fe0ba..67c8437bb 100644 --- a/src/Orchard.Web/Modules/Orchard.Workflows/Activities/ContentActivity.cs +++ b/src/Orchard.Web/Modules/Orchard.Workflows/Activities/ContentActivity.cs @@ -78,6 +78,16 @@ namespace Orchard.Workflows.Activities { } } + public class ContentFirstUpdatedActivity : ContentActivity { + public override string Name { + get { return "ContentFirstUpdated"; } + } + + public override LocalizedString Description { + get { return T("Content is updated for the first time."); } + } + } + public class ContentPublishedActivity : ContentActivity { public override string Name { get { return "ContentPublished"; } diff --git a/src/Orchard.Web/Modules/Orchard.Workflows/Handlers/WorkflowContentHandler.cs b/src/Orchard.Web/Modules/Orchard.Workflows/Handlers/WorkflowContentHandler.cs index 378b83e0a..76a32f42b 100644 --- a/src/Orchard.Web/Modules/Orchard.Workflows/Handlers/WorkflowContentHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Workflows/Handlers/WorkflowContentHandler.cs @@ -6,8 +6,16 @@ using Orchard.Workflows.Services; namespace Orchard.Workflows.Handlers { public class WorkflowContentHandler : ContentHandler { + // Used to memorize the ids of ContentItems for which we go through the + // OnCreated handler. + private HashSet _createdItems; + // Used to memorize the ids of ContentItems for which we go through the + // OnUpdated handler. + private HashSet _updatedItems; public WorkflowContentHandler(IWorkflowManager workflowManager) { + _createdItems = new HashSet(); + _updatedItems = new HashSet(); OnPublished( (context, part) => @@ -34,9 +42,15 @@ namespace Orchard.Workflows.Handlers { () => new Dictionary { { "Content", context.BuildingContentItem } })); OnCreated( - (context, part) => + (context, part) => { + + if (context.ContentItem != null) { // sanity check + _createdItems.Add(context.ContentItem.Id); + } + workflowManager.TriggerEvent("ContentCreated", context.ContentItem, - () => new Dictionary { { "Content", context.ContentItem } })); + () => new Dictionary { { "Content", context.ContentItem } }); + }); OnUpdated( (context, part) => { @@ -44,11 +58,28 @@ namespace Orchard.Workflows.Handlers { return; } + if (context.ContentItem != null) { // sanity check + if (!_updatedItems.Contains(context.ContentItem.Id)) { + // in case a further update is invoked, this would prevent + // the FirstUpdate event to be fired again + _updatedItems.Add(context.ContentItem.Id); + if (_createdItems.Contains(context.ContentItem.Id)) { + // first update after creation of item + workflowManager.TriggerEvent( + "ContentFirstUpdated", + context.ContentItem, + () => new Dictionary { { "Content", context.ContentItem } } + ); + } + } + } + workflowManager.TriggerEvent( "ContentUpdated", context.ContentItem, () => new Dictionary { { "Content", context.ContentItem } } ); + }); } }