@@ -13,19 +13,21 @@ import { Connection, Messages } from '@salesforce/core';
1313import OmniStudioBaseCommand from '../../basecommand' ;
1414import { DataRaptorMigrationTool } from '../../../migration/dataraptor' ;
1515import { DebugTimer , MigratedObject , MigratedRecordInfo } from '../../../utils' ;
16- import { MigrationResult , MigrationTool } from '../../../migration/interfaces' ;
16+ import { InvalidEntityTypeError , MigrationResult , MigrationTool } from '../../../migration/interfaces' ;
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' ;
27+ import { PromptUtil } from '../../../utils/promptUtil' ;
28+ import { YES_SHORT , YES_LONG , NO_SHORT , NO_LONG } from '../../../utils/projectPathUtil' ;
2829import { PostMigrate } from '../../../migration/postMigrate' ;
30+ import { GlobalAutoNumberMigrationTool } from '../../../migration/globalautonumber' ;
2931
3032// Initialize Messages with the current plugin directory
3133Messages . importMessagesDirectory ( __dirname ) ;
@@ -116,6 +118,13 @@ export default class Migrate extends OmniStudioBaseCommand {
116118 Logger . log ( `Could not enable Omni preferences: ${ errMsg } ` ) ;
117119 }
118120
121+ // check for confirmation over assessed action items
122+ const migrationConsent = await this . getMigrationConsent ( ) ;
123+ if ( ! migrationConsent ) {
124+ Logger . log ( messages . getMessage ( 'migrationConsentNotGiven' ) ) ;
125+ return ;
126+ }
127+
119128 const namespace = orgs . packageDetails . namespace ;
120129 // Let's time every step
121130 DebugTimer . getInstance ( ) . start ( ) ;
@@ -201,7 +210,9 @@ export default class Migrate extends OmniStudioBaseCommand {
201210 objectsToProcess
202211 ) ;
203212
204- actionItems = await postMigrate . setDesignersToUseStandardDataModel ( namespace ) ;
213+ if ( ! migrateOnly ) {
214+ actionItems = await postMigrate . setDesignersToUseStandardDataModel ( namespace ) ;
215+ }
205216 await postMigrate . restoreExperienceAPIMetadataSettings ( isExperienceBundleMetadataAPIProgramaticallyEnabled ) ;
206217 const migrationActionItems = this . collectActionItems ( objectMigrationResults ) ;
207218 actionItems = [ ...actionItems , ...migrationActionItems ] ;
@@ -212,13 +223,42 @@ export default class Migrate extends OmniStudioBaseCommand {
212223 conn . instanceUrl ,
213224 orgs ,
214225 messages ,
215- actionItems
226+ actionItems ,
227+ objectsToProcess
216228 ) ;
217229
218230 // Return results needed for --json flag
219231 return { objectMigrationResults } ;
220232 }
221233
234+ private async getMigrationConsent ( ) : Promise < boolean > {
235+ const askWithTimeOut = PromptUtil . askWithTimeOut ( messages ) ;
236+ let validResponse = false ;
237+ let consent = false ;
238+
239+ while ( ! validResponse ) {
240+ try {
241+ const resp = await askWithTimeOut ( Logger . prompt . bind ( Logger ) , messages . getMessage ( 'migrationConsentMessage' ) ) ;
242+ const response = typeof resp === 'string' ? resp . trim ( ) . toLowerCase ( ) : '' ;
243+
244+ if ( response === YES_SHORT || response === YES_LONG ) {
245+ consent = true ;
246+ validResponse = true ;
247+ } else if ( response === NO_SHORT || response === NO_LONG ) {
248+ consent = false ;
249+ validResponse = true ;
250+ } else {
251+ Logger . error ( messages . getMessage ( 'invalidYesNoResponse' ) ) ;
252+ }
253+ } catch ( err ) {
254+ Logger . error ( messages . getMessage ( 'requestTimedOut' ) ) ;
255+ process . exit ( 1 ) ;
256+ }
257+ }
258+
259+ return consent ;
260+ }
261+
222262 private async handleExperienceSitePrerequisites (
223263 objectsToProcess : string [ ] ,
224264 conn : Connection ,
@@ -316,10 +356,14 @@ export default class Migrate extends OmniStudioBaseCommand {
316356 } ;
317357 } )
318358 ) ;
319- } catch ( error : any ) {
320- const errMsg = error instanceof Error ? error . message : String ( error ) ;
359+ } catch ( ex : any ) {
360+ if ( ex instanceof InvalidEntityTypeError ) {
361+ Logger . error ( ex . message ) ;
362+ process . exit ( 1 ) ;
363+ }
364+ const errMsg = ex instanceof Error ? ex . message : String ( ex ) ;
321365 Logger . error ( messages . getMessage ( 'errorMigrationMessage' , [ errMsg ] ) ) ;
322- Logger . logVerbose ( error ) ;
366+ Logger . logVerbose ( ex ) ;
323367 objectMigrationResults . push ( {
324368 name : cls . getName ( ) ,
325369 data : [ ] ,
@@ -459,10 +503,11 @@ export default class Migrate extends OmniStudioBaseCommand {
459503 let errors : any [ ] = obj . errors || [ ] ;
460504 errors = errors . concat ( recordResults . errors || [ ] ) ;
461505
462- obj . status =
463- ! recordResults || recordResults . hasErrors
464- ? messages . getMessage ( 'labelStatusFailed' )
465- : messages . getMessage ( 'labelStatusComplete' ) ;
506+ obj . status = recordResults ?. skipped
507+ ? messages . getMessage ( 'labelStatusSkipped' )
508+ : ! recordResults || recordResults . hasErrors
509+ ? messages . getMessage ( 'labelStatusFailed' )
510+ : messages . getMessage ( 'labelStatusComplete' ) ;
466511 obj . errors = errors ;
467512 obj . migratedId = recordResults . id ;
468513 obj . warnings = recordResults . warnings ;
0 commit comments