Skip to content

Commit c328d72

Browse files
feat: related objects migration enablement for standard data model
1 parent e126552 commit c328d72

File tree

8 files changed

+365
-27
lines changed

8 files changed

+365
-27
lines changed

src/migration/flexcard.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
234234
flexCardAssessmentInfo.warnings.push(
235235
this.messages.getMessage('needManualInterventionAsSpecialCharsInFlexcardName')
236236
);
237+
flexCardAssessmentInfo.errors.push(
238+
this.messages.getMessage('needManualInterventionAsSpecialCharsInFlexcardName')
239+
);
237240
assessmentStatus = 'Needs Manual Intervention';
238241
}
239242
}
@@ -404,6 +407,9 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
404407
flexCardAssessmentInfo.warnings.push(
405408
this.messages.getMessage('needManualInterventionAsSpecialCharsInChildFlexcardName')
406409
);
410+
flexCardAssessmentInfo.errors.push(
411+
this.messages.getMessage('needManualInterventionAsSpecialCharsInChildFlexcardName')
412+
);
407413
flexCardAssessmentInfo.migrationStatus = 'Needs Manual Intervention';
408414
}
409415
}

src/migration/interfaces.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,15 @@ export interface ExpSiteComponentAttributes {
175175
richTextValue?: string;
176176
}
177177

178+
export interface OmniScriptStandardKey {
179+
type: string;
180+
subtype: string;
181+
language: string;
182+
}
183+
178184
export interface MigrationStorage {
179185
osStorage: Map<string, OmniScriptStorage>;
186+
osStandardStorage: Map<string, OmniScriptStorage>; // String keys (serialized OmniScriptStandardKey)
180187
fcStorage: Map<string, FlexcardStorage>;
181188
}
182189

src/migration/omniscript.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
MigrationResult,
2020
MigrationStorage,
2121
MigrationTool,
22+
OmniScriptStandardKey,
2223
OmniScriptStorage,
2324
TransformData,
2425
UploadRecordResult,
@@ -657,6 +658,16 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
657658
nameMapping.oldLanguage
658659
)}`;
659660

661+
if (this.IS_STANDARD_DATA_MODEL) {
662+
// Create object key for new storage format
663+
const keyObject: OmniScriptStandardKey = {
664+
type: nameMapping.oldType,
665+
subtype: nameMapping.oldSubtype,
666+
language: this.cleanLanguageName(nameMapping.oldLanguage),
667+
};
668+
StorageUtil.addStandardOmniScriptToStorage(storage, keyObject, value);
669+
}
670+
660671
finalKey = finalKey.toLowerCase();
661672
if (storage.osStorage.has(finalKey)) {
662673
// Key already exists - handle accordingly
@@ -1175,6 +1186,16 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
11751186
oldrecord[this.getFieldKey('SubType__c')]
11761187
}${this.cleanLanguageName(oldrecord[this.getFieldKey('Language__c')])}`;
11771188

1189+
if (this.IS_STANDARD_DATA_MODEL) {
1190+
// Create object key for new storage format
1191+
const keyObject: OmniScriptStandardKey = {
1192+
type: oldrecord[this.getFieldKey('Type__c')],
1193+
subtype: oldrecord[this.getFieldKey('SubType__c')],
1194+
language: this.cleanLanguageName(oldrecord[this.getFieldKey('Language__c')]),
1195+
};
1196+
StorageUtil.addStandardOmniScriptToStorage(storage, keyObject, value);
1197+
}
1198+
11781199
finalKey = finalKey.toLowerCase();
11791200
if (storage.osStorage.has(finalKey)) {
11801201
// Key already exists - handle accordingly

src/migration/related/ExperienceSiteMigration.ts

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ExpSiteComponent,
1010
ExpSiteComponentAttributes,
1111
MigrationStorage,
12+
OmniScriptStandardKey,
1213
OmniScriptStorage,
1314
ExpSitePageJson,
1415
Storage,
@@ -19,19 +20,22 @@ import { FileDiffUtil } from '../../utils/lwcparser/fileutils/FileDiffUtil';
1920
import { ExperienceSiteAssessmentInfo, ExperienceSiteAssessmentPageInfo } from '../../utils';
2021
import { StorageUtil } from '../../utils/storageUtil';
2122
import { createProgressBar } from '../base';
23+
import { isStandardDataModel } from '../../utils/dataModelService';
2224
import { BaseRelatedObjectMigration } from './BaseRealtedObjectMigration';
2325

2426
Messages.importMessagesDirectory(__dirname);
2527

2628
const TARGET_COMPONENT_NAME_OS = 'runtime_omnistudio:omniscript';
2729
const TARGET_COMPONENT_NAME_FC = 'runtime_omnistudio:flexcard';
30+
const TARGET_COMPONENT_NAME_OS_EXP = 'runtime_omnistudio:omniscriptExperienceCloud';
2831
const FLEXCARD_PREFIX = 'cf';
2932

3033
export class ExperienceSiteMigration extends BaseRelatedObjectMigration {
3134
private EXPERIENCE_SITES_PATH: string;
3235
private MIGRATE = 'Migrate';
3336
private ASSESS = 'Assess';
3437
private messages: Messages;
38+
private IS_STANDARD_DATA_MODEL: boolean = isStandardDataModel();
3539

3640
public constructor(projectPath: string, namespace: string, org: Org, messages: Messages) {
3741
super(projectPath, namespace, org);
@@ -235,6 +239,7 @@ export class ExperienceSiteMigration extends BaseRelatedObjectMigration {
235239
return;
236240
}
237241

242+
// Check for legacy wrapper component
238243
if (component.componentName === lookupComponentName) {
239244
Logger.logVerbose(this.messages.getMessage('omniWrapperFound'));
240245
experienceSiteAssessmentInfo.hasOmnistudioContent = true;
@@ -250,6 +255,18 @@ export class ExperienceSiteMigration extends BaseRelatedObjectMigration {
250255
return;
251256
}
252257

258+
if (this.IS_STANDARD_DATA_MODEL) {
259+
// Check for new LWC components that need reference updates
260+
if (this.isOmnistudioComponent(component.componentName)) {
261+
Logger.logVerbose(`Found Omnistudio component: ${component.componentName}`);
262+
experienceSiteAssessmentInfo.hasOmnistudioContent = true;
263+
264+
this.updateOmnistudioComponentReferences(component, experienceSiteAssessmentInfo, storage, type);
265+
266+
return;
267+
}
268+
}
269+
253270
const regionsInsideComponent: ExpSiteRegion[] = component.regions;
254271

255272
if (Array.isArray(regionsInsideComponent)) {
@@ -360,6 +377,106 @@ export class ExperienceSiteMigration extends BaseRelatedObjectMigration {
360377
return targetData === undefined || targetData.migrationSuccess === false || targetData.isDuplicate === true;
361378
}
362379

380+
/**
381+
* Check if component is an Omnistudio LWC component
382+
*/
383+
private isOmnistudioComponent(componentName: string): boolean {
384+
return (
385+
componentName === TARGET_COMPONENT_NAME_OS ||
386+
componentName === TARGET_COMPONENT_NAME_FC ||
387+
componentName === TARGET_COMPONENT_NAME_OS_EXP
388+
);
389+
}
390+
391+
/**
392+
* Update references in Omnistudio LWC components
393+
*/
394+
private updateOmnistudioComponentReferences(
395+
component: ExpSiteComponent,
396+
experienceSiteAssessmentInfo: ExperienceSiteAssessmentPageInfo,
397+
storage: MigrationStorage,
398+
type: string
399+
): void {
400+
if (component === undefined || component.componentAttributes === undefined) {
401+
return;
402+
}
403+
const componentName = component.componentName;
404+
const attributes = component.componentAttributes;
405+
406+
if (componentName === TARGET_COMPONENT_NAME_OS || componentName === TARGET_COMPONENT_NAME_OS_EXP) {
407+
this.updateOmniScriptComponentReferences(attributes, experienceSiteAssessmentInfo, storage, type);
408+
} else if (componentName === TARGET_COMPONENT_NAME_FC) {
409+
this.updateFlexCardComponentReferences(attributes, experienceSiteAssessmentInfo, storage, type);
410+
}
411+
}
412+
413+
/**
414+
* Update OmniScript component references (for runtime_omnistudio:omniscript and runtime_omnistudio:omniscriptExperienceCloud)
415+
*/
416+
private updateOmniScriptComponentReferences(
417+
attributes: ExpSiteComponentAttributes,
418+
experienceSiteAssessmentInfo: ExperienceSiteAssessmentPageInfo,
419+
storage: MigrationStorage,
420+
type: string
421+
): void {
422+
const currentType = attributes['type'] as string;
423+
const currentSubType = attributes['subType'] as string;
424+
const currentLanguage = attributes['language'] as string;
425+
426+
if (!currentType || !currentSubType || !currentLanguage) {
427+
return;
428+
}
429+
430+
// Create the OmniScriptStandardKey object for lookup in osStandardStorage
431+
const lookupKey: OmniScriptStandardKey = {
432+
type: currentType,
433+
subtype: currentSubType,
434+
language: currentLanguage,
435+
};
436+
// Look up in osStandardStorage using the object key
437+
const targetDataFromStorage: OmniScriptStorage = StorageUtil.getStandardOmniScript(storage, lookupKey);
438+
439+
if (this.shouldAddWarning(targetDataFromStorage)) {
440+
const originalKey = `${currentType}_${currentSubType}_${currentLanguage}`;
441+
const warningMsg: string = this.getWarningMessage(originalKey, targetDataFromStorage);
442+
experienceSiteAssessmentInfo.warnings.push(warningMsg);
443+
experienceSiteAssessmentInfo.status = type === this.ASSESS ? 'Needs Manual Intervention' : 'Skipped';
444+
} else {
445+
// Update the attributes with the new values from storage
446+
attributes['type'] = targetDataFromStorage.type;
447+
attributes['subType'] = targetDataFromStorage.subtype;
448+
attributes['language'] = targetDataFromStorage.language;
449+
}
450+
}
451+
452+
/**
453+
* Update FlexCard component references (for runtime_omnistudio:flexcard)
454+
*/
455+
private updateFlexCardComponentReferences(
456+
attributes: ExpSiteComponentAttributes,
457+
experienceSiteAssessmentInfo: ExperienceSiteAssessmentPageInfo,
458+
storage: MigrationStorage,
459+
type: string
460+
): void {
461+
const currentFlexCardName = attributes['flexcardName'] as string;
462+
463+
if (!currentFlexCardName) {
464+
return;
465+
}
466+
467+
// Look up in storage to see if this FlexCard was migrated
468+
const targetDataFromStorageFC: FlexcardStorage = storage.fcStorage.get(currentFlexCardName.toLowerCase());
469+
470+
if (this.shouldAddWarning(targetDataFromStorageFC)) {
471+
const warningMsg: string = this.getWarningMessage(currentFlexCardName, targetDataFromStorageFC);
472+
experienceSiteAssessmentInfo.warnings.push(warningMsg);
473+
experienceSiteAssessmentInfo.status = type === this.ASSESS ? 'Needs Manual Intervention' : 'Skipped';
474+
} else {
475+
// Update the flexcardName with the new value from storage
476+
attributes['flexcardName'] = targetDataFromStorageFC.name;
477+
}
478+
}
479+
363480
private getWarningMessage(oldTypeSubtypeLanguage: string, targetDataFromStorage: Storage): string {
364481
if (targetDataFromStorage === undefined) {
365482
// Add log verbose

0 commit comments

Comments
 (0)