@@ -17,17 +17,17 @@ import { InvalidEntityTypeError, MigrationResult, MigrationTool } from '../../..
1717import { ResultsBuilder } from '../../../utils/resultsbuilder' ;
1818import { CardMigrationTool } from '../../../migration/flexcard' ;
1919import { OmniScriptExportType , OmniScriptMigrationTool } from '../../../migration/omniscript' ;
20- import { GlobalAutoNumberMigrationTool } from '../../../migration/globalautonumber' ;
2120import { Logger } from '../../../utils/logger' ;
2221import OmnistudioRelatedObjectMigrationFacade from '../../../migration/related/OmnistudioRelatedObjectMigrationFacade' ;
2322import { generatePackageXml } from '../../../utils/generatePackageXml' ;
2423import { OmnistudioOrgDetails , OrgUtils } from '../../../utils/orgUtils' ;
2524import { Constants } from '../../../utils/constants/stringContants' ;
2625import { OrgPreferences } from '../../../utils/orgPreferences' ;
2726import { ProjectPathUtil } from '../../../utils/projectPathUtil' ;
28- import { PostMigrate } from '../../../migration/postMigrate' ;
2927import { PromptUtil } from '../../../utils/promptUtil' ;
3028import { YES_SHORT , YES_LONG , NO_SHORT , NO_LONG } from '../../../utils/projectPathUtil' ;
29+ import { PostMigrate } from '../../../migration/postMigrate' ;
30+ import { GlobalAutoNumberMigrationTool } from '../../../migration/globalautonumber' ;
3131
3232// Initialize Messages with the current plugin directory
3333Messages . importMessagesDirectory ( __dirname ) ;
@@ -198,21 +198,21 @@ export default class Migrate extends OmniStudioBaseCommand {
198198 // POST MIGRATION
199199 let actionItems = [ ] ;
200200 const postMigrate : PostMigrate = new PostMigrate (
201- this . org ,
202- namespace ,
203- conn ,
204- this . logger ,
205- messages ,
206- this . ux ,
207- objectsToProcess
208- ) ;
209- if ( ! migrateOnly ) {
201+ this . org ,
202+ namespace ,
203+ conn ,
204+ this . logger ,
205+ messages ,
206+ this . ux ,
207+ objectsToProcess
208+ ) ;
210209
211- actionItems = await postMigrate . setDesignersToUseStandardDataModel ( namespace ) ;
212- }
213- await postMigrate . restoreExperienceAPIMetadataSettings ( isExperienceBundleMetadataAPIProgramaticallyEnabled ) ;
214- const migrationActionItems = this . collectActionItems ( objectMigrationResults ) ;
215- actionItems = [ ...actionItems , ...migrationActionItems ] ;
210+ if ( ! migrateOnly ) {
211+ actionItems = await postMigrate . setDesignersToUseStandardDataModel ( namespace ) ;
212+ }
213+ await postMigrate . restoreExperienceAPIMetadataSettings ( isExperienceBundleMetadataAPIProgramaticallyEnabled ) ;
214+ const migrationActionItems = this . collectActionItems ( objectMigrationResults ) ;
215+ actionItems = [ ...actionItems , ...migrationActionItems ] ;
216216
217217 await ResultsBuilder . generateReport (
218218 objectMigrationResults ,
@@ -228,27 +228,87 @@ export default class Migrate extends OmniStudioBaseCommand {
228228 return { objectMigrationResults } ;
229229 }
230230
231- private async setDesignersToUseStandardDataModel ( namespace : string ) : Promise < string [ ] > {
232- const userActionMessage : string [ ] = [ ] ;
233- try {
234- Logger . logVerbose ( 'Setting designers to use the standard data model' ) ;
235- const apexCode = `
236- ${ namespace } .OmniStudioPostInstallClass.useStandardDataModel();
237- ` ;
238-
239- const result : ExecuteAnonymousResult = await AnonymousApexRunner . run ( this . org , apexCode ) ;
240- if ( result ?. success === false ) {
241- const message = result ?. exceptionStackTrace ;
242- Logger . error ( `Error occurred while setting designers to use the standard data model ${ message } ` ) ;
243- userActionMessage . push ( messages . getMessage ( 'manuallySwitchDesignerToStandardDataModel' ) ) ;
244- } else if ( result ?. success === true ) {
245- Logger . logVerbose ( 'Successfully executed setDesignersToUseStandardDataModel' ) ;
231+ private async getMigrationConsent ( ) : Promise < boolean > {
232+ const askWithTimeOut = PromptUtil . askWithTimeOut ( messages ) ;
233+ let validResponse = false ;
234+ let consent = false ;
235+
236+ while ( ! validResponse ) {
237+ try {
238+ const resp = await askWithTimeOut ( Logger . prompt . bind ( Logger ) , messages . getMessage ( 'migrationConsentMessage' ) ) ;
239+ const response = typeof resp === 'string' ? resp . trim ( ) . toLowerCase ( ) : '' ;
240+
241+ if ( response === YES_SHORT || response === YES_LONG ) {
242+ consent = true ;
243+ validResponse = true ;
244+ } else if ( response === NO_SHORT || response === NO_LONG ) {
245+ consent = false ;
246+ validResponse = true ;
247+ } else {
248+ Logger . error ( messages . getMessage ( 'invalidYesNoResponse' ) ) ;
249+ }
250+ } catch ( err ) {
251+ Logger . error ( messages . getMessage ( 'requestTimedOut' ) ) ;
252+ process . exit ( 1 ) ;
246253 }
247- } catch ( ex ) {
248- Logger . error ( `Exception occurred while setting designers to use the standard data model ${ JSON . stringify ( ex ) } ` ) ;
249- userActionMessage . push ( messages . getMessage ( 'manuallySwitchDesignerToStandardDataModel' ) ) ;
250254 }
251- return userActionMessage ;
255+
256+ return consent ;
257+ }
258+
259+ private async handleExperienceSitePrerequisites (
260+ objectsToProcess : string [ ] ,
261+ conn : Connection ,
262+ isExperienceBundleMetadataAPIProgramaticallyEnabled : { value : boolean }
263+ ) : Promise < void > {
264+ if ( objectsToProcess . includes ( Constants . ExpSites ) ) {
265+ const expMetadataApiConsent = await this . getExpSiteMetadataEnableConsent ( ) ;
266+ Logger . logVerbose ( `The consent for exp site is ${ expMetadataApiConsent } ` ) ;
267+
268+ if ( expMetadataApiConsent === false ) {
269+ Logger . warn ( 'Consent for experience sites is not provided. Experience sites will not be processed' ) ;
270+ this . removeKeyFromRelatedObjectsToProcess ( Constants . ExpSites , objectsToProcess ) ;
271+ Logger . logVerbose ( `Objects to process after removing expsite are ${ JSON . stringify ( objectsToProcess ) } ` ) ;
272+ return ;
273+ }
274+
275+ const isMetadataAPIPreEnabled = await OrgPreferences . isExperienceBundleMetadataAPIEnabled ( conn ) ;
276+ if ( isMetadataAPIPreEnabled === true ) {
277+ Logger . logVerbose ( 'ExperienceBundle metadata api is already enabled' ) ;
278+ return ;
279+ }
280+
281+ Logger . logVerbose ( 'ExperienceBundle metadata api needs to be programatically enabled' ) ;
282+ isExperienceBundleMetadataAPIProgramaticallyEnabled . value = await OrgPreferences . setExperienceBundleMetadataAPI (
283+ conn ,
284+ true
285+ ) ;
286+ if ( isExperienceBundleMetadataAPIProgramaticallyEnabled . value === false ) {
287+ this . removeKeyFromRelatedObjectsToProcess ( Constants . ExpSites , objectsToProcess ) ;
288+ Logger . warn ( 'Since the api could not able enabled the experience sites would not be processed' ) ;
289+ }
290+
291+ Logger . logVerbose ( `Objects to process are ${ JSON . stringify ( objectsToProcess ) } ` ) ;
292+ }
293+ }
294+
295+ private collectActionItems ( objectMigrationResults : MigratedObject [ ] ) : string [ ] {
296+ const actionItems : string [ ] = [ ] ;
297+ // Collect errors from migration results and add them to action items
298+ for ( const result of objectMigrationResults ) {
299+ if ( result . errors && result . errors . length > 0 ) {
300+ actionItems . push ( ...result . errors ) ;
301+ }
302+ }
303+
304+ return actionItems ;
305+ }
306+
307+ private removeKeyFromRelatedObjectsToProcess ( keyToRemove : string , relatedObjects : string [ ] ) : void {
308+ const index = relatedObjects . indexOf ( Constants . ExpSites ) ;
309+ if ( index > - 1 ) {
310+ relatedObjects . splice ( index , 1 ) ;
311+ }
252312 }
253313
254314 private async truncateObjects ( migrationObjects : MigrationTool [ ] , debugTimer : DebugTimer ) : Promise < MigratedObject [ ] > {
0 commit comments