Skip to content

Commit 822b7c1

Browse files
authored
Adds progress information (#30)
1 parent a5c6da1 commit 822b7c1

File tree

8 files changed

+44
-25
lines changed

8 files changed

+44
-25
lines changed

messages/migrate.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"invalidOnlyFlag": "Invalid flag, valid options are: osip | fc | dr",
1515
"couldNotDeactivateOmniProcesses": "Could not deactivate current OmniProcesses",
1616
"couldNotTruncate": "Could not truncate {0}",
17+
"couldNotTruncateOmnniProcess": "Could not truncate OmniProcess. Please make sure your OS/IP is not referenced in an OmniScrirpt or Flex Card.",
1718
"invalidNameTypeSubtypeOrLanguage": "Not a valid Name, Type, SubType or Language",
1819
"invalidOrRepeatingOmniscriptElementNames": "Invalid or Repeating Element Names for Same OmniScript",
1920
"invalidDataRaptorName": "Invalid name, can not have special characters",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,4 @@
114114
"pre-push": "sf-husky-pre-push"
115115
}
116116
}
117-
}
117+
}

src/commands/omnistudio/migration/migrate.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default class Migrate extends OmniStudioBaseCommand {
5858
// Let's time every step
5959
DebugTimer.getInstance().start();
6060

61-
const namecheck = new MetaDataObjNameCheck(namespace, conn, this.logger, messages);
61+
const namecheck = new MetaDataObjNameCheck(namespace, conn, this.logger, messages, this.ux);
6262

6363
// Register the migration objects
6464
let migrationObjects: MigrationTool[] = [];
@@ -68,31 +68,31 @@ export default class Migrate extends OmniStudioBaseCommand {
6868
await namecheck.checkName('VlocityCard__c');
6969

7070
migrationObjects = [
71-
new CardMigrationTool(namespace, conn, this.logger, messages),
72-
new OmniScriptMigrationTool(OmniScriptExportType.All, namespace, conn, this.logger, messages),
73-
new DataRaptorMigrationTool(namespace, conn, this.logger, messages),
71+
new DataRaptorMigrationTool(namespace, conn, this.logger, messages, this.ux),
72+
new OmniScriptMigrationTool(OmniScriptExportType.All, namespace, conn, this.logger, messages, this.ux),
73+
new CardMigrationTool(namespace, conn, this.logger, messages, this.ux),
7474
];
7575
} else {
7676
switch (migrateOnly) {
7777
case 'os':
7878
await namecheck.checkName('OmniScript__c');
7979
migrationObjects.push(
80-
new OmniScriptMigrationTool(OmniScriptExportType.OS, namespace, conn, this.logger, messages)
80+
new OmniScriptMigrationTool(OmniScriptExportType.OS, namespace, conn, this.logger, messages, this.ux)
8181
);
8282
break;
8383
case 'ip':
8484
await namecheck.checkName('OmniScript__c');
8585
migrationObjects.push(
86-
new OmniScriptMigrationTool(OmniScriptExportType.IP, namespace, conn, this.logger, messages)
86+
new OmniScriptMigrationTool(OmniScriptExportType.IP, namespace, conn, this.logger, messages, this.ux)
8787
);
8888
break;
8989
case 'fc':
9090
await namecheck.checkName('VlocityCard__c');
91-
migrationObjects.push(new CardMigrationTool(namespace, conn, this.logger, messages));
91+
migrationObjects.push(new CardMigrationTool(namespace, conn, this.logger, messages, this.ux));
9292
break;
9393
case 'dr':
9494
await namecheck.checkName('DRBundle__c');
95-
migrationObjects.push(new DataRaptorMigrationTool(namespace, conn, this.logger, messages));
95+
migrationObjects.push(new DataRaptorMigrationTool(namespace, conn, this.logger, messages, this.ux));
9696
break;
9797
default:
9898
throw new Error(messages.getMessage('invalidOnlyFlag'));
@@ -105,8 +105,9 @@ export default class Migrate extends OmniStudioBaseCommand {
105105

106106
// We need to truncate the standard objects first
107107
let allTruncateComplete = true;
108-
for (const cls of migrationObjects) {
108+
for (const cls of migrationObjects.reverse()) {
109109
try {
110+
this.ux.log('Truncating: ' + cls.getName());
110111
debugTimer.lap('Truncating: ' + cls.getName());
111112
await cls.truncate();
112113
} catch (ex: any) {
@@ -119,8 +120,9 @@ export default class Migrate extends OmniStudioBaseCommand {
119120
}
120121

121122
if (allTruncateComplete) {
122-
for (const cls of migrationObjects) {
123+
for (const cls of migrationObjects.reverse()) {
123124
try {
125+
this.ux.log('Migrating: ' + cls.getName());
124126
debugTimer.lap('Migrating: ' + cls.getName());
125127
const results = await cls.migrate();
126128

src/migration/base.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { UX } from '@salesforce/command';
12
import { Connection, Logger, Messages } from '@salesforce/core';
23
import { DebugTimer, QueryTools } from '../utils';
34

@@ -11,12 +12,14 @@ export class BaseMigrationTool {
1112
protected readonly namespacePrefix: string;
1213
protected readonly logger: Logger;
1314
protected readonly messages: Messages;
15+
protected readonly ux: UX;
1416

15-
public constructor(namespace: string, connection: Connection, logger: Logger, messages: Messages) {
17+
public constructor(namespace: string, connection: Connection, logger: Logger, messages: Messages, ux: UX) {
1618
this.namespace = namespace;
1719
this.connection = connection;
1820
this.logger = logger;
1921
this.messages = messages;
22+
this.ux = ux;
2023
this.namespacePrefix = namespace ? namespace + '__' : '';
2124
}
2225

@@ -79,4 +82,11 @@ export class BaseMigrationTool {
7982
protected setRecordErrors(record: unknown, ...errors: string[]): void {
8083
record['errors'] = errors;
8184
}
85+
86+
protected reportProgress(total: number, current: number): void {
87+
const progress = ((100 * current) / total).toFixed(0);
88+
if (parseInt(progress, 10) % 10 === 0) {
89+
this.ux.log(`${progress}% complete...`);
90+
}
91+
}
8292
}

src/migration/dataraptor.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ export class DataRaptorMigrationTool extends BaseMigrationTool implements Migrat
5454

5555
// Start transforming each dataRaptor
5656
DebugTimer.getInstance().lap('Transform Data Raptor');
57+
let done = 0;
58+
const total = dataRaptors.length;
59+
5760
for (let dr of dataRaptors) {
61+
this.reportProgress(total, done);
5862

5963
// Skip if Type is "Migration"
6064
if (dr[this.namespacePrefix + 'Type__c'] === 'Migration') continue;
@@ -129,6 +133,7 @@ export class DataRaptorMigrationTool extends BaseMigrationTool implements Migrat
129133
drUploadInfo.set(recordId, drUploadResponse);
130134
}
131135

136+
done++;
132137
};
133138

134139
return {

src/migration/flexcard.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
9696
private async uploadCard(allCards: any[], card: AnyJson, cardsUploadInfo: Map<string, UploadRecordResult>, originalRecords: Map<string, any>, uniqueNames: Set<string>) {
9797

9898
const recordId = card['Id'];
99+
this.reportProgress(allCards.length, originalRecords.size);
99100

100101
// If we already uploaded this card, skip
101102
if (cardsUploadInfo.has(recordId)) {

src/migration/metadataobjnamecheck.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
/* eslint-disable */
2-
import { Connection, Logger, Messages } from '@salesforce/core';
32
import { DebugTimer, QueryTools } from '../utils';
43
import { BaseMigrationTool } from './base';
54
import { NameTransformData, OriginalRecordName } from './interfaces';
65

76
export class MetaDataObjNameCheck extends BaseMigrationTool {
8-
constructor(namespace: string, connection: Connection, logger: Logger, messages: Messages) {
9-
super(namespace, connection, logger, messages);
10-
}
117

128
async checkName(objName: string): Promise<any> {
139
const result = await this.metaDataObjUniqueNameCheck(objName);

src/migration/omniscript.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { MigrationResult, MigrationTool, TransformData, UploadRecordResult } fro
1010
import { ObjectMapping } from './interfaces';
1111
import { NetUtils, RequestMethod } from '../utils/net';
1212
import { Connection, Logger, Messages } from '@salesforce/core';
13+
import { UX } from '@salesforce/command';
1314

1415
export class OmniScriptMigrationTool extends BaseMigrationTool implements MigrationTool {
1516

@@ -25,8 +26,8 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
2526
static readonly OMNIPROCESSELEMENT_NAME = 'OmniProcessElement';
2627
static readonly OMNIPROCESSCOMPILATION_NAME = 'OmniProcessCompilation';
2728

28-
constructor(exportType: OmniScriptExportType, namespace: string, connection: Connection, logger: Logger, messages: Messages) {
29-
super(namespace, connection, logger, messages);
29+
constructor(exportType: OmniScriptExportType, namespace: string, connection: Connection, logger: Logger, messages: Messages, ux: UX) {
30+
super(namespace, connection, logger, messages, ux);
3031
this.exportType = exportType;
3132
}
3233

@@ -59,7 +60,7 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
5960
async truncate(): Promise<void> {
6061
const objectName = OmniScriptMigrationTool.OMNIPROCESS_NAME;
6162

62-
const allIds = await this.deactivateRecord(objectName, false);
63+
const allIds = await this.deactivateRecord(objectName);
6364
await this.truncateElements(objectName, allIds.os.parents);
6465
await this.truncateElements(objectName, allIds.os.childs);
6566
await this.truncateElements(objectName, allIds.ip.parents);
@@ -71,11 +72,11 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
7172

7273
let success: boolean = await NetUtils.delete(this.connection, ids);
7374
if (!success) {
74-
throw new Error(this.messages.getMessage('couldNotTruncate').formatUnicorn(objectName));
75+
throw new Error(this.messages.getMessage('couldNotTruncateOmnniProcess').formatUnicorn(objectName));
7576
}
7677
}
7778

78-
async deactivateRecord(objectName: string, isReusable: boolean): Promise<{ os: { parents: string[], childs: string[] }, ip: { parents: string[], childs: string[] } }> {
79+
async deactivateRecord(objectName: string): Promise<{ os: { parents: string[], childs: string[] }, ip: { parents: string[], childs: string[] } }> {
7980
DebugTimer.getInstance().lap('Truncating ' + objectName + ' (' + this.exportType + ')');
8081

8182
const filters = new Map<string, any>();
@@ -88,8 +89,6 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
8889
filters.set('IsIntegrationProcedure', false);
8990
}
9091

91-
// filters.set('IsOmniScriptEmbeddable', isReusable);
92-
9392
// const ids: string[] = await QueryTools.queryIds(this.connection, objectName, filters);
9493
const rows = await QueryTools.query(this.connection, objectName, ['Id', 'IsIntegrationProcedure', 'IsOmniScriptEmbeddable'], filters, sorting);
9594
if (rows.length === 0) {
@@ -127,13 +126,17 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
127126
const omniscripts = await this.getAllOmniScripts();
128127

129128
// Variables to be returned After Migration
130-
var originalOsRecords = new Map<string, any>();
131-
var osUploadInfo = new Map<string, UploadRecordResult>();
129+
let done = 0;
130+
let originalOsRecords = new Map<string, any>();
131+
let osUploadInfo = new Map<string, UploadRecordResult>();
132+
const total = omniscripts.length;
132133

133134
for (let omniscript of omniscripts) {
134135
const mappedRecords = [],
135136
originalRecords = new Map<string, AnyJson>();
136137

138+
this.reportProgress(total, done);
139+
137140
// Record is Active, Elements can't be Added, Modified or Deleted for that OS/IP
138141
omniscript[`${this.namespacePrefix}IsActive__c`] = false;
139142

@@ -184,6 +187,7 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
184187
originalOsRecords = new Map([...Array.from(originalOsRecords.entries()), ...Array.from(originalRecords.entries())]);
185188
osUploadInfo = new Map([...Array.from(osUploadInfo.entries()), ...Array.from(osUploadResponse.entries())]);
186189

190+
done++;
187191
};
188192

189193
const objectMigrationResults: MigrationResult[] = [];

0 commit comments

Comments
 (0)