Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions EntityFrameworkUtil.cs

This file was deleted.

51 changes: 31 additions & 20 deletions FixCombinedGivers.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,57 @@
using System.Linq;
using Quartz;
using Rock.Attribute;
using Rock.Data;
using Rock.Model;
using Rock.Web.Cache;
using Rock.Web.UI.Controls;

namespace com.bricksandmortarstudio.FixCombinedGivers
{
[DisallowConcurrentExecution]
[SlidingDateRangeField( "Date Range", "Apply to Person records created within this time frame. If not set then all records are considered.", false, "", enabledSlidingDateRangeTypes: "Previous, Last, Current, DateRange" )]
public class FixCombinedGivers : IJob
{
public void Execute( IJobExecutionContext context )
{
var rockContext = new RockContext();

var dataMap = context.JobDetail.JobDataMap;
RockContext rockContext = null;
IQueryable<GroupMember> familyMembers = null;
var dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues( dataMap.GetString( "DateRange" ) ?? "-1||" );
int peopleUpdated = 0;
var familyGroupType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY );
var familyMembers = new GroupMemberService( rockContext )
.Queryable( "Group,Person" )
.Where(
g =>
g.Group.GroupType.Id == familyGroupType.Id && g.Person.GivingGroupId == 0 ||
g.Person.GivingGroupId == null );
while (familyMembers.Any())

do
{
//Chunk to prevent foreach saving thread errors
foreach ( var chunk in familyMembers.OrderBy( f => f.Id ).QueryChunksOfSize( 100 ) )
if ( familyMembers != null )
{
foreach ( var familyMember in chunk )
foreach ( var familyMember in familyMembers.OrderBy( f => f.Id ).Take( 100 ).ToList() )
{
familyMember.Person.GivingGroupId = familyMember.GroupId;
peopleUpdated += 1;
}
rockContext.SaveChanges();
}

rockContext = new RockContext();

familyMembers = new GroupMemberService( rockContext )
.Queryable( "Group,Person" )
.Where(
g =>
g.Group.GroupType.Id == familyGroupType.Id && g.Person.GivingGroupId == 0 ||
g.Person.GivingGroupId == null );
}

}
.Queryable( "Group,Person" )
.Where( g => g.Group.GroupType.Id == familyGroupType.Id &&
( g.Person.GivingGroupId == 0 || g.Person.GivingGroupId == null ) );

if ( dateRange.Start.HasValue )
{
familyMembers = familyMembers.Where( g => g.Person.CreatedDateTime >= dateRange.Start );
}

if ( dateRange.End.HasValue )
{
familyMembers = familyMembers.Where( g => g.Person.CreatedDateTime < dateRange.End );
}
} while ( familyMembers.Any() );

context.Result = string.Format( "Combined giving on {0} {1}", peopleUpdated, peopleUpdated == 1 ? "person" : "people" );
}
}
}
2 changes: 1 addition & 1 deletion com.bricksandmortarstudio.FixCombinedGivers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -46,7 +47,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="EntityFrameworkUtil.cs" />
<Compile Include="FixCombinedGivers.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down