Skip to content

Commit da5f736

Browse files
Merge pull request #573 from contentstack/bugfix/CMG-580
resolved bugs
2 parents 18afc9e + 4c06a86 commit da5f736

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

api/src/services/contentful.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
757757
content.map((item: any) => {
758758
displayField[item?.sys?.id] =
759759
{
760-
displayField: item.displayField || "untitled",
760+
displayField: item?.displayField || "untitled",
761761
};
762762
}
763763
);
@@ -785,7 +785,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
785785
entryData[name][lang] ??= {};
786786
entryData[name][lang][id] ??= {};
787787
locales.push(lang);
788-
const fieldData = currentCT?.fieldMapping?.find((item: any) => key === item?.uid);
788+
const fieldData = currentCT?.fieldMapping?.find?.((item: any) => (key === item?.uid) && (!["text", "url"]?.includes?.(item?.backupFieldType)));
789789
const newId = fieldData?.contentstackFieldUid ?? `${key}`?.replace?.(/[^a-zA-Z0-9]+/g, "_");
790790
entryData[name][lang][id][newId] = processField(
791791
langValue,

upload-api/migration-contentful/libs/contentTypeMapper.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ const appDetails = require('../utils/apps/appDetails.json')
2323
*/
2424
const uidCorrector = (uid, affix) => {
2525
let newId = uid;
26-
if (restrictedUid.includes(uid)) {
27-
newId = uid.replace(uid, `${affix}_${uid}`);
28-
newId = newId.replace(/[^a-zA-Z0-9]+/g, '_');
26+
if (restrictedUid?.includes?.(uid)) {
27+
newId = uid?.replace?.(uid, `${affix}_${uid}`);
28+
newId = newId?.replace?.(/[^a-zA-Z0-9]+/g, '_');
2929
}
30-
return newId.replace(/([A-Z])/g, (match) => `_${match.toLowerCase()}`);
30+
return newId.replace(/([A-Z])/g, (match) => `_${match?.toLowerCase?.()}`);
3131
};
3232

3333
/**
@@ -104,10 +104,10 @@ const createFieldObject = (item, contentstackFieldType, backupFieldType, referen
104104
otherCmsField: item?.name,
105105
otherCmsType: item?.widgetId,
106106
contentstackField: item?.name,
107-
contentstackFieldUid: uidCorrector(item?.id),
107+
contentstackFieldUid: uidCorrector(item?.id, item?.prefix),
108108
contentstackFieldType: contentstackFieldType,
109109
backupFieldType: backupFieldType,
110-
backupFieldUid: uidCorrector(item?.id),
110+
backupFieldUid: uidCorrector(item?.id, item?.prefix),
111111
advanced: extractAdvancedFields(item, referenceFields, contentstackFieldType, backupFieldType)
112112
});
113113

@@ -368,7 +368,7 @@ const contentTypeMapper = (data) => {
368368
otherCmsField: `${item.name} > lat`,
369369
otherCmsType: 'Number',
370370
contentstackField: `${item.name} > lat`,
371-
contentstackFieldUid: `${uidCorrector(item?.id)}.lat`,
371+
contentstackFieldUid: `${uidCorrector(item?.id, item?.prefix)}.lat`,
372372
contentstackFieldType: 'number',
373373
backupFieldType: 'number',
374374
advanced: {
@@ -382,7 +382,7 @@ const contentTypeMapper = (data) => {
382382
otherCmsField: `${item.name} > lon`,
383383
otherCmsType: 'Number',
384384
contentstackField: `${item.name} > lon`,
385-
contentstackFieldUid: `${uidCorrector(item?.id)}.lon`,
385+
contentstackFieldUid: `${uidCorrector(item?.id, item?.prefix)}.lon`,
386386
contentstackFieldType: 'number',
387387
backupFieldType: 'number',
388388
advanced: {

upload-api/migration-contentful/libs/createInitialMapper.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const contentTypeMapper = require('./contentTypeMapper');
1212
/**
1313
* Internal module dependencies.
1414
*/
15-
const { readFile, writeFile, deleteFolderSync } = require('../utils/helper');
15+
const { readFile, deleteFolderSync } = require('../utils/helper');
1616
const config = require('../config');
1717
const idArray = require('../utils/restrictedKeyWords');
1818

@@ -109,14 +109,14 @@ const createInitialMapper = async () => {
109109
advanced: { mandatory: true }
110110
}
111111
];
112-
const dataArray = data.filter((item) => item.id !== 'title' && item.id !== 'url');
113-
const contentstackFields = [...uidTitle, ...contentTypeMapper(dataArray)].filter(Boolean);
112+
const contentstackFields = [...uidTitle, ...contentTypeMapper(data)]?.filter?.(
113+
Boolean
114+
);
114115

115116
contentTypeObject.fieldMapping = contentstackFields;
116117
initialMapper.push(contentTypeObject);
117118
}
118-
// writeFile(path.join(path.resolve(process.cwd(), `${config.data}/${config.contentful.contentful}`), 'schemaTest.json'), JSON.stringify(initialMapper, null, 4));
119-
deleteFolderSync(path.resolve(process.cwd(), config.data));
119+
deleteFolderSync(path.resolve(process.cwd(), config?.data));
120120
return { contentTypes: initialMapper };
121121
} catch (error) {
122122
console.error('Error saving content type:', error);

upload-api/migration-contentful/utils/restrictedKeyWords/index.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,7 @@
4141
"_version",
4242
"__v",
4343
"locale",
44-
"publish_details"
45-
]
44+
"publish_details",
45+
"title",
46+
"url"
47+
]

0 commit comments

Comments
 (0)