diff --git a/upload-api/migration-contentful/libs/contentTypeMapper.js b/upload-api/migration-contentful/libs/contentTypeMapper.js index 2817b8cbc..d9fcc5baf 100644 --- a/upload-api/migration-contentful/libs/contentTypeMapper.js +++ b/upload-api/migration-contentful/libs/contentTypeMapper.js @@ -23,7 +23,7 @@ const appDetails = require('../utils/apps/appDetails.json') */ const uidCorrector = (uid, affix) => { let newId = uid; - if (restrictedUid?.includes?.(uid)) { + if (restrictedUid?.includes?.(uid) || uid?.startsWith?.('_ids') || uid?.endsWith?.('_ids')) { newId = uid?.replace?.(uid, `${affix}_${uid}`); newId = newId?.replace?.(/[^a-zA-Z0-9]+/g, '_'); } diff --git a/upload-api/migration-contentful/libs/createInitialMapper.js b/upload-api/migration-contentful/libs/createInitialMapper.js index 039517511..52f704dc4 100644 --- a/upload-api/migration-contentful/libs/createInitialMapper.js +++ b/upload-api/migration-contentful/libs/createInitialMapper.js @@ -36,7 +36,7 @@ const idArray = require('../utils/restrictedKeyWords'); */ const uidCorrector = (uid, prefix) => { let newId = uid; - if (idArray.includes(uid)) { + if (idArray.includes(uid) || uid.startsWith('_ids') || uid.endsWith('_ids')) { newId = uid.replace(uid, `${prefix}_${uid}`); newId = newId.replace(/[^a-zA-Z0-9]+/g, '_'); } @@ -62,7 +62,7 @@ const uidCorrector = (uid, prefix) => { * * // Outputs: an array of content type objects, each containing metadata and field mappings. */ -const createInitialMapper = async () => { +const createInitialMapper = async (affix="") => { try { const initialMapper = []; const files = await fs.readdir( @@ -82,7 +82,7 @@ const createInitialMapper = async () => { otherCmsTitle: title, otherCmsUid: data[0]?.contentfulID, contentstackTitle: title.charAt(0).toUpperCase() + title.slice(1), - contentstackUid: uidCorrector(data[0]?.contentUid), + contentstackUid: uidCorrector(data[0]?.contentUid,affix), type: 'content_type', fieldMapping: [] }; diff --git a/upload-api/src/services/contentful/index.ts b/upload-api/src/services/contentful/index.ts index acc4728e2..38647e58f 100644 --- a/upload-api/src/services/contentful/index.ts +++ b/upload-api/src/services/contentful/index.ts @@ -19,7 +19,7 @@ const createContentfulMapper = async ( const fetchedLocales: [] = await extractLocale(cleanLocalPath); await extractContentTypes(cleanLocalPath, affix); - const initialMapper = await createInitialMapper(); + const initialMapper = await createInitialMapper(affix); const req = { method: 'post', maxBodyLength: Infinity,