Skip to content

Commit

Permalink
+ (Workflow) Fixed issue where the 'Process Target Workflow' option o…
Browse files Browse the repository at this point in the history
…n the 'Workflow Set Status' action did not process the selected workflow to completion. (Fixes #5220)
  • Loading branch information
Kwame-Agyei committed Feb 29, 2024
1 parent 6dbdceb commit 7f13dcb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 48 deletions.
@@ -1,4 +1,4 @@
// <copyright>
// <copyright>
// Copyright by the Spark Development Network
//
// Licensed under the Rock Community License (the "License");
Expand Down Expand Up @@ -40,7 +40,7 @@ namespace Rock.Workflow.Action
[WorkflowAttribute( "Activity", "The activity that should be activated", true, fieldTypeClassNames: new string[] { "Rock.Field.Types.WorkflowActivityFieldType" } )]
[WorkflowTextOrAttribute( "Attribute Key to Match", "Attribute Key to Match", "The workflow attribute key to match against in the target workflow.", true, key: "WorkflowAttributeKey" )]
[WorkflowTextOrAttribute( "Attribute Value to Match", "Attribute Value to Match", "The workflow attribute value to match against in the target workflow.", true, key: "WorkflowAttributeValue" )]
[Rock.SystemGuid.EntityTypeGuid( "2F192ADD-3222-4BD9-8E2F-CEF338B97EBD")]
[Rock.SystemGuid.EntityTypeGuid( "2F192ADD-3222-4BD9-8E2F-CEF338B97EBD" )]
public class ActivateOtherActivityOnMatch : ActionComponent
{
/// <summary>
Expand All @@ -64,7 +64,7 @@ public override bool Execute( RockContext rockContext, WorkflowAction action, Ob

var attributeKey = GetAttributeValue( action, "WorkflowAttributeKey", true );
var attributeValue = GetAttributeValue( action, "WorkflowAttributeValue", true );
if ( string.IsNullOrWhiteSpace( attributeKey) || string.IsNullOrWhiteSpace(attributeValue) )
if ( string.IsNullOrWhiteSpace( attributeKey ) || string.IsNullOrWhiteSpace( attributeValue ) )
{
action.AddLogEntry( "Invalid Workflow Property", true );
return false;
Expand All @@ -79,27 +79,30 @@ public override bool Execute( RockContext rockContext, WorkflowAction action, Ob

var entityType = EntityTypeCache.Get( typeof( Rock.Model.Workflow ) );

var workflowIds = new AttributeValueService( rockContext )
// Use new context so only changes made to the activity by this action are persisted
using ( var newRockContext = new RockContext() )
{
var workflowIds = new AttributeValueService( newRockContext )
.Queryable()
.AsNoTracking()
.Where( a => a.Attribute.Key == attributeKey && a.Value == attributeValue && a.Attribute.EntityTypeId == entityType.Id )
.Select(a => a.EntityId);
.Select( a => a.EntityId );

var workflows = new WorkflowService( rockContext )
.Queryable()
//.AsNoTracking()
.Where( w => w.WorkflowType.ActivityTypes.Any( a => a.Guid == activityType.Guid ) && workflowIds.Contains(w.Id) )
.ToList();
var workflows = new WorkflowService( newRockContext )
.Queryable()
.Where( w => w.WorkflowType.ActivityTypes.Any( a => a.Guid == activityType.Guid ) && workflowIds.Contains( w.Id ) )
.ToList();

foreach (var workflow in workflows )
{
WorkflowActivity.Activate( activityType, workflow );
action.AddLogEntry( string.Format( "Activated new '{0}' activity in {1} {2}", activityType.ToString(), workflow.TypeName, workflow.WorkflowId ) );
foreach ( var workflow in workflows )
{
WorkflowActivity.Activate( activityType, workflow, newRockContext );
action.AddLogEntry( string.Format( "Activated new '{0}' activity in {1} {2}", activityType.ToString(), workflow.TypeName, workflow.WorkflowId ) );
}

newRockContext.SaveChanges();
}


return true;
}

}
}
@@ -1,4 +1,4 @@
// <copyright>
// <copyright>
// Copyright by the Spark Development Network
//
// Licensed under the Rock Community License (the "License");
Expand Down Expand Up @@ -36,9 +36,9 @@ namespace Rock.Workflow.Action
[Export( typeof( ActionComponent ) )]
[ExportMetadata( "ComponentName", "Activate Activity in Other Workflow" )]

[WorkflowAttribute("Activity", "The activity that should be activated", true, fieldTypeClassNames: new string[] { "Rock.Field.Types.WorkflowActivityFieldType" } )]
[WorkflowTextOrAttribute("Workflow", "Workflow Attribute", "The ID or Guid of the workflow that should be activated", true, key:"WorkflowReference" )]
[Rock.SystemGuid.EntityTypeGuid( "DD266CDB-7D60-4312-B727-C2AA95C21128")]
[WorkflowAttribute( "Activity", "The activity that should be activated", true, fieldTypeClassNames: new string[] { "Rock.Field.Types.WorkflowActivityFieldType" } )]
[WorkflowTextOrAttribute( "Workflow", "Workflow Attribute", "The ID or Guid of the workflow that should be activated", true, key: "WorkflowReference" )]
[Rock.SystemGuid.EntityTypeGuid( "DD266CDB-7D60-4312-B727-C2AA95C21128" )]
public class ActivateOtherActivity : ActionComponent
{
/// <summary>
Expand All @@ -62,38 +62,41 @@ public override bool Execute( RockContext rockContext, WorkflowAction action, Ob

var reference = GetAttributeValue( action, "WorkflowReference", true );
Rock.Model.Workflow workflow = null;
if (reference.AsGuidOrNull() != null )
{
var referenceGuid = reference.AsGuid();
workflow = new WorkflowService( rockContext ).Queryable()
.Where( w => w.Guid == referenceGuid )
.FirstOrDefault();
}
else if (reference.AsIntegerOrNull() != null )
{
var referenceInt = reference.AsInteger();
workflow = new WorkflowService( rockContext ).Queryable()
.Where( w => w.Id == referenceInt )
.FirstOrDefault();
}
else
{
action.AddLogEntry( "Invalid Workflow Property", true );
return false;
}

var activityType = WorkflowActivityTypeCache.Get( workflowActivityGuid );
if ( activityType == null )

// Use new context so only changes made to the activity by this action are persisted
using ( var newRockContext = new RockContext() )
{
action.AddLogEntry( "Invalid Activity Property", true );
return false;
}
if ( reference.AsGuidOrNull() != null )
{
var referenceGuid = reference.AsGuid();
workflow = new WorkflowService( newRockContext ).Queryable()
.FirstOrDefault( w => w.Guid == referenceGuid );
}
else if ( reference.AsIntegerOrNull() != null )
{
var referenceInt = reference.AsInteger();
workflow = new WorkflowService( newRockContext ).Queryable()
.FirstOrDefault( w => w.Id == referenceInt );
}
else
{
action.AddLogEntry( "Invalid Workflow Property", true );
return false;
}

WorkflowActivity.Activate( activityType, workflow );
action.AddLogEntry( string.Format( "Activated new '{0}' activity", activityType.ToString() ) );
var activityType = WorkflowActivityTypeCache.Get( workflowActivityGuid );
if ( activityType == null )
{
action.AddLogEntry( "Invalid Activity Property", true );
return false;
}

WorkflowActivity.Activate( activityType, workflow, newRockContext );
action.AddLogEntry( string.Format( "Activated new '{0}' activity", activityType.ToString() ) );
newRockContext.SaveChanges();
}

return true;
}

}
}

0 comments on commit 7f13dcb

Please sign in to comment.