mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Added an event activity for workflows that activates on the first Upd… (#8438)
This commit is contained in:
parent
6e410a321d
commit
d3aca80447
@ -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 class ContentPublishedActivity : ContentActivity {
|
||||||
public override string Name {
|
public override string Name {
|
||||||
get { return "ContentPublished"; }
|
get { return "ContentPublished"; }
|
||||||
|
@ -6,8 +6,16 @@ using Orchard.Workflows.Services;
|
|||||||
namespace Orchard.Workflows.Handlers {
|
namespace Orchard.Workflows.Handlers {
|
||||||
|
|
||||||
public class WorkflowContentHandler : ContentHandler {
|
public class WorkflowContentHandler : ContentHandler {
|
||||||
|
// Used to memorize the ids of ContentItems for which we go through the
|
||||||
|
// OnCreated handler.
|
||||||
|
private HashSet<int> _createdItems;
|
||||||
|
// Used to memorize the ids of ContentItems for which we go through the
|
||||||
|
// OnUpdated handler.
|
||||||
|
private HashSet<int> _updatedItems;
|
||||||
|
|
||||||
public WorkflowContentHandler(IWorkflowManager workflowManager) {
|
public WorkflowContentHandler(IWorkflowManager workflowManager) {
|
||||||
|
_createdItems = new HashSet<int>();
|
||||||
|
_updatedItems = new HashSet<int>();
|
||||||
|
|
||||||
OnPublished<ContentPart>(
|
OnPublished<ContentPart>(
|
||||||
(context, part) =>
|
(context, part) =>
|
||||||
@ -34,9 +42,15 @@ namespace Orchard.Workflows.Handlers {
|
|||||||
() => new Dictionary<string, object> { { "Content", context.BuildingContentItem } }));
|
() => new Dictionary<string, object> { { "Content", context.BuildingContentItem } }));
|
||||||
|
|
||||||
OnCreated<ContentPart>(
|
OnCreated<ContentPart>(
|
||||||
(context, part) =>
|
(context, part) => {
|
||||||
|
|
||||||
|
if (context.ContentItem != null) { // sanity check
|
||||||
|
_createdItems.Add(context.ContentItem.Id);
|
||||||
|
}
|
||||||
|
|
||||||
workflowManager.TriggerEvent("ContentCreated", context.ContentItem,
|
workflowManager.TriggerEvent("ContentCreated", context.ContentItem,
|
||||||
() => new Dictionary<string, object> { { "Content", context.ContentItem } }));
|
() => new Dictionary<string, object> { { "Content", context.ContentItem } });
|
||||||
|
});
|
||||||
|
|
||||||
OnUpdated<ContentPart>(
|
OnUpdated<ContentPart>(
|
||||||
(context, part) => {
|
(context, part) => {
|
||||||
@ -44,11 +58,28 @@ namespace Orchard.Workflows.Handlers {
|
|||||||
return;
|
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<string, object> { { "Content", context.ContentItem } }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
workflowManager.TriggerEvent(
|
workflowManager.TriggerEvent(
|
||||||
"ContentUpdated",
|
"ContentUpdated",
|
||||||
context.ContentItem,
|
context.ContentItem,
|
||||||
() => new Dictionary<string, object> { { "Content", context.ContentItem } }
|
() => new Dictionary<string, object> { { "Content", context.ContentItem } }
|
||||||
);
|
);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user