| | | 1 | | using Elsa.Alterations.AlterationTypes; |
| | | 2 | | using Elsa.Alterations.Core.Abstractions; |
| | | 3 | | using Elsa.Alterations.Core.Contexts; |
| | | 4 | | using Elsa.Common.Models; |
| | | 5 | | using Elsa.Workflows.Management; |
| | | 6 | | using JetBrains.Annotations; |
| | | 7 | | using Microsoft.Extensions.DependencyInjection; |
| | | 8 | | |
| | | 9 | | namespace Elsa.Alterations.AlterationHandlers; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Upgrades the version of the workflow instance. |
| | | 13 | | /// </summary> |
| | | 14 | | [UsedImplicitly] |
| | | 15 | | public class MigrateHandler : AlterationHandlerBase<Migrate> |
| | | 16 | | { |
| | | 17 | | /// <inheritdoc /> |
| | | 18 | | protected override async ValueTask HandleAsync(AlterationContext context, Migrate alteration) |
| | | 19 | | { |
| | 1 | 20 | | var workflowDefinitionService = context.ServiceProvider.GetRequiredService<IWorkflowDefinitionService>(); |
| | 1 | 21 | | var definitionId = context.Workflow.Identity.DefinitionId; |
| | 1 | 22 | | var targetVersion = alteration.TargetVersion; |
| | 1 | 23 | | var cancellationToken = context.CancellationToken; |
| | 1 | 24 | | var targetWorkflowDefinition = await workflowDefinitionService.FindWorkflowDefinitionAsync(definitionId, Version |
| | | 25 | | |
| | 1 | 26 | | if (targetWorkflowDefinition == null) |
| | | 27 | | { |
| | 0 | 28 | | context.Fail($"Workflow definition with ID {definitionId} and version {targetVersion} not found"); |
| | 0 | 29 | | return; |
| | | 30 | | } |
| | | 31 | | |
| | 1 | 32 | | var targetWorkflow = await workflowDefinitionService.MaterializeWorkflowAsync(targetWorkflowDefinition, cancella |
| | 1 | 33 | | await context.WorkflowExecutionContext.SetWorkflowGraphAsync(targetWorkflow); |
| | | 34 | | |
| | 1 | 35 | | context.Succeed(); |
| | 1 | 36 | | } |
| | | 37 | | } |