Skip to content

Commit

Permalink
Merge pull request #1205 from contentstack/fix/CS-42996
Browse files Browse the repository at this point in the history
Fix: Entry import fails if JSON RTE has a reference inside the table
  • Loading branch information
antonyagustine authored Dec 8, 2023
2 parents f6ecf00 + b157410 commit eb542b7
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 111 deletions.
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues",
"dependencies": {
"@contentstack/cli-cm-export": "~1.10.2",
"@contentstack/cli-cm-import": "~1.12.0",
"@contentstack/cli-cm-import": "~1.12.1",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.8",
"@colors/colors": "^1.5.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-import/1.12.0 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-import/1.12.1 darwin-arm64 node-v21.2.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-import",
"description": "Contentstack CLI plugin to import content into stack",
"version": "1.12.0",
"version": "1.12.1",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export default class ImportCommand extends Command {
'success',
);
} catch (error) {
trace(error, 'error', true);
log({ data: backupDir } as ImportConfig, `Failed to import stack content - ${formatError(error)}`, 'error');
log(
{ data: backupDir } as ImportConfig,
Expand Down
16 changes: 8 additions & 8 deletions packages/contentstack-import/src/import/modules/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import * as path from 'path';
import { isEmpty, values, cloneDeep, find, indexOf, forEach } from 'lodash';
import { ContentType, FsUtility } from '@contentstack/cli-utilities';
import { FsUtility } from '@contentstack/cli-utilities';
import {
fsUtil,
log,
Expand Down Expand Up @@ -125,7 +125,7 @@ export default class EntriesImport extends BaseClass {
await fileHelper.writeLargeFile(path.join(this.entriesMapperPath, 'uid-mapping.json'), this.entriesUidMapper); // TBD: manages mapper in one file, should find an alternative
fsUtil.writeFile(path.join(this.entriesMapperPath, 'failed-entries.json'), this.failedEntries);

if (this.autoCreatedEntries.length > 0) {
if (this.autoCreatedEntries?.length > 0) {
log(this.importConfig, 'Removing entries from master language which got created by default', 'info');
await this.removeAutoCreatedEntries().catch((error) => {
log(
Expand Down Expand Up @@ -528,8 +528,7 @@ export default class EntriesImport extends BaseClass {

async replaceEntriesHandler({
apiParams,
element: entry,
isLastRequest,
element: entry
}: {
apiParams: ApiOptions;
element: Record<string, string>;
Expand Down Expand Up @@ -672,6 +671,7 @@ export default class EntriesImport extends BaseClass {
if (this.jsonRteCTs.indexOf(cTUid) > -1) {
// the entries stored in eSuccessFilePath, have the same uids as the entries from source data
entry = restoreJsonRteEntryRefs(entry, sourceEntry, contentType.schema, {
uidMapper: this.entriesUidMapper,
mappedAssetUids: this.assetUidMapper,
mappedAssetUrls: this.assetUrlMapper,
});
Expand Down Expand Up @@ -785,13 +785,13 @@ export default class EntriesImport extends BaseClass {
const contentType: any = find(cTs, { uid: cTUid });
if (contentType.field_rules) {
const fieldDatatypeMap: { [key: string]: string } = {};
for (let i = 0; i < contentType.schema.length; i++) {
for (let i = 0; i < contentType.schema?.length; i++) {
const field = contentType.schema[i].uid;
fieldDatatypeMap[field] = contentType.schema[i].data_type;
}
let fieldRuleLength = contentType.field_rules.length;
let fieldRuleLength = contentType.field_rules?.length;
for (let k = 0; k < fieldRuleLength; k++) {
let fieldRuleConditionLength = contentType.field_rules[k].conditions.length;
let fieldRuleConditionLength = contentType.field_rules[k].conditions?.length;
for (let i = 0; i < fieldRuleConditionLength; i++) {
if (fieldDatatypeMap[contentType.field_rules[k].conditions[i].operand_field] === 'reference') {
let fieldRulesValue = contentType.field_rules[k].conditions[i].value;
Expand Down Expand Up @@ -905,7 +905,7 @@ export default class EntriesImport extends BaseClass {
locales: [],
entryUid: this.entriesUidMapper[entry.uid],
};
if (entry.publish_details && entry.publish_details.length > 0) {
if (entry.publish_details && entry.publish_details?.length > 0) {
forEach(entry.publish_details, (pubObject) => {
if (
this.envs.hasOwnProperty(pubObject.environment) &&
Expand Down
9 changes: 9 additions & 0 deletions packages/contentstack-import/src/types/entries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type EntryJsonRTEFieldDataType = {
uid?: string;
type?: string;
text?: string;
attrs?: { 'entry-uid'?: string; type?: string } & Record<string, any>;
children?: EntryJsonRTEFieldDataType[];
};

export { EntryJsonRTEFieldDataType };
2 changes: 2 additions & 0 deletions packages/contentstack-import/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,5 @@ export interface TermsConfig{

export { default as DefaultConfig } from './default-config';
export { default as ImportConfig } from './import-config';

export * from './entries'
Loading

0 comments on commit eb542b7

Please sign in to comment.