Skip to content

Commit cd83239

Browse files
authored
Fix execution order of workflow content handler to prevent incomplete data (#18173)
1 parent b518437 commit cd83239

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Startup.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,22 @@ public override void ConfigureServices(IServiceCollection services)
2828
services.AddActivity<RetrieveContentTask, RetrieveContentTaskDisplayDriver>();
2929
services.AddActivity<UpdateContentTask, UpdateContentTaskDisplayDriver>();
3030

31-
services.AddScoped<IContentHandler, ContentsHandler>();
3231
services.AddScoped<IWorkflowValueSerializer, ContentItemSerializer>();
3332
}
3433
}
34+
35+
[RequireFeatures("OrchardCore.Workflows")]
36+
public sealed class ContentHandlerStartup : StartupBase
37+
{
38+
// The order is set to OrchardCoreConstants.ConfigureOrder.WorkflowsContentHandlers to ensure the workflows content
39+
// handler is registered first in the DI container. This causes the workflows content handler to be invoked last
40+
// when content events are triggered, allowing it to access the final state of the content item after all other
41+
// content handlers have executed. Note: handlers are resolved in reverse order, so setting this constant ensures
42+
// this handler runs last during content item created, updated, etc. events.
43+
public override int Order => OrchardCoreConstants.ConfigureOrder.WorkflowsContentHandlers;
44+
45+
public override void ConfigureServices(IServiceCollection services)
46+
{
47+
services.AddScoped<IContentHandler, ContentsHandler>();
48+
}
49+
}

src/OrchardCore/OrchardCore.Abstractions/OrchardCoreConstants.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ public static class ConfigureOrder
7676

7777
// The UrlRewriting module should be registered before any other module that deals with URLs.
7878
public const int UrlRewriting = InfrastructureService + 100;
79+
80+
// The Workflows content handler should be registered before other content handlers to ensure it
81+
// processes content events last.
82+
public const int WorkflowsContentHandlers = InfrastructureService + 100;
7983
}
8084

8185
public static class DisplayType

0 commit comments

Comments
 (0)