Skip to content

Commit

Permalink
fix: Fixed circular references handling (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
hknokh committed May 1, 2023
1 parent d390c08 commit 86b2968
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
40 changes: 40 additions & 0 deletions src/modules/models/job_models/migrationJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) => {
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/modules/models/job_models/migrationJobTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 86b2968

Please sign in to comment.