@@ -14,6 +14,7 @@ export default class ImportCustomRoles extends BaseClass {
1414 private customRolesUidMapperPath : string ;
1515 private envUidMapperFolderPath : string ;
1616 private entriesUidMapperFolderPath : string ;
17+ private assetsUidMapperFolderPath : string ;
1718 private createdCustomRolesPath : string ;
1819 private customRolesFailsPath : string ;
1920 private customRolesConfig : CustomRoleConfig ;
@@ -25,6 +26,8 @@ export default class ImportCustomRoles extends BaseClass {
2526 private environmentsUidMap : Record < string , unknown > ;
2627 private entriesUidMap : Record < string , unknown > ;
2728 private localesUidMap : Record < string , unknown > ;
29+ private assetsUidMap : Record < string , unknown > ;
30+ private assetsFolderUidMap : Record < string , unknown > ;
2831 public targetLocalesMap : Record < string , unknown > ;
2932 public sourceLocalesMap : Record < string , unknown > ;
3033
@@ -37,6 +40,7 @@ export default class ImportCustomRoles extends BaseClass {
3740 this . customRolesUidMapperPath = join ( this . customRolesMapperPath , 'uid-mapping.json' ) ;
3841 this . envUidMapperFolderPath = join ( this . importConfig . backupDir , 'mapper' , 'environments' ) ;
3942 this . entriesUidMapperFolderPath = join ( this . importConfig . backupDir , 'mapper' , 'entries' ) ;
43+ this . assetsUidMapperFolderPath = join ( this . importConfig . backupDir , 'mapper' , 'assets' ) ;
4044 this . createdCustomRolesPath = join ( this . customRolesMapperPath , 'success.json' ) ;
4145 this . customRolesFailsPath = join ( this . customRolesMapperPath , 'fails.json' ) ;
4246 this . customRoles = { } ;
@@ -47,6 +51,8 @@ export default class ImportCustomRoles extends BaseClass {
4751 this . environmentsUidMap = { } ;
4852 this . entriesUidMap = { } ;
4953 this . localesUidMap = { } ;
54+ this . assetsUidMap = { } ;
55+ this . assetsFolderUidMap = { } ;
5056 }
5157
5258 /**
@@ -86,6 +92,16 @@ export default class ImportCustomRoles extends BaseClass {
8692 ? ( fsUtil . readFile ( join ( this . entriesUidMapperFolderPath , 'uid-mapping.json' ) , true ) as Record < string , unknown > ) || { }
8793 : { } ;
8894
95+ log . debug ( 'Loading assets UID data...' , this . importConfig . context ) ;
96+ this . assetsUidMap = fileHelper . fileExistsSync ( this . assetsUidMapperFolderPath )
97+ ? ( fsUtil . readFile ( join ( this . assetsUidMapperFolderPath , 'uid-mapping.json' ) , true ) as Record < string , unknown > ) || { }
98+ : { } ;
99+
100+ log . debug ( 'Loading asset folders UID data...' , this . importConfig . context ) ;
101+ this . assetsFolderUidMap = fileHelper . fileExistsSync ( this . assetsUidMapperFolderPath )
102+ ? ( fsUtil . readFile ( join ( this . assetsUidMapperFolderPath , 'folder-mapping.json' ) , true ) as Record < string , unknown > ) || { }
103+ : { } ;
104+
89105 if ( this . customRolesUidMapper && Object . keys ( this . customRolesUidMapper || { } ) . length > 0 ) {
90106 const customRolesUidCount = Object . keys ( this . customRolesUidMapper || { } ) . length ;
91107 log . debug ( `Loaded existing custom roles UID data: ${ customRolesUidCount } items` , this . importConfig . context ) ;
@@ -290,6 +306,23 @@ export default class ImportCustomRoles extends BaseClass {
290306 } else {
291307 log . debug ( 'No entry UID mappings available for transformation.' , this . importConfig . context ) ;
292308 }
309+ } else if ( rule . module === 'asset' ) {
310+ if ( ! isEmpty ( this . assetsUidMap ) ) {
311+ const originalAssets = rule . assets ?. length || 0 ;
312+ rule . assets = map ( rule . assets , ( uid : string ) => ( this . assetsUidMap [ uid ] as string ) ?? uid ) ;
313+ log . debug ( `Transformed ${ originalAssets } asset UIDs for rule` , this . importConfig . context ) ;
314+ } else {
315+ log . debug ( 'No asset UID mappings available for transformation.' , this . importConfig . context ) ;
316+ }
317+ } else if ( rule . module === 'folder' ) {
318+ if ( ! isEmpty ( this . assetsFolderUidMap ) ) {
319+ const originalFolders = rule . folders ?. length || 0 ;
320+ rule . folders = map ( rule . folders , ( uid : string ) => ( this . assetsFolderUidMap [ uid ] as string ) ?? uid ) ;
321+ rule . heirarchy = map ( rule . heirarchy , ( uid : string ) => ( this . assetsFolderUidMap [ uid ] as string ) ?? uid ) ;
322+ log . debug ( `Transformed ${ originalFolders } folder UIDs for rule` , this . importConfig . context ) ;
323+ } else {
324+ log . debug ( 'No asset folder UID mappings available for transformation.' , this . importConfig . context ) ;
325+ }
293326 }
294327 return rule ;
295328 } ;
0 commit comments