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 entry overwrite issues #1099

Merged
merged 2 commits into from
Oct 11, 2023
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
1 change: 1 addition & 0 deletions packages/contentstack-export/src/export/module-exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ModuleExporter {
try {
this.exportConfig.branchName = branch.uid;
this.exportConfig.branchDir = path.join(this.exportConfig.exportDir, branch.uid);
log(this.exportConfig, `Exporting content from branch ${branch.uid}`, 'success');
await this.export();
log(this.exportConfig, `The content of branch ${branch.uid} has been exported successfully!`, 'success');
} catch (error) {
Expand Down
55 changes: 33 additions & 22 deletions packages/contentstack-import/src/import/modules/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,24 @@ export default class EntriesImport extends BaseClass {
const onReject = ({ error, apiData: entry, additionalInfo }: any) => {
const { title, uid } = entry;
//Note: write existing entries into files to handler later
if (error?.errors?.title) {
if (this.importConfig.replaceExisting) {
entry.entryOldUid = uid;
entry.sourceEntryFilePath = path.join(basePath, additionalInfo.entryFileName); // stores source file path temporarily
existingEntriesFileHelper.writeIntoFile({ [uid]: entry } as any, { mapKeyVal: true });
}
if (!this.importConfig.skipExisting) {
log(this.importConfig, `Entry '${title}' already exists`, 'info');
if (error.errorCode === 119) {
if (error?.errors?.title || error?.errors?.uid) {
if (this.importConfig.replaceExisting) {
entry.entryOldUid = uid;
entry.sourceEntryFilePath = path.join(basePath, additionalInfo.entryFileName); // stores source file path temporarily
existingEntriesFileHelper.writeIntoFile({ [uid]: entry } as any, { mapKeyVal: true });
}
if (!this.importConfig.skipExisting) {
log(this.importConfig, `Entry '${title}' already exists`, 'info');
}
} else {
log(
this.importConfig,
`${title} entry of content type ${cTUid} in locale ${locale} failed to create`,
'error',
);
log(this.importConfig, formatError(error), 'error');
this.failedEntries.push({ content_type: cTUid, locale, entry: { uid, title } });
}
} else {
log(this.importConfig, `${title} entry of content type ${cTUid} in locale ${locale} failed to create`, 'error');
Expand Down Expand Up @@ -518,18 +528,19 @@ export default class EntriesImport extends BaseClass {
}) {
const { additionalInfo: { cTUid, locale } = {} } = apiParams;
return new Promise(async (resolve, reject) => {
const { items: [entryInStack] = [] }: any = await this.stack
.contentType(cTUid)
.entry()
.query({ query: { title: entry.title, locale } })
.findOne()
.catch((error: Error) => {
apiParams.reject({
error,
apiData: entry,
});
reject(true);
});
const { items: [entryInStack] = [] }: any =
(await this.stack
.contentType(cTUid)
.entry()
.query({ query: { title: entry.title, locale } })
.findOne()
.catch((error: Error) => {
apiParams.reject({
error,
apiData: entry,
});
reject(true);
})) || {};
if (entryInStack) {
const entryPayload = this.stack.contentType(cTUid).entry(entryInStack.uid);
Object.assign(entryPayload, entryInStack, cloneDeep(entry), {
Expand All @@ -539,7 +550,7 @@ export default class EntriesImport extends BaseClass {
_version: entryInStack._version,
});
return entryPayload
.update()
.update({ locale })
.then((response: any) => {
apiParams.resolve({
response,
Expand All @@ -556,7 +567,7 @@ export default class EntriesImport extends BaseClass {
});
} else {
apiParams.reject({
error: new Error(`Extension with title ${entry.title} not found in the stack`),
error: new Error(`Entry with title ${entry.title} not found in the stack`),
apiData: entry,
});
reject(true);
Expand Down