Skip to content

Commit

Permalink
Fixed variants publish issue when bulkPublishLimit is 1
Browse files Browse the repository at this point in the history
  • Loading branch information
sunil-lakshman committed Oct 28, 2024
1 parent 7c20b8e commit 2fcc541
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 7 additions & 6 deletions packages/contentstack-bulk-publish/src/producer/unpublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand All @@ -248,7 +250,6 @@ async function getSyncEntries(
}
});
}

async function attachVariantsToItems(stack, items, queryParams) {
for (const item of items) {
const { content_type_uid, data } = item;
Expand Down Expand Up @@ -375,4 +376,4 @@ module.exports = {
setConfig,
getQueryParams,
start,
};
};

0 comments on commit 2fcc541

Please sign in to comment.