From 86b29689fb22e54622acc91b33ff0416cadd752f Mon Sep 17 00:00:00 2001 From: hknokh Date: Tue, 2 May 2023 01:09:51 +0300 Subject: [PATCH] fix: Fixed circular references handling (#576) --- src/modules/models/job_models/migrationJob.ts | 40 +++++++++++++++++++ .../models/job_models/migrationJobTask.ts | 4 +- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/modules/models/job_models/migrationJob.ts b/src/modules/models/job_models/migrationJob.ts index 542dc9f2..e907b415 100644 --- a/src/modules/models/job_models/migrationJob.ts +++ b/src/modules/models/job_models/migrationJob.ts @@ -530,10 +530,14 @@ export default class MigrationJob { })); if (processedRecordsAmount > 0) { this.logger.infoNormal(RESOURCES.updatingTargetObjectCompleted, task.sObjectName, String(processedRecordsAmount)); + this.logger.infoVerbose(RESOURCES.newLine); } totalProcessedRecordsAmount += processedRecordsAmount; totalProcessedRecordsByObjectsMap.set(task.sObjectName, processedRecordsAmount); } + + this.logger.infoVerbose(RESOURCES.newLine); + if (totalProcessedRecordsAmount > 0) this.logger.infoNormal(RESOURCES.updatingTargetCompleted, this.logger.getResourceString(RESOURCES.step1), String(totalProcessedRecordsAmount)); else @@ -548,6 +552,35 @@ export default class MigrationJob { totalProcessedRecordsAmount = 0; if (this.script.targetOrg.media == DATA_MEDIA_TYPE.Org) { + + this.logger.infoVerbose(RESOURCES.newLine); + this.logger.infoNormal(RESOURCES.pass1); + this.logger.headerVerbose(RESOURCES.separator); + + for (let index = 0; index < this.tasks.length; index++) { + const task = this.tasks[index]; + let processedRecordsAmount = (await task.updateRecords("backwards", async (data: ProcessedData) => { + allMissingParentLookups = allMissingParentLookups.concat(data.missingParentLookups); + if (noAbortPrompt) { + ___warn(data, task.sObjectName); + return; + } + await ___promptToAbort(data, task.sObjectName); + noAbortPrompt = true; + })); + if (processedRecordsAmount > 0) { + this.logger.infoNormal(RESOURCES.updatingTargetObjectCompleted, task.sObjectName, String(processedRecordsAmount)); + this.logger.infoVerbose(RESOURCES.newLine); + } + totalProcessedRecordsAmount += processedRecordsAmount; + totalProcessedRecordsByObjectsMap.set(task.sObjectName, totalProcessedRecordsByObjectsMap.get(task.sObjectName) + processedRecordsAmount); + } + + // To properly handle circular refernces, we have perform the backwards update twice + this.logger.infoVerbose(RESOURCES.newLine); + this.logger.infoNormal(RESOURCES.pass2); + this.logger.headerVerbose(RESOURCES.separator); + for (let index = 0; index < this.tasks.length; index++) { const task = this.tasks[index]; let processedRecordsAmount = (await task.updateRecords("backwards", async (data: ProcessedData) => { @@ -561,11 +594,15 @@ export default class MigrationJob { })); if (processedRecordsAmount > 0) { this.logger.infoNormal(RESOURCES.updatingTargetObjectCompleted, task.sObjectName, String(processedRecordsAmount)); + this.logger.infoVerbose(RESOURCES.newLine); } totalProcessedRecordsAmount += processedRecordsAmount; totalProcessedRecordsByObjectsMap.set(task.sObjectName, totalProcessedRecordsByObjectsMap.get(task.sObjectName) + processedRecordsAmount); } } + + this.logger.infoVerbose(RESOURCES.newLine); + if (totalProcessedRecordsAmount > 0) this.logger.infoNormal(RESOURCES.updatingTargetCompleted, this.logger.getResourceString(RESOURCES.step2), String(totalProcessedRecordsAmount)); else @@ -579,6 +616,7 @@ export default class MigrationJob { this.logger.headerMinimal(RESOURCES.deletingTarget, this.logger.getResourceString(RESOURCES.step1)); for (let index = 0; index < this.deleteTasks.length; index++) { + this.logger.infoVerbose(RESOURCES.newLine); const task = this.deleteTasks[index]; if (task.scriptObject.isHierarchicalDeleteOperation) { let processedRecordsAmount = await task.deleteRecords(); @@ -590,6 +628,8 @@ export default class MigrationJob { } } + this.logger.infoVerbose(RESOURCES.newLine); + if (totalProcessedRecordsAmount > 0) this.logger.infoNormal(RESOURCES.deletingDataCompleted, this.logger.getResourceString(RESOURCES.step1), String(totalProcessedRecordsAmount)); else diff --git a/src/modules/models/job_models/migrationJobTask.ts b/src/modules/models/job_models/migrationJobTask.ts index 12acbe7a..155fa548 100644 --- a/src/modules/models/job_models/migrationJobTask.ts +++ b/src/modules/models/job_models/migrationJobTask.ts @@ -1110,8 +1110,8 @@ export default class MigrationJobTask { // For Step 1 : Simple sFields or reference fields with the parent lookup BEFORE return field.isSimpleNotLookup || field.isSimpleReference && self.data.prevTasks.indexOf(field.parentLookupObject.task) >= 0; else - // For Step 2 : Reference sFields with the parent lookup AFTER + self - return field.isSimpleReference && self.data.nextTasks.concat(self).indexOf(field.parentLookupObject.task) >= 0; + // For Step 2 : Reference sFields. Removed to fix circular reference handling: with the parent lookup AFTER + self + return field.isSimpleReference;// && self.data.nextTasks.concat(self).indexOf(field.parentLookupObject.task) >= 0; }).concat(new SFieldDescribe({ name: CONSTANTS.__ID_FIELD_NAME }), updateMode == "forwards" ? self.scriptObject.getExtraFieldsToUpdate().map(name => {