Skip to content

Commit 53f97d1

Browse files
authored
Merge pull request #511 from contentstack/feature/CMG-526-mkt
mktapp bug fix
2 parents fbb6fc3 + ba1dd60 commit 53f97d1

File tree

2 files changed

+54
-40
lines changed

2 files changed

+54
-40
lines changed

api/src/services/contentful.service.ts

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -88,39 +88,44 @@ function makeChunks(assetData: any) {
8888

8989
const transformCloudinaryObject = (input: any) => {
9090
const result: any = [];
91+
if (!Array.isArray(input)) {
92+
return result;
93+
}
9194
for (const metaData of input ?? []) {
92-
result?.push({
93-
public_id: metaData.public_id,
94-
resource_type: metaData.resource_type,
95-
type: metaData.type,
96-
format: metaData.format,
97-
version: metaData.version,
98-
url: metaData.original_url,
99-
secure_url: metaData.original_secure_url,
100-
width: metaData.width,
101-
height: metaData.height,
102-
bytes: metaData.bytes,
103-
duration: metaData.duration,
104-
tags: metaData.tags,
105-
metadata: metaData.metadata,
106-
created_at: metaData.created_at,
107-
access_mode: "public",
108-
access_control: [],
109-
created_by: {
110-
type: "",
111-
id: ""
112-
},
113-
uploaded_by: {
114-
type: "",
115-
id: ""
116-
},
117-
folder_id: "",
118-
id: "",
119-
folder: "",
120-
cs_metadata: {
121-
config_label: "config"
122-
}
123-
});
95+
if (metaData?.public_id) {
96+
result?.push({
97+
public_id: metaData.public_id,
98+
resource_type: metaData.resource_type,
99+
type: metaData.type,
100+
format: metaData.format,
101+
version: metaData.version,
102+
url: metaData.original_url,
103+
secure_url: metaData.original_secure_url,
104+
width: metaData.width,
105+
height: metaData.height,
106+
bytes: metaData.bytes,
107+
duration: metaData.duration,
108+
tags: metaData.tags,
109+
metadata: metaData.metadata,
110+
created_at: metaData.created_at,
111+
access_mode: "public",
112+
access_control: [],
113+
created_by: {
114+
type: "",
115+
id: ""
116+
},
117+
uploaded_by: {
118+
type: "",
119+
id: ""
120+
},
121+
folder_id: uuidv4(),
122+
id: uuidv4(),
123+
folder: "",
124+
cs_metadata: {
125+
config_label: "config"
126+
}
127+
});
128+
}
124129
}
125130
return result;
126131
}
@@ -185,7 +190,7 @@ function convertToArray(data: any) {
185190
if (typeof data === 'object' && data !== null && !Array.isArray(data)) {
186191
return [data]// Converts object values into an array
187192
}
188-
return data; // Return as is if it's already an array or not an object
193+
return data ?? []; // Return as is if it's already an array or not an object
189194
}
190195

191196
const mktApp = (type: string, data: any) => {
@@ -736,7 +741,6 @@ const mapLocales = ({ masterLocale, locale, locales }: any) => {
736741
* @throws Will log errors encountered during file reading, processing, or writing of entries.
737742
*/
738743
const createEntry = async (packagePath: any, destination_stack_id: string, projectId: string, contentTypes: any, mapperKeys: any, master_locale: string): Promise<void> => {
739-
console.info("🚀 ~ createEntry ~ master_locale:", master_locale)
740744
const srcFunc = 'createEntry';
741745
try {
742746
const entriesSave = path.join(DATA, destination_stack_id, ENTRIES_DIR_NAME);
@@ -783,7 +787,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
783787
entryData[name][lang][id] ??= {};
784788
locales.push(lang);
785789
const fieldData = currentCT?.fieldMapping?.find((item: any) => key === item?.uid);
786-
const newId = fieldData?.contentstackFieldUid ?? `${key}`.replace(/[^a-zA-Z0-9]+/g, "_");
790+
const newId = fieldData?.contentstackFieldUid ?? `${key}`?.replace?.(/[^a-zA-Z0-9]+/g, "_");
787791
entryData[name][lang][id][newId] = processField(
788792
langValue,
789793
entryId,
@@ -796,16 +800,14 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
796800
const pathName = getDisplayName(name, displayField);
797801
locales.forEach((locale) => {
798802
const localeCode = mapLocales({ masterLocale: master_locale, locale, locales: LOCALE_MAPPER });
799-
console.info("🚀 ~ locales.forEach ~ localeCode:", localeCode);
800803
const publishDetails = Object?.values?.(environmentsId)?.length ? Object?.values?.(environmentsId)
801804
.filter((env: any) => env?.name === environment_id)
802805
?.map((env: any) => ({
803806
environment: env?.uid,
804807
version: 1,
805-
locale: locale?.toLowerCase(),
808+
locale: locale?.toLowerCase?.(),
806809
})) : [];
807-
808-
const title = entryData[name][locale][id][pathName] || "";
810+
const title = fields?.[pathName]?.[locale] || "";
809811
const urlTitle = title
810812
?.replace?.(/[^a-zA-Z0-9]+/g, "-")
811813
?.toLowerCase?.();
@@ -858,7 +860,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
858860
);
859861
for await (const [chunkId, chunkData] of Object.entries(chunks)) {
860862
refs[chunkIndex++] = `${chunkId}-entries.json`;
861-
await writeFile(filePath, `${chunkId}-entries.json`, chunkData)
863+
await writeFile(filePath, `${chunkId}-entries.json`, chunkData);
862864
}
863865
await writeFile(filePath, ENTRIES_MASTER_FILE, refs);
864866
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ const arrangeRte = (itemData, item) => {
162162
refs?.push(...contentType?.linkContentType ?? [])
163163
}
164164
}
165+
if (foundItem?.nodes?.["entry-hyperlink"]) {
166+
const contentType = foundItem?.nodes?.['entry-hyperlink']?.find((element) => element?.linkContentType);
167+
if (contentType?.linkContentType?.length) {
168+
refs?.push(...contentType?.linkContentType ?? [])
169+
}
170+
}
171+
if (foundItem?.nodes?.["hyperlink"]) {
172+
const contentType = foundItem?.nodes?.['hyperlink']?.find((element) => element?.linkContentType);
173+
if (contentType?.linkContentType?.length) {
174+
refs?.push(...contentType?.linkContentType ?? [])
175+
}
176+
}
165177
if (refs?.length) {
166178
const replaceUids = [];
167179
for (const uid of refs ?? []) {

0 commit comments

Comments
 (0)