-
Notifications
You must be signed in to change notification settings - Fork 8
Bugfix/cmg 616 #673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix/cmg 616 #673
Changes from 15 commits
7b723d2
016c940
be67715
67f11c8
7cd5c9c
cec94e4
baaefd1
3c39511
e574dbd
24a34ed
43f1c94
a10cb5d
a3012ad
58f3f14
7a0b218
06947c7
5ed10b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2330,6 +2330,17 @@ async function extractPosts( packagePath: string, destinationStackId: string, pr | |
| // Process the current chunk | ||
| const chunkPostData = await processChunkData(chunkData, filename, isLastChunk, contenttype); | ||
| postdataCombined = { ...postdataCombined, ...chunkPostData }; | ||
|
|
||
| const seenTitles = new Map(); | ||
| Object?.entries(postdataCombined)?.forEach(([uid, item]:any) => { | ||
| const originalTitle = item?.title; | ||
|
|
||
| if (seenTitles.has(originalTitle)) { | ||
|
||
| item.title = `${originalTitle} - ${item?.uid}`; | ||
| } | ||
| seenTitles.set(item?.title, true); | ||
| }); | ||
|
|
||
| const message = getLogMessage( | ||
| srcFunc, | ||
| `${filename.split(".").slice(0, -1).join(".")} has been successfully transformed.`, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,9 +74,19 @@ const arrangGroups = ({ schema, newStack }: any) => { | |
| schema?.forEach((item: any) => { | ||
| if (item?.contentstackFieldType === 'group') { | ||
| const groupSchema: any = { ...item, schema: [] } | ||
| if (item?.contentstackFieldUid?.includes('.')) { | ||
| const parts = item?.contentstackFieldUid?.split('.'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why we are making changes in this file @AishDani
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If any group from the source CMS is mapped to a nested group present in Contentstack, then we are modifying its Contentstack UID with all nested groups by adding a dot in between. In this function we are arranging schema of group so keeping only nested group uid to source group which will help to find match in Contentstack schema. |
||
| groupSchema.contentstackFieldUid = parts?.[parts?.length - 1]; | ||
| } | ||
| schema?.forEach((et: any) => { | ||
| if (et?.contentstackFieldUid?.includes(`${item?.contentstackFieldUid}.`) || | ||
| (newStack === false && et?.uid?.includes(`${item?.uid}.`))) { | ||
| const target = groupSchema?.contentstackFieldUid; | ||
| const index = et?.contentstackFieldUid?.indexOf(target); | ||
|
||
|
|
||
| if (index > 0) { | ||
| et.contentstackFieldUid = et?.contentstackFieldUid?.substring(index); | ||
| } | ||
| groupSchema?.schema?.push(et); | ||
| } | ||
| }) | ||
|
|
@@ -112,7 +122,7 @@ const saveAppMapper = async ({ marketPlacePath, data, fileName }: any) => { | |
| } | ||
| } | ||
|
|
||
| const convertToSchemaFormate = ({ field, advanced = true, marketPlacePath }: any) => { | ||
| const convertToSchemaFormate = ({ field, advanced = true, marketPlacePath, keyMapper }: any) => { | ||
| switch (field?.contentstackFieldType) { | ||
| case 'single_line_text': { | ||
| return { | ||
|
|
@@ -435,7 +445,7 @@ const convertToSchemaFormate = ({ field, advanced = true, marketPlacePath }: any | |
| return { | ||
| data_type: "reference", | ||
| display_name: field?.title, | ||
| reference_to: field?.refrenceTo ?? [], | ||
| reference_to: field?.refrenceTo?.map((item:string) => keyMapper[item] || item) ?? [], | ||
| field_metadata: { | ||
| ref_multiple: true, | ||
| ref_multiple_content_types: true | ||
|
|
@@ -654,45 +664,98 @@ const existingCtMapper = async ({ keyMapper, contentTypeUid, projectId, region, | |
| } | ||
| } | ||
|
|
||
| const mergeArrays = async (a: any[], b: any[]) => { | ||
| for await (const fieldGp of b) { | ||
| const exists = a.some(fld => | ||
| fld?.uid === fieldGp?.uid && | ||
| fld?.data_type === fieldGp?.data_type | ||
| const mergeArrays = (a: any[], b: any[]): any[] => { | ||
| const result = [...a]; | ||
|
|
||
| for (const field of b) { | ||
| const exists = result?.some(f => | ||
| f?.uid === field?.uid && | ||
| f?.data_type === field?.data_type | ||
| ); | ||
| if (!exists) { | ||
| a.push(fieldGp); | ||
| result?.push(field); | ||
| } | ||
| } | ||
| return a; | ||
|
|
||
| return result; | ||
| }; | ||
|
|
||
| const mergeFields = async (schema1: any[], schema2: any[]): Promise<any[]> => { | ||
| const result: any[] = []; | ||
|
|
||
| for (const field2 of schema2) { | ||
| if (field2?.data_type === 'group') { | ||
| const machingGroup = findGroupByUid(schema1, field2?.uid); | ||
| if(machingGroup){ | ||
| const schema = await mergeArrays(machingGroup?.schema ?? [],field2?.schema ?? [] ); | ||
| result?.push({ | ||
| ...field2, | ||
| schema: schema | ||
| }); | ||
| } | ||
| else{ | ||
| result?.push({ | ||
| ...field2, | ||
| schema: await mergeFields(schema1, field2?.schema) | ||
| }) | ||
| } | ||
| } | ||
| else{ | ||
| const exists = schema1?.find( | ||
| (fld) => | ||
| fld?.uid === field2?.uid && | ||
| fld?.data_type === field2?.data_type | ||
| ); | ||
| result?.push({ | ||
| ...field2 | ||
| }); | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| for (const field1 of schema1) { | ||
| const isMatched = schema2?.some( | ||
| (field2) => | ||
| field1?.uid === field2?.uid && | ||
| field1?.data_type === field2?.data_type | ||
| ); | ||
|
|
||
| if (!isMatched) { | ||
| result?.push(field1); | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
|
|
||
| const findGroupByUid = ( | ||
| schema: any[], | ||
| uid: string, | ||
| excludeRef: any = null | ||
| ): any | undefined => { | ||
| for (const field of schema) { | ||
| if (field?.data_type === 'group') { | ||
| if (field?.uid === uid && field !== excludeRef) return field; | ||
| const nested = findGroupByUid(field?.schema ?? [], uid, excludeRef); | ||
| if (nested) return nested; | ||
| } | ||
| } | ||
| return undefined; | ||
| }; | ||
|
|
||
| const mergeTwoCts = async (ct: any, mergeCts: any) => { | ||
| const ctData: any = { | ||
| ...ct, | ||
| const merged :any = { | ||
| title: mergeCts?.title, | ||
| uid: mergeCts?.uid, | ||
| options: { | ||
| "singleton": false, | ||
| } | ||
| } | ||
| for await (const field of ctData?.schema ?? []) { | ||
| if (field?.data_type === 'group') { | ||
| const currentGroup = mergeCts?.schema?.find((grp: any) => grp?.uid === field?.uid && | ||
| grp?.data_type === 'group'); | ||
| const group = []; | ||
| for await (const fieldGp of currentGroup?.schema ?? []) { | ||
| const fieldNst = field?.schema?.find((fld: any) => fld?.uid === fieldGp?.uid && | ||
| fld?.data_type === fieldGp?.data_type); | ||
| if (fieldNst === undefined) { | ||
| group?.push(fieldGp); | ||
| } | ||
| } | ||
| field.schema = [...field?.schema ?? [], ...group]; | ||
| } | ||
| } | ||
| ctData.schema = await mergeArrays(ctData?.schema, mergeCts?.schema) ?? []; | ||
| return ctData; | ||
| }, | ||
| schema: await mergeFields(ct?.schema ?? [], mergeCts?.schema ?? []) | ||
| }; | ||
|
|
||
| return merged; | ||
| } | ||
|
|
||
| export const contenTypeMaker = async ({ contentType, destinationStackId, projectId, newStack, keyMapper, region, user_id }: any) => { | ||
|
|
@@ -717,7 +780,7 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project | |
| "display_name": item?.contentstackField, | ||
| "field_metadata": {}, | ||
| "schema": [], | ||
| "uid": item?.contentstackFieldUid, | ||
| "uid": item?.contentstackFieldUid?.replace(/\./g, '_'), | ||
| "multiple": false, | ||
| "mandatory": false, | ||
| "unique": false | ||
|
|
@@ -728,7 +791,7 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project | |
| uid: extractValue(element?.contentstackFieldUid, item?.contentstackFieldUid, '.'), | ||
| title: extractValue(element?.contentstackField, item?.contentstackField, ' >')?.trim(), | ||
| } | ||
| const schema: any = convertToSchemaFormate({ field, marketPlacePath }); | ||
| const schema: any = convertToSchemaFormate({ field, marketPlacePath, keyMapper}); | ||
| if (typeof schema === 'object' && Array.isArray(group?.schema) && element?.isDeleted === false) { | ||
| group.schema.push(schema); | ||
| } | ||
|
|
@@ -741,7 +804,8 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project | |
| title: item?.contentstackField, | ||
| uid: item?.contentstackFieldUid | ||
| }, | ||
| marketPlacePath | ||
| marketPlacePath, | ||
| keyMapper | ||
| }); | ||
| if (dt && item?.isDeleted === false) { | ||
| ct?.schema?.push(dt); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object?.entries?.(postdataCombined)?.forEach?.(([uid, item]:any)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done