Skip to content

Commit

Permalink
fix: Fixed smart order
Browse files Browse the repository at this point in the history
  • Loading branch information
hknokh2 committed Jan 26, 2023
1 parent 6fe2d25 commit 14a49bf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/modules/components/common_components/statics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ export const CONSTANTS = {
['AccountContactRelation', ['Account', 'Contact', 'Case']]
]),

SPECIAL_OBJECT_DELETE_ORDER: new Map<string, Array<string>>([
['ProductAttribute', ['ProductAttributeSetProduct']]
]),

SPECIAL_OBJECT_UPDATE_ORDER: new Map<string, Array<string>>([
['ProductAttributeSetProduct', ['ProductAttribute']]
]),

OBJECTS_TO_FERIFY_IN_QUERY_TRANSFORM: ['Group'],
EXTRA_OBJECTS_TO_DESCRIBE: ['Group'],

Expand Down
22 changes: 22 additions & 0 deletions src/modules/models/job_models/migrationJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ export default class MigrationJob {

// Create delete task order
this.deleteTasks = this.tasks.slice().reverse();

// Fix delete order
___applySpecialTaskOrder(this.deleteTasks, CONSTANTS.SPECIAL_OBJECT_DELETE_ORDER);

// Fix update order
___applySpecialTaskOrder(this.tasks, CONSTANTS.SPECIAL_OBJECT_UPDATE_ORDER);


}

// Output execution orders
Expand All @@ -195,6 +203,20 @@ export default class MigrationJob {
this.script.addonRuntime.createSfdmuPluginJob();

// ------------------------------- Internal functions --------------------------------------- //
function ___applySpecialTaskOrder(tasks: Task[], specialOrderToApply: Map<string, string[]>) {
for (let leftIndex = 0; leftIndex < tasks.length - 1; leftIndex++) {
const leftTask = tasks[leftIndex];
for (let rightIndex = leftIndex + 1; rightIndex < tasks.length; rightIndex++) {
const rightTask = tasks[rightIndex];
const childObjects = specialOrderToApply.get(rightTask.sObjectName);
if (childObjects && childObjects.includes(leftTask.sObjectName)) {
tasks.splice(rightIndex, 1);
tasks.splice(leftIndex, 0, rightTask);
}
}
}
}

function ___updateQueryTaskOrder() {
let swapped = false;
let tempTasks: Array<MigrationJobTask> = [].concat(self.queryTasks);
Expand Down

0 comments on commit 14a49bf

Please sign in to comment.