diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentActivity.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentActivity.cs index d733a8426bf..ecf1874f896 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentActivity.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentActivity.cs @@ -79,7 +79,19 @@ public override async Task OnWorkflowRestartingAsync(WorkflowExecutionContext wo if (workflowContext.Input.TryGetValue(ContentEventConstants.ContentEventInputKey, out var contentEvent)) { - var contentEventContext = ((JsonObject)contentEvent).ToObject(); + if (contentEvent is not JsonObject jsonObject) + { + jsonObject = []; + if (contentEvent is Dictionary items) + { + foreach (var item in items) + { + jsonObject[item.Key] = JsonSerializer.SerializeToNode(item.Value); + } + } + } + + var contentEventContext = jsonObject.ToObject(); if (contentEventContext?.ContentItemVersionId != null) { @@ -93,11 +105,23 @@ public override async Task OnWorkflowRestartingAsync(WorkflowExecutionContext wo if (contentItem == null && workflowContext.Input.TryGetValue(ContentEventConstants.ContentItemInputKey, out var contentItemEvent)) { - var item = ((JsonObject)contentItemEvent).ToObject(); + if (contentItemEvent is not JsonObject jsonObject) + { + jsonObject = []; + if (contentEvent is Dictionary items) + { + foreach (var item in items) + { + jsonObject[item.Key] = JsonSerializer.SerializeToNode(item.Value); + } + } + } + + var existingContentItem = jsonObject.ToObject(); - if (item?.ContentItemId != null) + if (existingContentItem?.ContentItemId != null) { - contentItem = await ContentManager.GetAsync(item.ContentItemId); + contentItem = await ContentManager.GetAsync(existingContentItem.ContentItemId); } } @@ -135,8 +159,8 @@ protected virtual async Task GetContentAsync(WorkflowExecutionContext else { // If no expression was provided, see if the content item was provided as an input or as a property. - content = workflowContext.Input.GetValue(ContentEventConstants.ContentItemInputKey) - ?? workflowContext.Properties.GetValue(ContentEventConstants.ContentItemInputKey); + content = workflowContext.Input.GetValue(ContentEventConstants.ContentItemInputKey) + ?? workflowContext.Properties.GetValue(ContentEventConstants.ContentItemInputKey); } if (content?.ContentItem?.ContentItemId != null) diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UpdateContentTask.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UpdateContentTask.cs index bbe8a56ed67..8190b52a9d8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UpdateContentTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UpdateContentTask.cs @@ -98,7 +98,7 @@ public async override Task ExecuteAsync(WorkflowExecuti } else { - contentItem = workflowContext.Input.GetValue(ContentEventConstants.ContentItemInputKey)?.ContentItem; + contentItem = workflowContext.Input.GetValue(ContentEventConstants.ContentItemInputKey)?.ContentItem; } if (contentItem == null) diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Handlers/ContentsHandler.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Handlers/ContentsHandler.cs index 8b7f8d7e3fb..51f1cff6830 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Handlers/ContentsHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Handlers/ContentsHandler.cs @@ -66,7 +66,7 @@ private Task> TriggerWorkflowEventAsync(st var input = new Dictionary { { ContentEventConstants.ContentItemInputKey, contentItem }, - { ContentEventConstants.ContentEventInputKey, contentEvent } + { ContentEventConstants.ContentEventInputKey, contentEvent }, }; return _workflowManager.TriggerEventAsync(name, input, correlationId: contentItem.ContentItemId); diff --git a/src/OrchardCore.Modules/OrchardCore.Workflows/UserTasks/Drivers/UserTaskEventContentDriver.cs b/src/OrchardCore.Modules/OrchardCore.Workflows/UserTasks/Drivers/UserTaskEventContentDriver.cs index 7b91a897e59..23515c7193e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Workflows/UserTasks/Drivers/UserTaskEventContentDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Workflows/UserTasks/Drivers/UserTaskEventContentDriver.cs @@ -93,7 +93,7 @@ public override async Task UpdateAsync(ContentItem model, IUpdat { { ContentEventConstants.UserActionInputKey, action }, { ContentEventConstants.ContentItemInputKey, model }, - { ContentEventConstants.ContentEventInputKey, contentEvent } + { ContentEventConstants.ContentEventInputKey, contentEvent }, }; await _workflowManager.TriggerEventAsync(nameof(UserTaskEvent), input, correlationId: model.ContentItemId); diff --git a/src/OrchardCore/OrchardCore.Workflows.Abstractions/Helpers/DictionaryExtensions.cs b/src/OrchardCore/OrchardCore.Workflows.Abstractions/Helpers/DictionaryExtensions.cs index 655972a33e3..fda94622fd8 100644 --- a/src/OrchardCore/OrchardCore.Workflows.Abstractions/Helpers/DictionaryExtensions.cs +++ b/src/OrchardCore/OrchardCore.Workflows.Abstractions/Helpers/DictionaryExtensions.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Text.Json; namespace OrchardCore.Workflows.Helpers { @@ -25,14 +24,7 @@ public static TValue GetValue(this IDictionary dictionar return default; } - if (value is not TValue castedValue) - { - var json = JConvert.SerializeObject(value); - - return JConvert.DeserializeObject(json); - } - - return castedValue; + return (TValue)value; } ///