Skip to content

Commit fcdceb0

Browse files
chore: saving the changes
1 parent 6a401d7 commit fcdceb0

File tree

3 files changed

+79
-14
lines changed

3 files changed

+79
-14
lines changed

messages/migrate.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,5 +263,8 @@
263263
"errorEnablingOmniStudioSettingsMetadata": "We couldn't enable the Omnistudio Metadata setting: %s. Enable it manually.",
264264
"manuallyEnableOmniStudioSettingsMetadata": "Manually enable the Omnistudio Metadata setting in your org’s Omnistudio Settings page.",
265265
"omniStudioMetadataEnableConsentNotGiven": "You’ve not consented to proceed with enabling the Omnistudio Metadata setting. We’ll not be able to proceed with the migration.",
266-
"enablingOmniStudioSettingsMetadataStatus": "Enabling Omnistudio Metadata setting…"
266+
"enablingOmniStudioSettingsMetadataStatus": "Enabling Omnistudio Metadata setting…",
267+
"omniStudioAllVersionsMigrationConsent": "All Versions of omnistudio components [Omniscript, Data Mapper, Integration Procedure, Flexcard] need to be migrated for metadata to be enabled as org is on Standard Data Model. Do you agree to migrate all versions? [y/n]",
268+
"omniStudioAllVersionsMigrationConsentNotGiven": "You've not consented to proceed with the all versions migration. We'll not be able to proceed with the migration.",
269+
"omniStudioAllVersionsMigrationConsentGiven": "You've consented to proceed with the all versions migration."
267270
}

src/commands/omnistudio/migration/migrate.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default class Migrate extends OmniStudioBaseCommand {
8989
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9090
public async runMigration(): Promise<any> {
9191
const migrateOnly = (this.flags.only || '') as string;
92-
const allVersions = this.flags.allversions || (false as boolean);
92+
let allVersions = this.flags.allversions || (false as boolean);
9393
const relatedObjects = (this.flags.relatedobjects || '') as string;
9494
// this.org is guaranteed because requiresUsername=true, as opposed to supportsUsername
9595
const conn = this.org.getConnection();
@@ -132,18 +132,8 @@ export default class Migrate extends OmniStudioBaseCommand {
132132
const isExperienceBundleMetadataAPIProgramaticallyEnabled: { value: boolean } = { value: false };
133133

134134
if (isStandardDataModel()) {
135-
// Get user consent to enable OmniStudio Metadata for standard data model migration
136-
const omniStudioMetadataEnableConsent = await preMigrate.getOmniStudioMetadataEnableConsent();
137-
if (!omniStudioMetadataEnableConsent) {
138-
Logger.error(messages.getMessage('omniStudioMetadataEnableConsentNotGiven'));
139-
return;
140-
}
141-
142-
// Handle config tables cleanup for standard data model migration
143-
const isMetadataCleanupSuccess = await preMigrate.handleOmniStudioMetadataCleanup();
144-
if (!isMetadataCleanupSuccess) {
145-
return;
146-
}
135+
allVersions = await preMigrate.handleAllVersionsPrerequisites(allVersions);
136+
await preMigrate.handleOmnistudioMetadataPrerequisites();
147137
}
148138

149139
let actionItems = [];

src/migration/premigrate.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,43 @@ export class PreMigrate extends BaseMigrationTool {
1717
super(namespace, connection, logger, messages, ux);
1818
}
1919

20+
/**
21+
* Ensures all versions are migrated when on standard data model.
22+
* If the -a flag was not provided, prompts user for consent.
23+
*
24+
* @param allVersionsFlagFromCLI - The allVersions flag value from CLI (-a flag)
25+
* @returns true if all versions should be migrated, false otherwise
26+
*/
27+
public async handleAllVersionsPrerequisites(allVersionsFlagFromCLI: boolean): Promise<boolean> {
28+
if (allVersionsFlagFromCLI === false) {
29+
// Get user consent to migrate allversions of OmniStudio components for standard data model migration
30+
const omniStudioAllVersionsMigrationConsent = await this.getOmnistudioAllVersionsMigrationConsent();
31+
if (!omniStudioAllVersionsMigrationConsent) {
32+
Logger.error(this.messages.getMessage('omniStudioAllVersionsMigrationConsentNotGiven'));
33+
process.exit(1);
34+
}
35+
36+
Logger.logVerbose(this.messages.getMessage('omniStudioAllVersionsMigrationConsentGiven'));
37+
return true;
38+
}
39+
return allVersionsFlagFromCLI;
40+
}
41+
42+
public async handleOmnistudioMetadataPrerequisites(): Promise<void> {
43+
// Get user consent to enable OmniStudio Metadata for standard data model migration
44+
const omniStudioMetadataEnableConsent = await this.getOmniStudioMetadataEnableConsent();
45+
if (!omniStudioMetadataEnableConsent) {
46+
Logger.error(this.messages.getMessage('omniStudioMetadataEnableConsentNotGiven'));
47+
process.exit(1);
48+
}
49+
50+
// Handle config tables cleanup for standard data model migration
51+
const isMetadataCleanupSuccess = await this.handleOmniStudioMetadataCleanup();
52+
if (!isMetadataCleanupSuccess) {
53+
process.exit(1);
54+
}
55+
}
56+
2057
public async handleExperienceSitePrerequisites(
2158
objectsToProcess: string[],
2259
conn: Connection,
@@ -241,4 +278,39 @@ export class PreMigrate extends BaseMigrationTool {
241278
}
242279
return consent;
243280
}
281+
282+
/**
283+
* Gets user consent for OmniStudio migrating all versions of Omnistudio Components
284+
*
285+
* @returns Promise<boolean> - true if user consents, false otherwise
286+
*/
287+
private async getOmnistudioAllVersionsMigrationConsent(): Promise<boolean> {
288+
const askWithTimeOut = PromptUtil.askWithTimeOut(this.messages);
289+
let validResponse = false;
290+
let consent = false;
291+
292+
while (!validResponse) {
293+
try {
294+
const resp = await askWithTimeOut(
295+
Logger.prompt.bind(Logger),
296+
this.messages.getMessage('omniStudioAllVersionsMigrationConsent')
297+
);
298+
const response = typeof resp === 'string' ? resp.trim().toLowerCase() : '';
299+
300+
if (response === YES_SHORT || response === YES_LONG) {
301+
consent = true;
302+
validResponse = true;
303+
} else if (response === NO_SHORT || response === NO_LONG) {
304+
consent = false;
305+
validResponse = true;
306+
} else {
307+
Logger.error(this.messages.getMessage('invalidYesNoResponse'));
308+
}
309+
} catch (err) {
310+
Logger.error(this.messages.getMessage('requestTimedOut'));
311+
process.exit(1);
312+
}
313+
}
314+
return consent;
315+
}
244316
}

0 commit comments

Comments
 (0)