/// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(IJobExecutionContext context)
        {
            var familyGroupTypeId = GroupTypeCache.GetFamilyGroupType().Id;

            var personIdListWithFamilyId = new PersonService(new RockContext()).Queryable(true, true).Where(a => a.PrimaryFamilyId.HasValue).Select(a => new { a.Id, a.PrimaryFamilyId }).ToArray();
            var recordsUpdated           = 0;

            // we only need one person from each family (and it doesn't matter who)
            var personIdList = personIdListWithFamilyId.GroupBy(a => a.PrimaryFamilyId.Value).Select(s => s.FirstOrDefault()?.Id).Where(a => a.HasValue).Select(s => s.Value).ToList();

            foreach (var personId in personIdList)
            {
                try
                {
                    using (var rockContext = new RockContext())
                    {
                        // Ensure the person's primary family has a group name set set one if it doesn't.
                        CheckFamilyGroupName(personId, rockContext);

                        // Update the Group Salutations
                        recordsUpdated += PersonService.UpdateGroupSalutations(personId, rockContext);
                    }
                }
                catch (Exception ex)
                {
                    ExceptionLogService.LogException(new Exception($"Error running the job 'PostV124DataMigrationsUpdateGroupSalutations'. UpdateGroupSalutations failed for person ID {personId}", ex));
                }
            }

            ServiceJobService.DeleteJob(context.GetJobId());
        }
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            // get the configured timeout, or default to 60 minutes if it is blank
            var commandTimeout  = dataMap.GetString(AttributeKey.CommandTimeout).AsIntegerOrNull() ?? 3600;
            var migrationHelper = new MigrationHelper(new JobMigration(commandTimeout));

            migrationHelper.CreateIndexIfNotExists("InteractionSession", new[] { "InteractionSessionLocationId" }, new string[0]);

            ServiceJobService.DeleteJob(context.GetJobId());
        }
Example #3
0
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            // get the configured timeout, or default to 60 minutes if it is blank
            var commandTimeout  = dataMap.GetString(AttributeKey.CommandTimeout).AsIntegerOrNull() ?? 3600;
            var migrationHelper = new MigrationHelper(new JobMigration(commandTimeout));

            // Referenced by FK_dbo.Interaction_dbo.InteractionComponent_InteractionComponentId
            // 23-Nov-2021 DMV: No need to drop this index if it is already there, which in some cases it is.
            migrationHelper.CreateIndexIfNotExists("Interaction", new[] { "InteractionComponentId" }, new string[0]);

            ServiceJobService.DeleteJob(context.GetJobId());
        }
Example #4
0
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            // get the configured timeout, or default to 60 minutes if it is blank
            var commandTimeout  = dataMap.GetString(AttributeKey.CommandTimeout).AsIntegerOrNull() ?? 3600;
            var migrationHelper = new MigrationHelper(new JobMigration(commandTimeout));

            migrationHelper.DropIndexIfExists("CommunicationRecipient", "IX_Status");

            migrationHelper.CreateIndexIfNotExists("CommunicationRecipient",
                                                   new[] { "Status" },
                                                   new[] { "CommunicationId" });

            ServiceJobService.DeleteJob(context.GetJobId());
        }
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(IJobExecutionContext context)
        {
            var familyGroupTypeId = GroupTypeCache.GetFamilyGroupType().Id;

            var rockContext = new RockContext();

            // just in case there are Groups that have a null or empty Name, update them.
            var familiesWithoutNames = new GroupService(rockContext)
                                       .Queryable().Where(a => a.GroupTypeId == familyGroupTypeId)
                                       .Where(a => string.IsNullOrEmpty(a.Name));

            if (familiesWithoutNames.Any())
            {
                rockContext.BulkUpdate(familiesWithoutNames, g => new Group {
                    Name = "Family"
                });
            }

            // Re-calculates all GroupSalutation values on Family Groups.
            var familyIdList = new GroupService(rockContext)
                               .Queryable().Where(a => a.GroupTypeId == familyGroupTypeId)
                               .Select(a => a.Id).ToList();

            foreach (var familyId in familyIdList)
            {
                try
                {
                    using (var rockContextUpdate = new RockContext())
                    {
                        GroupService.UpdateGroupSalutations(familyId, rockContextUpdate);
                    }
                }
                catch (Exception ex)
                {
                    ExceptionLogService.LogException(new Exception($"Error running the job 'PostV127DataMigrationsRebuildGroupSalutations'. UpdateGroupSalutations failed for Group Id {familyId}", ex));
                }
            }


            ServiceJobService.DeleteJob(context.GetJobId());
        }
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="System.NotImplementedException"></exception>

        public void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            // get the configured timeout, or default to 60 minutes if it is blank
            var commandTimeout       = dataMap.GetString(AttributeKey.CommandTimeout).AsIntegerOrNull() ?? AttributeDefaults.CommandTimeout;
            var isProcessingComplete = false;
            var batchSize            = 2;
            var totalBatchSize       = 0;
            var currentBatch         = 1;

            totalBatchSize = new StepService(new RockContext())
                             .Queryable()
                             .Where(a => a.CompletedDateTime.HasValue && !a.StepProgramCompletionId.HasValue)
                             .Select(a => a.PersonAlias.PersonId)
                             .Distinct()
                             .Count();
            var runtime = System.Diagnostics.Stopwatch.StartNew();
            var lastProcessedPersonId = 0;

            while (!isProcessingComplete)
            {
                using (var rockContext = new RockContext())
                {
                    var stepTypeService = new StepTypeService(rockContext);
                    var stepService     = new StepService(rockContext);
                    var personQry       = stepService
                                          .Queryable()
                                          .Where(a => a.CompletedDateTime.HasValue && !a.StepProgramCompletionId.HasValue && a.PersonAlias.PersonId > lastProcessedPersonId)
                                          .Select(a => a.PersonAlias.PersonId)
                                          .Distinct()
                                          .OrderBy(a => a)
                                          .Take(batchSize);

                    var stepProgramStepTypeMappings = stepTypeService
                                                      .Queryable()
                                                      .Where(a => a.IsActive)
                                                      .GroupBy(a => a.StepProgramId)
                                                      .ToDictionary(a => a.Key, b => b.Select(c => c.Id).ToList());

                    var steps = new StepService(rockContext)
                                .Queryable("PersonAlias")
                                .AsNoTracking()
                                .Where(a => personQry.Contains(a.PersonAlias.PersonId) && !a.StepProgramCompletionId.HasValue && a.CompletedDateTime.HasValue)
                                .ToList();

                    isProcessingComplete = personQry.Count() < batchSize;
                    var batchPersonIds = personQry.ToList();

                    foreach (var personId in batchPersonIds)
                    {
                        var personSteps = steps.Where(a => a.PersonAlias.PersonId == personId);
                        if (!personSteps.Any())
                        {
                            continue;
                        }

                        foreach (var stepProgramId in stepProgramStepTypeMappings.Keys)
                        {
                            var stepTypeIds    = stepProgramStepTypeMappings[stepProgramId];
                            var stepsByProgram = personSteps.Where(a => stepTypeIds.Contains(a.StepTypeId)).OrderBy(a => a.CompletedDateTime).ToList();

                            if (!stepsByProgram.Any())
                            {
                                continue;
                            }

                            while (stepsByProgram.Any() && stepTypeIds.All(a => stepsByProgram.Any(b => b.StepTypeId == a)))
                            {
                                var stepSet = new List <Step>();
                                foreach (var stepTypeId in stepTypeIds)
                                {
                                    var step = stepsByProgram.Where(a => a.StepTypeId == stepTypeId).FirstOrDefault();
                                    if (step == null)
                                    {
                                        continue;
                                    }

                                    stepSet.Add(step);
                                    stepsByProgram.RemoveAll(a => a.Id == step.Id);
                                }

                                var personAliasId = stepSet.Select(a => a.PersonAliasId).FirstOrDefault();
                                StepService.UpdateStepProgramCompletion(stepSet, personAliasId, stepProgramId);
                            }
                        }
                        lastProcessedPersonId = personId;
                    }

                    var processTime           = runtime.ElapsedMilliseconds;
                    var recordsProcessed      = ( double )(batchSize * currentBatch) + batchPersonIds.Count;
                    var recordsPerMillisecond = recordsProcessed / processTime;
                    var recordsRemaining      = totalBatchSize - recordsProcessed;
                    var minutesRemaining      = recordsRemaining / recordsPerMillisecond / 1000 / 60;
                    context.UpdateLastStatusMessage($"Processing {recordsProcessed} of {totalBatchSize} records. Approximately {minutesRemaining:N0} minutes remaining.");
                    currentBatch++;
                }
            }

            ServiceJobService.DeleteJob(context.GetJobId());
        }
Example #7
0
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            // Get the configured timeout, or default to 60 minutes if it is blank
            var commandTimeout = dataMap.GetString(AttributeKey.CommandTimeout).AsIntegerOrNull() ?? 3600;

            // Get a list of all FinancialPaymentDetails that need to have the Encrypted fields decrypted into the plain text fields
#pragma warning disable 612, 618
            var financialPaymentDetailIdsToUpdate = new FinancialPaymentDetailService(new RockContext())
                                                    .Queryable()
                                                    .Where(pd =>
                                                           (pd.ExpirationMonth == null && pd.ExpirationMonthEncrypted != null) ||
                                                           (pd.NameOnCardEncrypted != null && pd.NameOnCard == null))
                                                    .OrderByDescending(a => a.Id)
                                                    .Select(a => a.Id)
                                                    .ToList();
#pragma warning restore 612, 618

            var    runtime            = System.Diagnostics.Stopwatch.StartNew();
            var    lastProgressUpdate = DateTime.MinValue;
            double recordsProcessed   = 0;
            var    totalRecords       = financialPaymentDetailIdsToUpdate.Count();

            // Load the FinancialPayemntDetail record for each of the financialPaymentDetailIdsToUpdate
            // and convert the encrypted fields to plain text field.
            foreach (var financialPaymentDetailId in financialPaymentDetailIdsToUpdate)
            {
                using (var rockContext = new RockContext())
                {
                    var financialPaymentDetail = new FinancialPaymentDetailService(rockContext).Get(financialPaymentDetailId);

                    if (financialPaymentDetail != null)
                    {
                        // Tell EF that the whole FinancialPaymentDetail record has been modified.
                        // This will ensure that all the logic for setting the field data
                        // is processed, and that all the appropriate PostSaveChanges, etc is done.
                        rockContext.Entry(financialPaymentDetail).State = EntityState.Modified;
                        rockContext.SaveChanges();
                    }

                    var processTime = runtime.ElapsedMilliseconds;
                    recordsProcessed++;
                    var recordsPerMillisecond = recordsProcessed / processTime;
                    var recordsRemaining      = totalRecords - recordsProcessed;
                    var minutesRemaining      = recordsRemaining / recordsPerMillisecond / 1000 / 60;

                    if (RockDateTime.Now - lastProgressUpdate > TimeSpan.FromSeconds(10))
                    {
                        // Update the status every 10 seconds so that the progress can be shown.
                        context.UpdateLastStatusMessage($"Processing {recordsProcessed} of {totalRecords} records. Approximately {minutesRemaining:N0} minutes remaining.");
                        lastProgressUpdate = RockDateTime.Now;
                    }
                }
            }

            context.UpdateLastStatusMessage($"Processed {recordsProcessed} of {totalRecords} records. ");

            // Now that all the rows that need to have been decrypted have been processed, the job can be deleted.
            ServiceJobService.DeleteJob(context.GetJobId());
        }