@@ -9,11 +9,7 @@ import {
99 jsonToHtml ,
1010 jsonToMarkdown ,
1111} from '@contentstack/json-rte-serializer' ;
12- import {
13- CHUNK_SIZE ,
14- LOCALE_MAPPER ,
15- MIGRATION_DATA_CONFIG ,
16- } from '../../constants/index.js' ;
12+ import { CHUNK_SIZE , MIGRATION_DATA_CONFIG } from '../../constants/index.js' ;
1713import { getLogMessage } from '../../utils/index.js' ;
1814import customLogger from '../../utils/custom-logger.utils.js' ;
1915import { getDbConnection } from '../../helper/index.js' ;
@@ -27,26 +23,33 @@ import {
2723 type AssetFieldMapping ,
2824} from './field-analysis.service.js' ;
2925import FieldFetcherService from './field-fetcher.service.js' ;
30- import {
31- entriesFieldCreator ,
32- unflatten ,
33- } from '../../utils/entries-field-creator.utils.js' ;
3426import { mapDrupalLocales } from './locales.service.js' ;
3527// Dynamic import for phpUnserialize will be used in the function
3628
3729// Local utility functions (extracted from entries-field-creator.utils.ts patterns)
38- const append = 'a' ;
30+ // Default prefix fallback if none provided
31+ const DEFAULT_PREFIX = 'cs' ;
3932
4033function startsWithNumber ( str : string ) {
4134 return / ^ \d / . test ( str ) ;
4235}
4336
44- const uidCorrector = ( { uid, id } : any ) => {
37+ const uidCorrector = ( {
38+ uid,
39+ id,
40+ prefix,
41+ } : {
42+ uid ?: string ;
43+ id ?: string ;
44+ prefix ?: string ;
45+ } ) => {
4546 const value = uid || id ;
4647 if ( ! value ) return '' ;
4748
49+ const effectivePrefix = prefix || DEFAULT_PREFIX ;
50+
4851 if ( startsWithNumber ( value ) ) {
49- return `${ append } _${ _ . replace (
52+ return `${ effectivePrefix } _${ _ . replace (
5053 value ,
5154 new RegExp ( '[ -]' , 'g' ) ,
5255 '_'
@@ -69,9 +72,7 @@ interface TaxonomyFieldOutput {
6972const {
7073 DATA ,
7174 ENTRIES_DIR_NAME ,
72- ENTRIES_MASTER_FILE ,
7375 ASSETS_DIR_NAME ,
74- ASSETS_SCHEMA_FILE ,
7576 REFERENCES_DIR_NAME ,
7677 REFERENCES_FILE_NAME ,
7778 TAXONOMIES_DIR_NAME ,
@@ -190,34 +191,6 @@ async function readFile(filePath: string, fileName: string) {
190191 }
191192}
192193
193- /**
194- * Splits the given entry data into chunks that are under the specified size in bytes.
195- */
196- function makeChunks ( entryData : any ) {
197- let currentChunkSize = 0 ;
198- const chunkSize = CHUNK_SIZE ; // 1 MB in bytes
199- let currentChunkId = uuidv4 ( ) ;
200- const chunks : { [ key : string ] : any } = { } ;
201-
202- for ( const [ key , value ] of Object . entries ( entryData ) ) {
203- const tempObj = { [ ( value as { uid : string } ) . uid ] : value } ;
204- chunks [ currentChunkId ] = { ...chunks [ currentChunkId ] , ...tempObj } ;
205-
206- currentChunkSize = Buffer . byteLength (
207- JSON . stringify ( chunks [ currentChunkId ] ) ,
208- 'utf8'
209- ) ;
210-
211- if ( currentChunkSize > chunkSize ) {
212- currentChunkId = uuidv4 ( ) ;
213- currentChunkSize = 0 ;
214- chunks [ currentChunkId ] = { } ;
215- }
216- }
217-
218- return chunks ;
219- }
220-
221194/**
222195 * Fetches field configurations from Drupal database
223196 */
@@ -663,7 +636,8 @@ const processFieldData = async (
663636 referenceFieldMapping : ReferenceFieldMapping ,
664637 assetFieldMapping : any ,
665638 taxonomyReferenceLookup : Record < number , TaxonomyFieldOutput > ,
666- contentType : string
639+ contentType : string ,
640+ prefix : string = DEFAULT_PREFIX
667641) : Promise < any > => {
668642 const fieldNames = Object . keys ( entryData ) ;
669643 const isoDate = new Date ( ) ;
@@ -872,7 +846,10 @@ const processFieldData = async (
872846 } else if ( fieldName . endsWith ( '_tid' ) ) {
873847 ctValue [ fieldName ] = [ value ] ;
874848 } else if ( fieldName === 'nid' ) {
875- ctValue . uid = uidCorrector ( { id : `content_type_entries_title_${ value } ` } ) ;
849+ ctValue . uid = uidCorrector ( {
850+ id : `content_type_entries_title_${ value } ` ,
851+ prefix,
852+ } ) ;
876853 } else if ( fieldName === 'langcode' ) {
877854 // Use the actual langcode from the entry for proper multilingual support
878855 ctValue . locale = value || 'en-us' ; // fallback to en-us if langcode is empty
@@ -1149,7 +1126,6 @@ const processEntries = async (
11491126 // This replaces the old hardcoded transformation rules with dynamic user mapping
11501127 const transformedEntriesByLocale : { [ locale : string ] : any [ ] } = { } ;
11511128 const allLocales = Object . keys ( entriesByLocale ) ;
1152- const hasUnd = allLocales . includes ( 'und' ) ;
11531129 const hasEn = allLocales . includes ( 'en' ) ;
11541130 const hasEnUs = allLocales . includes ( 'en-us' ) ;
11551131
@@ -1252,6 +1228,9 @@ const processEntries = async (
12521228 const existingLocaleContent =
12531229 ( await readFile ( localeFolderPath , localeFileName ) ) || { } ;
12541230
1231+ // Extract prefix from project for UID correction
1232+ const prefix = project ?. legacy_cms ?. affix || DEFAULT_PREFIX ;
1233+
12551234 // Process each entry in this locale
12561235 for ( const entry of localeEntries ) {
12571236 let processedEntry = await processFieldData (
@@ -1264,7 +1243,8 @@ const processEntries = async (
12641243 referenceFieldMapping ,
12651244 assetFieldMapping ,
12661245 taxonomyReferenceLookup ,
1267- contentType
1246+ contentType ,
1247+ prefix
12681248 ) ;
12691249
12701250 // 🏷️ TAXONOMY CONSOLIDATION: Merge all taxonomy fields into single 'taxonomies' field
@@ -1412,6 +1392,7 @@ const processEntries = async (
14121392 if ( typeof entry . nid === 'number' ) {
14131393 const entryUid = uidCorrector ( {
14141394 id : `content_type_entries_title_${ entry . nid } ` ,
1395+ prefix,
14151396 } ) ;
14161397 existingLocaleContent [ entryUid ] = processedEntry ;
14171398 allProcessedContent [ entryUid ] = processedEntry ;
@@ -1525,7 +1506,6 @@ const processContentType = async (
15251506
15261507 // 🧪 Process entries in batches (test migration: single entry, main migration: all entries)
15271508 const effectiveLimit = isTest ? 1 : LIMIT ;
1528- const maxIterations = isTest ? 1 : Math . ceil ( totalCount / LIMIT ) ; // Test: single iteration, Main: full pagination
15291509
15301510 for (
15311511 let i = 0 ;
@@ -1624,11 +1604,6 @@ export const createEntry = async (
16241604 destination_stack_id ,
16251605 REFERENCES_DIR_NAME
16261606 ) ;
1627- const taxonomiesSave = path . join (
1628- DATA ,
1629- destination_stack_id ,
1630- TAXONOMIES_DIR_NAME
1631- ) ;
16321607
16331608 // Initialize directories
16341609 await fs . promises . mkdir ( entriesSave , { recursive : true } ) ;
0 commit comments