Skip to content
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

Fixed cross publish issue and updated variant entry publish payload #1569

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
924 changes: 443 additions & 481 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions packages/contentstack-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ EXAMPLES
$ csdx plugins
```

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

## `csdx plugins:add PLUGIN`

Expand Down Expand Up @@ -341,7 +341,7 @@ EXAMPLES
$ csdx plugins:inspect myplugin
```

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

## `csdx plugins:install PLUGIN`

Expand Down Expand Up @@ -390,7 +390,7 @@ EXAMPLES
$ csdx plugins:install someuser/someplugin
```

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

## `csdx plugins:link PATH`

Expand Down Expand Up @@ -420,7 +420,7 @@ EXAMPLES
$ csdx plugins:link myplugin
```

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

## `csdx plugins:remove [PLUGIN]`

Expand Down Expand Up @@ -461,7 +461,7 @@ FLAGS
--reinstall Reinstall all plugins after uninstalling.
```

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

## `csdx plugins:uninstall [PLUGIN]`

Expand Down Expand Up @@ -489,7 +489,7 @@ EXAMPLES
$ csdx plugins:uninstall myplugin
```

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

## `csdx plugins:unlink [PLUGIN]`

Expand Down Expand Up @@ -533,5 +533,5 @@ DESCRIPTION
Update installed plugins.
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.4/src/commands/plugins/update.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/update.ts)_
<!-- commandsstop -->
8 changes: 4 additions & 4 deletions packages/contentstack-bulk-publish/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -596,13 +596,13 @@ EXAMPLES

Using --include-variants

$ 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]
$ 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]



Using --entry-uid and --include-variants

$ 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]
$ 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]
```

## `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>]`
Expand Down Expand Up @@ -1042,13 +1042,13 @@ EXAMPLES

Using --include-variants

$ 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]
$ 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]



Using --entry-uid and --include-variants

$ 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]
$ 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]
```

_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)_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,20 @@ class PublishEntriesCommand extends Command {
entriesFlags['publish-all-content-types'] || entriesFlags.publishAllContentTypes || false;
entriesFlags.apiVersion = entriesFlags['api-version'] || '3';
entriesFlags.includeVariants = entriesFlags['include-variants'] || entriesFlags.includeVariants || false;
entriesFlags.publishWithoutBase = entriesFlags['publish-without-base'] || entriesFlags.publishWithoutBase || false;
entriesFlags.entryUid = entriesFlags['entry-uid'] || entriesFlags.entryUid;

if (entriesFlags.entryUid === undefined) {
delete entriesFlags['entryUid'];
}
delete entriesFlags['api-version'];
delete entriesFlags['retry-failed'];
delete entriesFlags['content-types'];
delete entriesFlags['bulk-publish'];
delete entriesFlags['publish-all-content-types'];
delete entriesFlags['include-variants'];
delete entriesFlags['entry-uid'];
delete entriesFlags['publish-without-base'];

let updatedFlags;
try {
Expand Down Expand Up @@ -59,8 +67,9 @@ class PublishEntriesCommand extends Command {
} else {
this.error('Please use `--alias` or `--stack-api-key` to proceed.', { exit: 2 });
}
updatedFlags.includeVariantsFlag = entriesFlags.includeVariants;
updatedFlags.entry_uid = entriesFlags.entryUid;
if (updatedFlags.publishWithoutBase && !updatedFlags.includeVariants) {
this.error('Please use `--include-variants` to proceed.', { exit: 2 });
}
updatedFlags.bulkPublish = updatedFlags.bulkPublish !== 'false';
stack = await getStack(config);
}
Expand Down Expand Up @@ -201,7 +210,7 @@ PublishEntriesCommand.flags = {
default: 'true',
}),
'api-version': flags.string({
description : "API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].",
description: 'API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].',
}),
'publish-all-content-types': flags.boolean({
description: '(optional) Publish all contenttypes (cannot be set when contentTypes flag is set)',
Expand Down Expand Up @@ -249,9 +258,13 @@ PublishEntriesCommand.flags = {
'delivery-token': flags.string({ description: 'Delivery token for source environment' }),
'source-env': flags.string({ description: 'Source environment' }),
'entry-uid': flags.string({ description: 'Entry Uid for publish all associated variant entries.' }),
'include-variants': flags.boolean({
'include-variants': flags.boolean({
default: false, // set the default value to false
description: 'Include Variants flag will publish all associated variant entries.'
description: 'Include Variants flag will publish all associated variant entries with base entry.',
}),
'publish-without-base': flags.boolean({
default: false,
description: 'Publish without base flag will publish all associated variant entries except base entry.',
}),
};

Expand All @@ -278,15 +291,18 @@ PublishEntriesCommand.examples = [
'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]',
'',
'Using --include-variants',
'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]',
'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]',
'',
'Using --entry-uid and --include-variants',
'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]',
'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]',
'',
'Using --include-variants and --publish-without-base',
'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]',
];

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

PublishEntriesCommand.usage =
'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]';
'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]';

module.exports = PublishEntriesCommand;
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ class UnpublishCommand extends Command {
unpublishFlags.onlyAssets = false;
unpublishFlags.onlyEntries = true;
unpublishFlags.apiVersion = unpublishFlags['api-version'] || '3';
unpublishFlags.includeVariants = unpublishFlags['include-variants'];
unpublishFlags.includeVariants = unpublishFlags['include-variants'] || false;
delete unpublishFlags['api-version'];
delete unpublishFlags['retry-failed'];
delete unpublishFlags['bulk-unpublish'];
delete unpublishFlags['content-type'];
delete unpublishFlags['delivery-token'];
delete unpublishFlags['include-variants'];

let updatedFlags;
try {
Expand Down Expand Up @@ -60,7 +61,6 @@ class UnpublishCommand extends Command {
updatedFlags.deliveryToken = await cliux.prompt('Enter delivery token of your source environment');
}
updatedFlags.bulkUnpublish = updatedFlags.bulkUnpublish === 'false' ? false : true;
updatedFlags.includeVariantsFlag = updatedFlags.includeVariants;
stack = await getStack(config);
}
if (!updatedFlags.deliveryToken && updatedFlags.deliveryToken.length === 0) {
Expand Down
12 changes: 8 additions & 4 deletions packages/contentstack-bulk-publish/src/producer/cross-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ async function bulkAction(stack, items, bulkPublish, filter, destEnv, apiVersion

if (variantsFlag) {
entry.variants = items[index].data.variants || [];
entry.publish_with_base_entry = true;
entry.variant_rules = {
publish_latest_base: true,
publish_latest_base_conditionally: true
};
}

bulkPublishSet.push(JSON.parse(JSON.stringify(entry)));
Expand Down Expand Up @@ -210,7 +213,8 @@ async function getSyncEntries(
if (variantsFlag) {
for (let index = 0; index < entriesResponse?.items?.length; index++) {
let variants = [];
variants = await getVariantEntries(stack, entries[index].content_type_uid, entries, index, queryParamsObj);
const entries = entriesResponse.items[index];
variants = await getVariantEntries(stack, entries.content_type_uid, entriesResponse, index, queryParamsObj);
if (variants.length > 0) {
entriesResponse.items[index].data.variants = variants;
}
Expand Down Expand Up @@ -268,10 +272,10 @@ async function getVariantEntries(stack, contentType, entries, index, queryParams
skip: skip, // Adding skip parameter for pagination
limit: 100, // Set a limit to fetch up to 100 entries per request
};

const entryUid = entries.items[index].data.uid
const variantsEntriesResponse = await stack
.contentType(contentType)
.entry(entries[index].data.uid)
.entry(entryUid)
.variants()
.query(variantQueryParams)
.find();
Expand Down
Loading
Loading