From 960bebfdbb78de0088c1d40bc725e73051855475 Mon Sep 17 00:00:00 2001 From: AishDani Date: Sun, 9 Mar 2025 20:24:03 +0530 Subject: [PATCH 1/8] fix:bugs [CMG-536][CMG-537] --- ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx | 8 +++++++- ui/src/components/LegacyCms/Actions/LoadSelectCms.tsx | 2 +- ui/src/components/LegacyCms/index.tsx | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx b/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx index b9a38e75..7f5b260d 100644 --- a/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx +++ b/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx @@ -61,8 +61,14 @@ const LoadFileFormat = (props: LoadFileFormatProps) => { }; const getFileExtension = (filePath: string): string => { + const normalizedPath = filePath.replace(/\\/g, "/")?.replace(/\/$/, ""); + + // Use regex to extract the file extension + const match = normalizedPath.match(/\.([a-zA-Z0-9]+)$/); + const ext = match ? match[1].toLowerCase() : ""; + const fileName = filePath?.split('/')?.pop(); - const ext = fileName?.split('.')?.pop(); + //const ext = fileName?.split('.')?.pop(); const validExtensionRegex = /\.(pdf|zip|xml|json)$/i; return ext && validExtensionRegex?.test(`.${ext}`) ? `${ext}` : ''; }; diff --git a/ui/src/components/LegacyCms/Actions/LoadSelectCms.tsx b/ui/src/components/LegacyCms/Actions/LoadSelectCms.tsx index 0d676c5b..9e4b9e32 100644 --- a/ui/src/components/LegacyCms/Actions/LoadSelectCms.tsx +++ b/ui/src/components/LegacyCms/Actions/LoadSelectCms.tsx @@ -144,7 +144,7 @@ const LoadSelectCms = (props: LoadSelectCmsProps) => { } }; //await updateLegacyCMSData(selectedOrganisation.value, projectId, { legacy_cms: newSelectedCard?.cms_id }); - dispatch(updateNewMigrationData(newMigrationDataObj)); + //dispatch(updateNewMigrationData(newMigrationDataObj)); props?.handleStepChange(props?.currentStep); } diff --git a/ui/src/components/LegacyCms/index.tsx b/ui/src/components/LegacyCms/index.tsx index d9cb1244..4a206bb0 100644 --- a/ui/src/components/LegacyCms/index.tsx +++ b/ui/src/components/LegacyCms/index.tsx @@ -140,7 +140,7 @@ const LegacyCMSComponent = forwardRef(({ legacyCMSData, isCompleted, handleOnAll } //Make Step 2 complete - if (!isEmptyString(selectedCmsData?.cms_id) && !isEmptyString(legacyCMSData?.affix)) { + if (!isEmptyString(selectedCmsData?.cms_id) && (!isEmptyString(legacyCMSData?.affix) || !isEmptyString(newMigrationData?.legacy_cms?.affix))) { setInternalActiveStepIndex(1); } From be68d688c56c102d7f1abba20fc8546f768c9cd6 Mon Sep 17 00:00:00 2001 From: AishDani Date: Sun, 9 Mar 2025 20:30:18 +0530 Subject: [PATCH 2/8] refactor:the logic for saving wordpress xml file with dynamic name and validating condition --- upload-api/src/routes/index.ts | 100 +++++++++++----------- upload-api/src/services/fileProcessing.ts | 2 +- 2 files changed, 52 insertions(+), 50 deletions(-) diff --git a/upload-api/src/routes/index.ts b/upload-api/src/routes/index.ts index 3a344c1f..0cb22486 100644 --- a/upload-api/src/routes/index.ts +++ b/upload-api/src/routes/index.ts @@ -97,7 +97,9 @@ router.get('/validator', express.json(), fileOperationLimiter, async function (r const cmsType = config?.cmsType?.toLowerCase(); if (config?.isLocalPath) { - const fileName = config?.localPath?.split?.('/')?.pop?.(); + const fileName = path.basename(config?.localPath || ""); + //const fileName = config?.localPath?.replace(/\/$/, "")?.split?.('/')?.pop?.(); + if (!fileName) { res.send('Filename could not be determined from the local path.'); } @@ -105,7 +107,7 @@ router.get('/validator', express.json(), fileOperationLimiter, async function (r if (fileName) { const name = fileName?.split?.('.')?.[0]; const fileExt = fileName?.split('.')?.pop() ?? ''; - const bodyStream = createReadStream(config?.localPath); + const bodyStream = createReadStream(config?.localPath?.replace(/\/$/, "")); bodyStream.on('error', (error: any) => { console.error(error); @@ -137,7 +139,7 @@ router.get('/validator', express.json(), fileOperationLimiter, async function (r const data = await handleFileProcessing(fileExt, xmlData, cmsType,name); res.status(data?.status || 200).json(data); if (data?.status === 200) { - const filePath = path.join(__dirname, '..', '..', 'extracted_files', "data.json"); + const filePath = path.join(__dirname, '..', '..', 'extracted_files', `${name}.json`); createMapper(filePath, projectId, app_token, affix, config); } }); @@ -168,59 +170,59 @@ router.get('/validator', express.json(), fileOperationLimiter, async function (r } }); } - } else { - const params = { - Bucket: config?.awsData?.bucketName, - Key: config?.awsData?.buketKey - }; - const getObjectCommand = new GetObjectCommand(params); - // Get the object from S3 - const s3File = await client.send(getObjectCommand); - //file Name From key - const fileName = params?.Key?.split?.('/')?.pop?.() ?? ''; - //file ext from fileName - const fileExt = fileName?.split?.('.')?.pop?.() ?? 'test'; - - if (!s3File.Body) { - throw new Error('Empty response body from S3'); - } - - const bodyStream: Readable = s3File.Body as Readable; + } + }else { + const params = { + Bucket: config?.awsData?.bucketName, + Key: config?.awsData?.buketKey + }; + const getObjectCommand = new GetObjectCommand(params); + // Get the object from S3 + const s3File = await client.send(getObjectCommand); + //file Name From key + const fileName = params?.Key?.split?.('/')?.pop?.() ?? ''; + //file ext from fileName + const fileExt = fileName?.split?.('.')?.pop?.() ?? 'test'; + + if (!s3File.Body) { + throw new Error('Empty response body from S3'); + } - // Create a writable stream to save the downloaded zip file - const zipFileStream = createWriteStream(`${fileName}`); + const bodyStream: Readable = s3File.Body as Readable; - // // Pipe the S3 object's body to the writable stream - bodyStream.pipe(zipFileStream); + // Create a writable stream to save the downloaded zip file + const zipFileStream = createWriteStream(`${fileName}`); - // Create a writable stream to save the downloaded zip file - let zipBuffer: Buffer | null = null; + // // Pipe the S3 object's body to the writable stream + bodyStream.pipe(zipFileStream); - // Collect the data from the stream into a buffer - bodyStream.on('data', (chunk) => { - if (zipBuffer === null) { - zipBuffer = chunk; - } else { - zipBuffer = Buffer.concat([zipBuffer, chunk]); - } - }); + // Create a writable stream to save the downloaded zip file + let zipBuffer: Buffer | null = null; - //buffer fully stremd - bodyStream.on('end', async () => { - if (!zipBuffer) { - throw new Error('No data collected from the stream.'); - } + // Collect the data from the stream into a buffer + bodyStream.on('data', (chunk) => { + if (zipBuffer === null) { + zipBuffer = chunk; + } else { + zipBuffer = Buffer.concat([zipBuffer, chunk]); + } + }); - const data = await handleFileProcessing(fileExt, zipBuffer, cmsType,fileName); - res.json(data); - res.send('file valited sucessfully.'); - const filePath = path.join(__dirname, '..', '..', 'extracted_files', fileName); - console.log("🚀 ~ bodyStream.on ~ filePath:", filePath) - createMapper(filePath, projectId, app_token, affix, config); - }); - } + //buffer fully stremd + bodyStream.on('end', async () => { + if (!zipBuffer) { + throw new Error('No data collected from the stream.'); + } - } } + const data = await handleFileProcessing(fileExt, zipBuffer, cmsType,fileName); + res.json(data); + res.send('file valited sucessfully.'); + const filePath = path.join(__dirname, '..', '..', 'extracted_files', fileName); + console.log("🚀 ~ bodyStream.on ~ filePath:", filePath) + createMapper(filePath, projectId, app_token, affix, config); + }); + } +} catch (err: any) { console.error('🚀 ~ router.get ~ err:', err); } diff --git a/upload-api/src/services/fileProcessing.ts b/upload-api/src/services/fileProcessing.ts index e442797b..45bd6645 100644 --- a/upload-api/src/services/fileProcessing.ts +++ b/upload-api/src/services/fileProcessing.ts @@ -39,7 +39,7 @@ const handleFileProcessing = async (fileExt: string, zipBuffer: any, cmsType: st const $ = Cheerio.load(zipBuffer, { xmlMode: true }); const fixedXml = $.xml(); const parsedJson = await parseXmlToJson(fixedXml); - const isSaved = await saveJson(parsedJson,"data.json"); + const isSaved = await saveJson(parsedJson,`${name}.json`); if (isSaved) { logger.info('Validation success:', { status: HTTP_CODES?.OK, From 3f883fbd671b43a3ea8ab5f34b4535379161b4ff Mon Sep 17 00:00:00 2001 From: AishDani Date: Mon, 10 Mar 2025 10:53:16 +0530 Subject: [PATCH 3/8] refactor;added optional chaining and await in asset function in wordpress code --- api/src/services/wordpress.service.ts | 110 ++++++++++++++------------ 1 file changed, 58 insertions(+), 52 deletions(-) diff --git a/api/src/services/wordpress.service.ts b/api/src/services/wordpress.service.ts index cd8b4b52..57f39adb 100644 --- a/api/src/services/wordpress.service.ts +++ b/api/src/services/wordpress.service.ts @@ -2,7 +2,7 @@ import fs from "fs"; import path from "path"; import { fileURLToPath } from "url"; import axios from "axios"; -import _ from "lodash"; +//import _ from "lodash"; import { MIGRATION_DATA_CONFIG } from "../constants/index.js"; import jsdom from "jsdom"; import { htmlToJson } from "@contentstack/json-rte-serializer"; @@ -113,7 +113,7 @@ let blog_base_url = ""; //helper function to convert entries with content type function mapContentTypeToEntry(contentType: any, data: any) { return contentType?.fieldMapping?.reduce((acc: { [key: string]: any }, field: FieldMapping) => { - const fieldValue = data[field.uid]; + const fieldValue = data?.[field?.uid]; let formattedValue; switch (field?.contentstackFieldType) { @@ -131,6 +131,9 @@ function mapContentTypeToEntry(contentType: any, data: any) { default: formattedValue = fieldValue; } + if(field?.advanced?.multiple){ + formattedValue = Array.isArray(formattedValue) ? formattedValue : [formattedValue]; + } acc[field.contentstackFieldUid] = formattedValue; return acc; @@ -366,7 +369,7 @@ async function saveAsset(assets: any, retryCount: number, affix: string, destina await writeFileAsync(failedJSONFilePath, failedJSON, 4); if (retryCount === 0) { - return saveAsset(assets, 1, affix, destinationStackId, projectId, baseSiteUrl); + return await saveAsset(assets, 1, affix, destinationStackId, projectId, baseSiteUrl); } else { const message = getLogMessage( srcFunc, @@ -384,15 +387,15 @@ async function getAsset(attachments: any[], affix: string, destinationStackId: s const BATCH_SIZE = 5; // 5 promises at a time const results = []; - for (let i = 0; i < attachments.length; i += BATCH_SIZE) { - const batch = attachments.slice(i, i + BATCH_SIZE); + for (let i = 0; i < attachments?.length; i += BATCH_SIZE) { + const batch = attachments?.slice(i, i + BATCH_SIZE); const batchResults = await Promise.allSettled( - batch.map((data) => { - saveAsset(data, 0, affix, destinationStackId, projectId, baseSiteUrl) + batch?.map(async (data) => { + await saveAsset(data, 0, affix, destinationStackId, projectId, baseSiteUrl) }) ); - results.push(...batchResults); + results?.push(...batchResults); } await writeFileAsync( path.join(assetsSave, MIGRATION_DATA_CONFIG.ASSETS_FILE_NAME), @@ -419,7 +422,7 @@ async function getAllAssets( const assets: Asset[] = alldataParsed?.rss?.channel?.item ?? alldataParsed?.channel?.item; // await writeFileAsync(path.join(assetsSave, MIGRATION_DATA_CONFIG.ASSETS_FILE_NAME), assets, 4); - if (!assets || assets.length === 0) { + if (!assets || assets?.length === 0) { const message = getLogMessage( "createAssetFolderFile", `No assets found.`, @@ -430,10 +433,10 @@ async function getAllAssets( return; } - const attachments = assets.filter( + const attachments = assets?.filter( ({ "wp:post_type": postType }) => postType === "attachment" ); - if (attachments.length > 0) { + if (attachments?.length > 0) { await getAsset(attachments, affix, destinationStackId, projectId,baseSiteUrl); } return; @@ -756,42 +759,45 @@ async function saveAuthors(authorDetails: any[], destinationStackId: string, pro const srcFunc = "saveAuthors"; try { - const authordata = authorDetails.reduce( - async (acc: { [key: string]: any }, data) => { - const uid = `authors_${data["wp:author_id"] || data["wp:author_login"] - }`; - - const title = data["wp:author_login"] || `Authors - ${data["wp:author_id"]}`; - const url = `/${title.toLowerCase().replace(/ /g, "_")}`; - const customId = idCorrector(uid); - const authordata: any = { - uid: uid, - title: data["wp:author_login"], - url: url, - email: data["wp:author_email"], - first_name: data["wp:author_first_name"], - last_name: data["wp:author_last_name"], - }; - acc[customId] = { - ...acc[customId], - uid: customId, - ...mapContentTypeToEntry(contentType, authordata), - }; - acc[customId].publish_details = []; + const authordata: { [key: string]: any } = {}; - const message = getLogMessage( - srcFunc, - `Entry title ${data["wp:author_login"]} (authors) in the ${master_locale} locale has been successfully transformed.`, - {} - ); - - await customLogger(projectId, destinationStackId, 'info', message); - return acc; - }, - {} - ); + for (const data of authorDetails) { + const uid = `authors_${data["wp:author_id"] || data["wp:author_login"]}`; + const title = data["wp:author_login"] || `Authors - ${data["wp:author_id"]}`; + const url = `/${title.toLowerCase().replace(/ /g, "_")}`; + const customId = idCorrector(uid); + + const authordataEntry: any = { + uid: uid, + title: data["wp:author_login"], + url: url, + email: data["wp:author_email"], + first_name: data["wp:author_first_name"], + last_name: data["wp:author_last_name"], + }; + + authordata[customId] = { + ...authordata[customId], + uid: customId, + ...mapContentTypeToEntry(contentType, authordataEntry), + }; + authordata[customId].publish_details = []; + + const message = getLogMessage( + srcFunc, + `Entry title ${data["wp:author_login"]} (authors) in the ${master_locale} locale has been successfully transformed.`, + {} + ); + + await customLogger(projectId, destinationStackId, 'info', message); + } await writeFileAsync(authorsFilePath, authordata, 4); - await writeFileAsync(path.join(authorsFolderPath, "index.json"), {"1": `${master_locale}.json`}, 4); + await writeFileAsync( + path.join(authorsFolderPath, "index.json"), + { "1": `${master_locale}.json` }, + 4 + ); + const message = getLogMessage( srcFunc, `${authorDetails.length} Authors exported successfully`, @@ -1522,11 +1528,11 @@ async function getAllTerms(affix: string, packagePath: string, destinationStackI const alldata: any = await fs.promises.readFile(packagePath, "utf8"); const alldataParsed = JSON.parse(alldata); const terms = - alldataParsed?.rss?.channel["wp:term"] || - alldataParsed?.channel["wp:term"] || + alldataParsed?.rss?.channel?.["wp:term"] || + alldataParsed?.channel?.["wp:term"] || ""; - if (!terms || terms.length === 0) { + if (!terms || terms?.length === 0) { const message = getLogMessage( srcFunc, `No terms found`, @@ -1738,7 +1744,7 @@ function getParent(data: any,id: string) { return catParent; } -async function saveCategories(categoryDetails: any[], destinationStackId:string, projectId: string, contenttype:any, master_locale:stting) { +async function saveCategories(categoryDetails: any[], destinationStackId:string, projectId: string, contenttype:any, master_locale:string) { const srcFunc = 'saveCategories'; try { const categorydata = categoryDetails.reduce( @@ -1922,7 +1928,7 @@ async function featuredImageMapping(postid: string, post: any, postdata: any) { .filter(Boolean); // Filter out undefined matches if (assetsDetails.length > 0) { - postdata[postid]["featured_image"] = assetsDetails; + postdata[postid]["featured_image"] = assetsDetails[0]; } return postdata; } catch (error) { @@ -2030,13 +2036,13 @@ async function processChunkData( const base = blog_base_url.split("/").filter(Boolean); const blogname = base[base.length - 1]; const url = data["link"].split(blogname)[1]; - const title = data["title"] ?? `Posts - ${data["wp:post_id"]}`; + //const title = data["title"] ?? `Posts - ${data["wp:post_id"]}`; const uid = `posts_${data["wp:post_id"]}` const customId = idCorrector(uid) postdata[customId] = { title: data["title"] || `Posts - ${data["wp:post_id"]}`, uid: customId, - url: "/"+title.toLowerCase().replace(/ /g, "_"), + url: url, date: postDate, full_description: jsonValue, excerpt: data["excerpt:encoded"] From 23061b53615d33a3ca4b18f591e26b983302a198 Mon Sep 17 00:00:00 2001 From: AishDani Date: Mon, 10 Mar 2025 10:54:10 +0530 Subject: [PATCH 4/8] refactor:conflict in upload siteocore service --- upload-api/migration-sitecore/index.js | 19 ++++---- .../migration-sitecore/libs/extractLocales.js | 47 +++++++++---------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/upload-api/migration-sitecore/index.js b/upload-api/migration-sitecore/index.js index 69b5e385..642aacac 100644 --- a/upload-api/migration-sitecore/index.js +++ b/upload-api/migration-sitecore/index.js @@ -1,19 +1,20 @@ /* eslint-disable @typescript-eslint/no-var-requires */ -const contentTypes = require("./libs/contenttypes.js") // eslint-disable-next-line @typescript-eslint/no-var-requires -const ExtractConfiguration = require("./libs/configuration.js") +const contentTypes = require('./libs/contenttypes.js'); // eslint-disable-next-line @typescript-eslint/no-var-requires -const reference = require("./libs/reference.js") +const ExtractConfiguration = require('./libs/configuration.js'); // eslint-disable-next-line @typescript-eslint/no-var-requires -const ExtractFiles = require("./libs/convert.js") +const reference = require('./libs/reference.js'); // eslint-disable-next-line @typescript-eslint/no-var-requires -const extractLocales = require("./libs/extractLocales.js") +const ExtractFiles = require('./libs/convert.js'); +// eslint-disable-next-line @typescript-eslint/no-var-requires +const { findAndExtractLanguages } = require('./libs/extractLocales.js'); -module.exports = { +module.exports = { contentTypes, ExtractConfiguration, reference, - ExtractFiles, - extractLocales -} + ExtractFiles, + findAndExtractLanguages +}; diff --git a/upload-api/migration-sitecore/libs/extractLocales.js b/upload-api/migration-sitecore/libs/extractLocales.js index ff979ad5..9aeff090 100644 --- a/upload-api/migration-sitecore/libs/extractLocales.js +++ b/upload-api/migration-sitecore/libs/extractLocales.js @@ -1,33 +1,32 @@ /* eslint-disable @typescript-eslint/no-var-requires */ -const fs = require("fs"); -const path = require("path"); - +const fs = require('fs'); +/* eslint-disable @typescript-eslint/no-var-requires */ +const path = require('path'); const uniqueLanguages = new Set(); // Define uniqueLanguages globally or pass it as a parameter -const extractLocales = (dir) => { - const items = fs.readdirSync(dir, { withFileTypes: true }); +const findAndExtractLanguages = (dir) => { + const items = fs.readdirSync(dir, { withFileTypes: true }); - for (const item of items) { - const fullPath = path.join(dir, item.name); - - if (item.isDirectory()) { - extractLocales(fullPath); // Proper recursion - } else if (item.isFile() && item.name === "data.json.json") { - try { - const rawData = fs.readFileSync(fullPath, "utf8"); - const jsonData = JSON.parse(rawData); - const language = jsonData?.item?.$?.language; + for (const item of items) { + const fullPath = path.join(dir, item.name); - if (language) { - uniqueLanguages.add(language); - } - } catch (error) { - console.error(`Error reading ${fullPath}:`, error.message); - } + if (item.isDirectory()) { + findAndExtractLanguages(fullPath); // Proper recursion + } else if (item.isFile() && item.name === 'data.json.json') { + try { + const rawData = fs.readFileSync(fullPath, 'utf8'); + const jsonData = JSON.parse(rawData); + const language = jsonData?.item?.$?.language; + + if (language) { + uniqueLanguages.add(language); } + } catch (error) { + console.error(`Error reading ${fullPath}:`, error.message); + } } - return uniqueLanguages; + } + return uniqueLanguages; }; - -module.exports = extractLocales; \ No newline at end of file +module.exports = findAndExtractLanguages; From 57d29323fa36ea62c8ef6fbd2174f96b02f9886c Mon Sep 17 00:00:00 2001 From: AishDani Date: Mon, 10 Mar 2025 10:58:44 +0530 Subject: [PATCH 5/8] refactor:resolved conflicts in sitecore code --- upload-api/migration-sitecore/index.js | 5 ++--- upload-api/migration-sitecore/libs/extractLocales.js | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/upload-api/migration-sitecore/index.js b/upload-api/migration-sitecore/index.js index 642aacac..10c85354 100644 --- a/upload-api/migration-sitecore/index.js +++ b/upload-api/migration-sitecore/index.js @@ -1,6 +1,5 @@ /* eslint-disable @typescript-eslint/no-var-requires */ -// eslint-disable-next-line @typescript-eslint/no-var-requires const contentTypes = require('./libs/contenttypes.js'); // eslint-disable-next-line @typescript-eslint/no-var-requires const ExtractConfiguration = require('./libs/configuration.js'); @@ -9,12 +8,12 @@ const reference = require('./libs/reference.js'); // eslint-disable-next-line @typescript-eslint/no-var-requires const ExtractFiles = require('./libs/convert.js'); // eslint-disable-next-line @typescript-eslint/no-var-requires -const { findAndExtractLanguages } = require('./libs/extractLocales.js'); +const extractLocales = require('./libs/extractLocales.js'); module.exports = { contentTypes, ExtractConfiguration, reference, ExtractFiles, - findAndExtractLanguages + extractLocales }; diff --git a/upload-api/migration-sitecore/libs/extractLocales.js b/upload-api/migration-sitecore/libs/extractLocales.js index 9aeff090..9ee71a98 100644 --- a/upload-api/migration-sitecore/libs/extractLocales.js +++ b/upload-api/migration-sitecore/libs/extractLocales.js @@ -1,18 +1,17 @@ /* eslint-disable @typescript-eslint/no-var-requires */ const fs = require('fs'); -/* eslint-disable @typescript-eslint/no-var-requires */ const path = require('path'); const uniqueLanguages = new Set(); // Define uniqueLanguages globally or pass it as a parameter -const findAndExtractLanguages = (dir) => { +const extractLocales = (dir) => { const items = fs.readdirSync(dir, { withFileTypes: true }); for (const item of items) { const fullPath = path.join(dir, item.name); if (item.isDirectory()) { - findAndExtractLanguages(fullPath); // Proper recursion + extractLocales(fullPath); // Proper recursion } else if (item.isFile() && item.name === 'data.json.json') { try { const rawData = fs.readFileSync(fullPath, 'utf8'); @@ -29,4 +28,5 @@ const findAndExtractLanguages = (dir) => { } return uniqueLanguages; }; -module.exports = findAndExtractLanguages; + +module.exports = extractLocales; From 6e8406a0d27a11ee8e21c2c2d5ad27cc8ba1e5ec Mon Sep 17 00:00:00 2001 From: AishDani Date: Mon, 17 Mar 2025 11:11:07 +0530 Subject: [PATCH 6/8] fix:optional chaining comments in PR --- api/src/services/wordpress.service.ts | 12 ++++++------ .../components/LegacyCms/Actions/LoadFileFormat.tsx | 6 +++--- upload-api/migration-sitecore/libs/extractLocales.js | 8 ++++---- upload-api/src/routes/index.ts | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/api/src/services/wordpress.service.ts b/api/src/services/wordpress.service.ts index 57f39adb..9da32ecd 100644 --- a/api/src/services/wordpress.service.ts +++ b/api/src/services/wordpress.service.ts @@ -800,7 +800,7 @@ async function saveAuthors(authorDetails: any[], destinationStackId: string, pro const message = getLogMessage( srcFunc, - `${authorDetails.length} Authors exported successfully`, + `${authorDetails?.length} Authors exported successfully`, {} ) await customLogger(projectId, destinationStackId, 'info', message); @@ -1927,7 +1927,7 @@ async function featuredImageMapping(postid: string, post: any, postdata: any) { }) .filter(Boolean); // Filter out undefined matches - if (assetsDetails.length > 0) { + if (assetsDetails?.length > 0) { postdata[postid]["featured_image"] = assetsDetails[0]; } return postdata; @@ -2031,11 +2031,11 @@ async function processChunkData( ); const htmlDoc = dom.window.document.querySelector("body"); const jsonValue = htmlToJson(htmlDoc); - const postDate = new Date(data["wp:post_date_gmt"]).toISOString(); + const postDate = new Date(data["wp:post_date_gmt"])?.toISOString(); - const base = blog_base_url.split("/").filter(Boolean); - const blogname = base[base.length - 1]; - const url = data["link"].split(blogname)[1]; + const base = blog_base_url?.split("/")?.filter(Boolean); + const blogname = base[base?.length - 1]; + const url = data["link"]?.split(blogname)[1]; //const title = data["title"] ?? `Posts - ${data["wp:post_id"]}`; const uid = `posts_${data["wp:post_id"]}` const customId = idCorrector(uid) diff --git a/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx b/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx index 7f5b260d..76bbf281 100644 --- a/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx +++ b/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx @@ -61,11 +61,11 @@ const LoadFileFormat = (props: LoadFileFormatProps) => { }; const getFileExtension = (filePath: string): string => { - const normalizedPath = filePath.replace(/\\/g, "/")?.replace(/\/$/, ""); + const normalizedPath = filePath?.replace(/\\/g, "/")?.replace(/\/$/, ""); // Use regex to extract the file extension - const match = normalizedPath.match(/\.([a-zA-Z0-9]+)$/); - const ext = match ? match[1].toLowerCase() : ""; + const match = normalizedPath?.match(/\.([a-zA-Z0-9]+)$/); + const ext = match ? match[1]?.toLowerCase() : ""; const fileName = filePath?.split('/')?.pop(); //const ext = fileName?.split('.')?.pop(); diff --git a/upload-api/migration-sitecore/libs/extractLocales.js b/upload-api/migration-sitecore/libs/extractLocales.js index 9ee71a98..9693c945 100644 --- a/upload-api/migration-sitecore/libs/extractLocales.js +++ b/upload-api/migration-sitecore/libs/extractLocales.js @@ -8,11 +8,11 @@ const extractLocales = (dir) => { const items = fs.readdirSync(dir, { withFileTypes: true }); for (const item of items) { - const fullPath = path.join(dir, item.name); + const fullPath = path.join(dir, item?.name); - if (item.isDirectory()) { + if (item?.isDirectory()) { extractLocales(fullPath); // Proper recursion - } else if (item.isFile() && item.name === 'data.json.json') { + } else if (item?.isFile() && item?.name === 'data.json.json') { try { const rawData = fs.readFileSync(fullPath, 'utf8'); const jsonData = JSON.parse(rawData); @@ -22,7 +22,7 @@ const extractLocales = (dir) => { uniqueLanguages.add(language); } } catch (error) { - console.error(`Error reading ${fullPath}:`, error.message); + console.error(`Error reading ${fullPath}:`, error?.message); } } } diff --git a/upload-api/src/routes/index.ts b/upload-api/src/routes/index.ts index 0cb22486..2d6c91b8 100644 --- a/upload-api/src/routes/index.ts +++ b/upload-api/src/routes/index.ts @@ -184,11 +184,11 @@ router.get('/validator', express.json(), fileOperationLimiter, async function (r //file ext from fileName const fileExt = fileName?.split?.('.')?.pop?.() ?? 'test'; - if (!s3File.Body) { + if (!s3File?.Body) { throw new Error('Empty response body from S3'); } - const bodyStream: Readable = s3File.Body as Readable; + const bodyStream: Readable = s3File?.Body as Readable; // Create a writable stream to save the downloaded zip file const zipFileStream = createWriteStream(`${fileName}`); From 836e512c460faff2f78d1778bdca176817077f35 Mon Sep 17 00:00:00 2001 From: AishDani Date: Mon, 17 Mar 2025 11:30:47 +0530 Subject: [PATCH 7/8] refactor:added validation --- upload-api/migration-sitecore/libs/extractLocales.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upload-api/migration-sitecore/libs/extractLocales.js b/upload-api/migration-sitecore/libs/extractLocales.js index 539634ff..1d359a5d 100644 --- a/upload-api/migration-sitecore/libs/extractLocales.js +++ b/upload-api/migration-sitecore/libs/extractLocales.js @@ -11,7 +11,7 @@ const extractLocales = (dir) => { for (const item of items) { const fullPath = path?.join?.(dir, item?.name); - if (item.isDirectory()) { + if (item?.isDirectory()) { extractLocales?.(fullPath); // Proper recursion } else if (item?.isFile() && item?.name === "data.json.json") { try { From c06ef766b4598c705e6c9f3d2484d2f666aa8a27 Mon Sep 17 00:00:00 2001 From: AishDani Date: Mon, 17 Mar 2025 14:19:58 +0530 Subject: [PATCH 8/8] fix:resolved content mapper bug [CMG-542] --- ui/src/components/ContentMapper/index.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ui/src/components/ContentMapper/index.tsx b/ui/src/components/ContentMapper/index.tsx index 4d8a466c..0c7de7de 100644 --- a/ui/src/components/ContentMapper/index.tsx +++ b/ui/src/components/ContentMapper/index.tsx @@ -175,21 +175,21 @@ const Fields: MappingFields = { options: { 'Dropdown':'dropdown' }, - type: 'enum', + type: 'dropdown', }, 'radio': { label :'Select', options: { 'Select':'select' }, - type: 'enum', + type: 'radio', }, 'checkbox': { label:'Select', options: { 'Select':'checkbox' }, - type:'boolean' + type:'display_type' }, 'global_field':{ label : 'Global', @@ -1256,10 +1256,14 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R return value?.data_type === 'isodate'; case 'json': return value?.data_type === 'json'; - case 'enum': - return 'enum' in value; - case 'display_type': + // case 'enum': + // return 'enum' in value; + case 'radio': + return value?.display_type === 'radio'; + case 'dropdown': return value?.display_type === 'dropdown'; + case 'checkbox': + return value?.display_type === 'checkbox'; case 'allow_rich_text': return value?.field_metadata?.allow_rich_text === true; case 'Group':