From 2fcc5413ab3dacf8767545c517a2bcf8a473dae2 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Mon, 28 Oct 2024 12:24:45 +0530 Subject: [PATCH] Fixed variants publish issue when bulkPublishLimit is 1 --- .../src/producer/cross-publish.js | 2 +- .../src/producer/unpublish.js | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/contentstack-bulk-publish/src/producer/cross-publish.js b/packages/contentstack-bulk-publish/src/producer/cross-publish.js index 3493990431..2fbf2223e7 100644 --- a/packages/contentstack-bulk-publish/src/producer/cross-publish.js +++ b/packages/contentstack-bulk-publish/src/producer/cross-publish.js @@ -50,7 +50,7 @@ async function bulkAction(stack, items, bulkPublish, filter, destEnv, apiVersion publish_details: [items[index].data.publish_details] || [], }; - if (variantsFlag) { + if (variantsFlag && Array.isArray(items[index].data.variants) && items[index].data.variants.length > 0) { entry.variants = items[index].data.variants || []; entry.variant_rules = { publish_latest_base: false, diff --git a/packages/contentstack-bulk-publish/src/producer/unpublish.js b/packages/contentstack-bulk-publish/src/producer/unpublish.js index 8f4d29391c..2d750545cd 100644 --- a/packages/contentstack-bulk-publish/src/producer/unpublish.js +++ b/packages/contentstack-bulk-publish/src/producer/unpublish.js @@ -69,7 +69,6 @@ function bulkAction(stack, items, bulkUnpublish, environment, locale, apiVersion if (variantsFlag && Array.isArray(items[index].data.variants) && items[index].data.variants.length > 0) { const entryWithVariants = { ...entryData, variants: items[index].data.variants }; bulkUnPublishSet.push(entryWithVariants); - bulkUnPublishSet.push(entryData); } else { bulkUnPublishSet.push(entryData); } @@ -215,13 +214,16 @@ async function getSyncEntries( syncData['type'] = queryParamsObj.type; } - let entriesResponse = await Stack.sync(syncData); + const entriesResponse = await Stack.sync(syncData); if (entriesResponse.items.length > 0) { if (variantsFlag) { queryParamsObj.apiVersion = VARIANTS_UNPUBLISH_API_VERSION; - entriesResponse.items = await attachVariantsToItems(stack, entriesResponse.items, queryParamsObj); // with variants data + const itemsWithVariants = await attachVariantsToItems(stack, entriesResponse.items, queryParamsObj); + // Call bulkAction for entries with variants + await bulkAction(stack, itemsWithVariants, bulkUnpublish, environment, locale, apiVersion, bulkPublishLimit, variantsFlag); } - await bulkAction(stack, entriesResponse.items, bulkUnpublish, environment, locale, apiVersion, variantsFlag, bulkPublishLimit); + // Call bulkAction for entries without variants + await bulkAction(stack, entriesResponse.items, bulkUnpublish, environment, locale, apiVersion, bulkPublishLimit, false); } if (entriesResponse.items.length === 0) { @@ -248,7 +250,6 @@ async function getSyncEntries( } }); } - async function attachVariantsToItems(stack, items, queryParams) { for (const item of items) { const { content_type_uid, data } = item; @@ -375,4 +376,4 @@ module.exports = { setConfig, getQueryParams, start, -}; +}; \ No newline at end of file