-
Notifications
You must be signed in to change notification settings - Fork 8
[CMG-698] - Issue with Wordpress Connector. Case #00044506 for Horizontal #757
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
Changes from all commits
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2260,19 +2260,22 @@ function limitConcurrency(maxConcurrency: number) { | |||||
| } | ||||||
| const limit = limitConcurrency(5); | ||||||
|
|
||||||
| async function featuredImageMapping(postid: string, post: any, postdata: any) { | ||||||
| async function featuredImageMapping(postid: string, post: any, postdata: any, assetsSchemaPath: string) { | ||||||
| try { | ||||||
| const filePath = path.join(process.cwd(), assetsSave, MIGRATION_DATA_CONFIG.ASSETS_SCHEMA_FILE); | ||||||
| const fileContent = fs.readFileSync(filePath, 'utf8').trim(); | ||||||
| // **THE FIX: Use the path argument directly, don't use the global variable** | ||||||
| const fileContent = fs.readFileSync(assetsSchemaPath, 'utf8').trim(); | ||||||
|
|
||||||
| if (!fileContent) { | ||||||
| throw new Error(`File ${filePath} is empty or missing`); | ||||||
| } | ||||||
| const assetsId = JSON?.parse(fileContent); | ||||||
| if (!post["wp:postmeta"] || !assetsId) return; | ||||||
| if (!fileContent) { | ||||||
| // File is empty, so no assets have been processed. Nothing to map. | ||||||
| return postdata; | ||||||
| } | ||||||
|
|
||||||
| const postmetaArray = Array.isArray(post["wp:postmeta"]) ? post["wp:postmeta"] | ||||||
| : [post["wp:postmeta"]]; | ||||||
| const assetsId = JSON.parse(fileContent); | ||||||
| if (!post["wp:postmeta"] || !assetsId) { | ||||||
| return postdata; | ||||||
| } | ||||||
|
|
||||||
| const postmetaArray = Array.isArray(post["wp:postmeta"]) ? post["wp:postmeta"] : [post["wp:postmeta"]]; | ||||||
|
|
||||||
| const assetsDetails = postmetaArray | ||||||
| .filter((meta) => meta["wp:meta_key"] === "_thumbnail_id") | ||||||
|
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. meta?.["wp:meta_key"] |
||||||
|
|
@@ -2283,14 +2286,17 @@ async function featuredImageMapping(postid: string, post: any, postdata: any) { | |||||
| (asset: any) => asset.uid === attachmentid | ||||||
| ); | ||||||
| }) | ||||||
| .filter(Boolean); // Filter out undefined matches | ||||||
| .filter(Boolean); | ||||||
|
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. const assetsDetails = postmetaArray |
||||||
|
|
||||||
| if (assetsDetails?.length > 0) { | ||||||
| if (assetsDetails.length > 0 && postdata[postid]) { | ||||||
|
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. assetsDetails?.length > 0 && postdata?.[postid] |
||||||
| // Assign the found asset object to the 'featured_image' field | ||||||
| postdata[postid]["featured_image"] = assetsDetails[0]; | ||||||
| } | ||||||
| return postdata; | ||||||
| } catch (error) { | ||||||
| console.error(error); | ||||||
| console.error("Error during featured image mapping:", error); | ||||||
| // Return the original postdata if an error occurs to avoid losing the entry | ||||||
| return postdata; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -2383,96 +2389,67 @@ async function processChunkData( | |||||
| isLastChunk: boolean, | ||||||
| contenttype: any, | ||||||
| authorsFilePath: string, | ||||||
| referencesFilePath: string | ||||||
| referencesFilePath: string, | ||||||
| assetsSchemaPath: string | ||||||
| ) { | ||||||
| const postdata: any = {}; | ||||||
| const formattedPosts: any = {}; | ||||||
| let postdataCombined = {}; | ||||||
| let postdataCombined: Record<string, any> = {}; | ||||||
|
|
||||||
| try { | ||||||
| const writePromises = []; | ||||||
| // This filter is good, it correctly selects only post-like items. | ||||||
| const filteredChunk = chunkData?.filter((item: any) => | ||||||
| item["wp:post_type"] !== "page" && | ||||||
|
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. ?. |
||||||
| item["wp:post_type"] !== "attachment" && | ||||||
| ["publish", "inherit", "draft"]?.includes(item["wp:status"]) | ||||||
| ); | ||||||
|
|
||||||
| const filteredChunk = chunkData?.filter((item:any) => item["wp:post_type"] === "post" && ["publish", "inherit", "draft"]?.includes(item["wp:status"])); | ||||||
| // The main loop processes one item at a time. | ||||||
| for (const data of filteredChunk) { | ||||||
| writePromises.push( | ||||||
| limit(async () => { | ||||||
| const { postCategories, postTags, postTerms } = extractPostCategories(data["category"], referencesFilePath); | ||||||
|
|
||||||
|
|
||||||
| // Extract author | ||||||
| const postAuthor = extractPostAuthor(data["dc:creator"], authorsFilePath); | ||||||
|
|
||||||
| const dom = new JSDOM( | ||||||
| data["content:encoded"] | ||||||
| .replace(/<!--.*?-->/g, "") | ||||||
| .replace(/<!--?\s+\/?wp:.*?-->/g, ""), | ||||||
| { virtualConsole } | ||||||
| ); | ||||||
| const htmlDoc = dom.window.document.querySelector("body"); | ||||||
| const jsonValue = htmlToJson(htmlDoc); | ||||||
|
|
||||||
| // Format date safely | ||||||
| let postDate: string | null = null; | ||||||
| try { | ||||||
| const parsed = new Date(data["wp:post_date_gmt"]); | ||||||
| if (!isNaN(parsed.getTime())) { | ||||||
| postDate = parsed.toISOString(); | ||||||
| } | ||||||
| } catch (error) { | ||||||
| console.error(`Error parsing date for post ${data["wp:post_id"]}:`, error); | ||||||
| } | ||||||
|
|
||||||
| const base = blog_base_url?.split("/")?.filter(Boolean); | ||||||
| const blogname = base[base?.length - 1]; | ||||||
| const url = data["link"]?.split(blogname)[1]; | ||||||
| const uid = `posts_${data["wp:post_id"]}`; | ||||||
| const customId = idCorrector(uid); | ||||||
|
|
||||||
| postdata[customId] = { | ||||||
| title: data["title"] || `Posts - ${data["wp:post_id"]}`, | ||||||
| uid: customId, | ||||||
| url: url, | ||||||
| date: postDate, | ||||||
| full_description: jsonValue, | ||||||
| excerpt: (data["excerpt:encoded"] || "") | ||||||
| .replace(/<!--.*?-->/g, "") | ||||||
| .replace(/<!--?\s+\/?wp:.*?-->/g, ""), | ||||||
| author: postAuthor, | ||||||
| category: postCategories, | ||||||
| terms: postTerms, | ||||||
| tag: postTags, | ||||||
| featured_image: '', | ||||||
| publish_details: [], | ||||||
| }; | ||||||
|
|
||||||
| for (const [key, value] of Object.entries(postdata as { [key: string]: any })) { | ||||||
| const customId = idCorrector(value?.uid); | ||||||
| formattedPosts[customId] = { | ||||||
| ...formattedPosts[customId], | ||||||
| uid: customId, | ||||||
| ...(await mapContentTypeToEntry(contenttype, value)), | ||||||
| }; | ||||||
| formattedPosts[customId].publish_details = []; | ||||||
| } | ||||||
| const customId = idCorrector(`posts_${data["wp:post_id"]}`); | ||||||
|
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. data?.["wp:post_id"] |
||||||
|
|
||||||
| // Step 1: Resolve all references for the CURRENT post | ||||||
| const { postCategories, postTags, postTerms } = extractPostCategories(data["category"], referencesFilePath); | ||||||
|
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. data?.["category"] or for global use if(data) |
||||||
| const postAuthor = extractPostAuthor(data["dc:creator"], authorsFilePath); | ||||||
| const jsonValue = htmlToJson(new JSDOM(data["content:encoded"].replace("//g", "").replace(/<!--?\s+\/?wp:.*?-->/g, "")).window.document.querySelector("body")); | ||||||
|
||||||
| const jsonValue = htmlToJson(new JSDOM(data["content:encoded"].replace("//g", "").replace(/<!--?\s+\/?wp:.*?-->/g, "")).window.document.querySelector("body")); | |
| const jsonValue = htmlToJson(new JSDOM(data["content:encoded"].replace(/<!--.*?-->/gs, "").replace(/<!--?\s+\/?wp:.*?-->/g, "")).window.document.querySelector("body")); |
Copilot
AI
Aug 12, 2025
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.
The regex pattern "//g" in the replace function is incorrect. It should be /<!--.*?-->/g to properly remove HTML comments.
| excerpt: (data["excerpt:encoded"] || "").replace("//g", "").replace(/<!--?\s+\/?wp:.*?-->/g, ""), | |
| excerpt: (data["excerpt:encoded"] || "").replace(/<!--.*?-->/gs, "").replace(/<!--?\s+\/?wp:.*?-->/g, ""), |
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.
formattedPostWithImage?.[customId]
Copilot
AI
Aug 12, 2025
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.
The regex pattern "//g" in the replace function is incorrect. It should be /<!--.*?-->/g to properly remove HTML comments.
| const body = htmlToJson(new JSDOM(item["content:encoded"].replace("//g", "").replace(/<!--?\s+\/?wp:.*?-->/g, "")).window.document.querySelector('body')); | |
| const body = htmlToJson(new JSDOM(item["content:encoded"].replace(/<!--.*?-->/g, "").replace(/<!--?\s+\/?wp:.*?-->/g, "")).window.document.querySelector('body')); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,5 +86,8 @@ | |
| .log-message { | ||
| flex-grow: 1; | ||
| padding: 0 $px-16; | ||
| &.generic-log-message { | ||
| padding: $px-16; | ||
| } | ||
| } | ||
| } | ||
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.
meta?.["wp:meta_key"]
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.
Array.isArray(post?.["wp:postmeta"])
? post["wp:postmeta"]
: (post?.["wp:postmeta"] ? [post["wp:postmeta"]] : [])