Skip to content

Commit a91b454

Browse files
Fixed cross publish issue and updated variant entry publish payload (#1569)
* Fixed cross publish issue and updated variant entry publish payload * Fixed PR comments * Fixed PR comments * Reverted code changes * Removed api_version from header * Added new flag publish-without-base in entry variants publish (#1580)
1 parent 12a856d commit a91b454

File tree

14 files changed

+694
-571
lines changed

14 files changed

+694
-571
lines changed

package-lock.json

Lines changed: 443 additions & 481 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-audit/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ EXAMPLES
267267
$ csdx plugins
268268
```
269269

270-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.4/src/commands/plugins/index.ts)_
270+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/index.ts)_
271271

272272
## `csdx plugins:add PLUGIN`
273273

@@ -341,7 +341,7 @@ EXAMPLES
341341
$ csdx plugins:inspect myplugin
342342
```
343343

344-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.4/src/commands/plugins/inspect.ts)_
344+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/inspect.ts)_
345345

346346
## `csdx plugins:install PLUGIN`
347347

@@ -390,7 +390,7 @@ EXAMPLES
390390
$ csdx plugins:install someuser/someplugin
391391
```
392392

393-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.4/src/commands/plugins/install.ts)_
393+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/install.ts)_
394394

395395
## `csdx plugins:link PATH`
396396

@@ -420,7 +420,7 @@ EXAMPLES
420420
$ csdx plugins:link myplugin
421421
```
422422

423-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.4/src/commands/plugins/link.ts)_
423+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/link.ts)_
424424

425425
## `csdx plugins:remove [PLUGIN]`
426426

@@ -461,7 +461,7 @@ FLAGS
461461
--reinstall Reinstall all plugins after uninstalling.
462462
```
463463

464-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.4/src/commands/plugins/reset.ts)_
464+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/reset.ts)_
465465

466466
## `csdx plugins:uninstall [PLUGIN]`
467467

@@ -489,7 +489,7 @@ EXAMPLES
489489
$ csdx plugins:uninstall myplugin
490490
```
491491

492-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.4/src/commands/plugins/uninstall.ts)_
492+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/uninstall.ts)_
493493

494494
## `csdx plugins:unlink [PLUGIN]`
495495

@@ -533,5 +533,5 @@ DESCRIPTION
533533
Update installed plugins.
534534
```
535535

536-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.4/src/commands/plugins/update.ts)_
536+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/update.ts)_
537537
<!-- commandsstop -->

packages/contentstack-bulk-publish/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,13 +596,13 @@ EXAMPLES
596596
597597
Using --include-variants
598598
599-
$ csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] [--include-variants]
599+
$ csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] [--include-variants]
600600
601601
602602
603603
Using --entry-uid and --include-variants
604604
605-
$ csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] --entry-uid [ENTRY UID] [--include-variants]
605+
$ csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] --entry-uid [ENTRY UID] [--include-variants]
606606
```
607607

608608
## `csdx cm:entries:publish-modified [-a <value>] [--retry-failed <value>] [--bulk-publish <value>] [--source-env <value>] [--content-types <value>] [--locales <value>] [-e <value>] [-c <value>] [-y] [--branch <value>]`
@@ -1042,13 +1042,13 @@ EXAMPLES
10421042
10431043
Using --include-variants
10441044
1045-
$ csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] [--include-variants]
1045+
$ csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] [--include-variants]
10461046
10471047
10481048
10491049
Using --entry-uid and --include-variants
10501050
1051-
$ csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] --entry-uid [ENTRY UID] [--include-variants]
1051+
$ csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] --entry-uid [ENTRY UID] [--include-variants]
10521052
```
10531053

10541054
_See code: [src/commands/cm/entries/publish.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/entries/publish.js)_

packages/contentstack-bulk-publish/src/commands/cm/entries/publish.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,20 @@ class PublishEntriesCommand extends Command {
2222
entriesFlags['publish-all-content-types'] || entriesFlags.publishAllContentTypes || false;
2323
entriesFlags.apiVersion = entriesFlags['api-version'] || '3';
2424
entriesFlags.includeVariants = entriesFlags['include-variants'] || entriesFlags.includeVariants || false;
25+
entriesFlags.publishWithoutBase = entriesFlags['publish-without-base'] || entriesFlags.publishWithoutBase || false;
2526
entriesFlags.entryUid = entriesFlags['entry-uid'] || entriesFlags.entryUid;
27+
28+
if (entriesFlags.entryUid === undefined) {
29+
delete entriesFlags['entryUid'];
30+
}
2631
delete entriesFlags['api-version'];
2732
delete entriesFlags['retry-failed'];
2833
delete entriesFlags['content-types'];
2934
delete entriesFlags['bulk-publish'];
3035
delete entriesFlags['publish-all-content-types'];
36+
delete entriesFlags['include-variants'];
37+
delete entriesFlags['entry-uid'];
38+
delete entriesFlags['publish-without-base'];
3139

3240
let updatedFlags;
3341
try {
@@ -59,8 +67,9 @@ class PublishEntriesCommand extends Command {
5967
} else {
6068
this.error('Please use `--alias` or `--stack-api-key` to proceed.', { exit: 2 });
6169
}
62-
updatedFlags.includeVariantsFlag = entriesFlags.includeVariants;
63-
updatedFlags.entry_uid = entriesFlags.entryUid;
70+
if (updatedFlags.publishWithoutBase && !updatedFlags.includeVariants) {
71+
this.error('Please use `--include-variants` to proceed.', { exit: 2 });
72+
}
6473
updatedFlags.bulkPublish = updatedFlags.bulkPublish !== 'false';
6574
stack = await getStack(config);
6675
}
@@ -201,7 +210,7 @@ PublishEntriesCommand.flags = {
201210
default: 'true',
202211
}),
203212
'api-version': flags.string({
204-
description : "API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].",
213+
description: 'API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].',
205214
}),
206215
'publish-all-content-types': flags.boolean({
207216
description: '(optional) Publish all contenttypes (cannot be set when contentTypes flag is set)',
@@ -249,9 +258,13 @@ PublishEntriesCommand.flags = {
249258
'delivery-token': flags.string({ description: 'Delivery token for source environment' }),
250259
'source-env': flags.string({ description: 'Source environment' }),
251260
'entry-uid': flags.string({ description: 'Entry Uid for publish all associated variant entries.' }),
252-
'include-variants': flags.boolean({
261+
'include-variants': flags.boolean({
253262
default: false, // set the default value to false
254-
description: 'Include Variants flag will publish all associated variant entries.'
263+
description: 'Include Variants flag will publish all associated variant entries with base entry.',
264+
}),
265+
'publish-without-base': flags.boolean({
266+
default: false,
267+
description: 'Publish without base flag will publish all associated variant entries except base entry.',
255268
}),
256269
};
257270

@@ -278,15 +291,18 @@ PublishEntriesCommand.examples = [
278291
'csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN]',
279292
'',
280293
'Using --include-variants',
281-
'csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] [--include-variants]',
294+
'csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] [--include-variants]',
282295
'',
283296
'Using --entry-uid and --include-variants',
284-
'csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] --entry-uid [ENTRY UID] [--include-variants]',
297+
'csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] --entry-uid [ENTRY UID] [--include-variants]',
298+
'',
299+
'Using --include-variants and --publish-without-base',
300+
'csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] [--include-variants][--publish-without-base]',
285301
];
286302

287303
PublishEntriesCommand.aliases = ['cm:bulk-publish:entries'];
288304

289305
PublishEntriesCommand.usage =
290-
'cm:entries:publish [-a <value>] [--retry-failed <value>] [--bulk-publish <value>] [--publish-all-content-types] [--content-types <value>] [--locales <value>] [-e <value>] [-c <value>] [-y] [--branch <value>] [--delivery-token <value>] [--source-env <value>] [--entry-uid <value>] [--include-variants]';
306+
'cm:entries:publish [-a <value>] [--retry-failed <value>] [--bulk-publish <value>] [--publish-all-content-types] [--content-types <value>] [--locales <value>] [-e <value>] [-c <value>] [-y] [--branch <value>] [--delivery-token <value>] [--source-env <value>] [--entry-uid <value>] [--include-variants][--publish-without-base]';
291307

292308
module.exports = PublishEntriesCommand;

packages/contentstack-bulk-publish/src/commands/cm/entries/unpublish.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ class UnpublishCommand extends Command {
1919
unpublishFlags.onlyAssets = false;
2020
unpublishFlags.onlyEntries = true;
2121
unpublishFlags.apiVersion = unpublishFlags['api-version'] || '3';
22-
unpublishFlags.includeVariants = unpublishFlags['include-variants'];
22+
unpublishFlags.includeVariants = unpublishFlags['include-variants'] || false;
2323
delete unpublishFlags['api-version'];
2424
delete unpublishFlags['retry-failed'];
2525
delete unpublishFlags['bulk-unpublish'];
2626
delete unpublishFlags['content-type'];
2727
delete unpublishFlags['delivery-token'];
28+
delete unpublishFlags['include-variants'];
2829

2930
let updatedFlags;
3031
try {
@@ -60,7 +61,6 @@ class UnpublishCommand extends Command {
6061
updatedFlags.deliveryToken = await cliux.prompt('Enter delivery token of your source environment');
6162
}
6263
updatedFlags.bulkUnpublish = updatedFlags.bulkUnpublish === 'false' ? false : true;
63-
updatedFlags.includeVariantsFlag = updatedFlags.includeVariants;
6464
stack = await getStack(config);
6565
}
6666
if (!updatedFlags.deliveryToken && updatedFlags.deliveryToken.length === 0) {

packages/contentstack-bulk-publish/src/producer/cross-publish.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ async function bulkAction(stack, items, bulkPublish, filter, destEnv, apiVersion
5151

5252
if (variantsFlag) {
5353
entry.variants = items[index].data.variants || [];
54-
entry.publish_with_base_entry = true;
54+
entry.variant_rules = {
55+
publish_latest_base: true,
56+
publish_latest_base_conditionally: true
57+
};
5558
}
5659

5760
bulkPublishSet.push(JSON.parse(JSON.stringify(entry)));
@@ -210,7 +213,8 @@ async function getSyncEntries(
210213
if (variantsFlag) {
211214
for (let index = 0; index < entriesResponse?.items?.length; index++) {
212215
let variants = [];
213-
variants = await getVariantEntries(stack, entries[index].content_type_uid, entries, index, queryParamsObj);
216+
const entries = entriesResponse.items[index];
217+
variants = await getVariantEntries(stack, entries.content_type_uid, entriesResponse, index, queryParamsObj);
214218
if (variants.length > 0) {
215219
entriesResponse.items[index].data.variants = variants;
216220
}
@@ -268,10 +272,10 @@ async function getVariantEntries(stack, contentType, entries, index, queryParams
268272
skip: skip, // Adding skip parameter for pagination
269273
limit: 100, // Set a limit to fetch up to 100 entries per request
270274
};
271-
275+
const entryUid = entries.items[index].data.uid
272276
const variantsEntriesResponse = await stack
273277
.contentType(contentType)
274-
.entry(entries[index].data.uid)
278+
.entry(entryUid)
275279
.variants()
276280
.query(variantQueryParams)
277281
.find();

0 commit comments

Comments
 (0)