Skip to content

Commit

Permalink
Merge pull request #1007 from contentstack/fix/CS-40867
Browse files Browse the repository at this point in the history
Updating the Entry Migration script to perform the merge operation on entries
  • Loading branch information
aman19K authored Aug 28, 2023
2 parents d534486 + 87dbd68 commit 2b24712
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
22 changes: 16 additions & 6 deletions packages/contentstack-branches/src/utils/entry-create-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export function entryCreateScript(contentType) {
return path.split('[').reduce((o, key) => o && o[key.replace(/\]$/, '')], obj);
}
function updateValueByPath(obj, path, newValue, type, index) {
function updateValueByPath(obj, path, newValue, type, fileIndex) {
path.split('[').reduce((o, key, index, arr) => {
if (index === arr.length - 1) {
if (type === 'file') {
o[key.replace(/]$/, '')][index] = newValue;
o[key.replace(/]$/, '')][fileIndex] = newValue;
} else {
o[key.replace(/]$/, '')][0].uid = newValue;
}
Expand Down Expand Up @@ -81,7 +81,7 @@ export function entryCreateScript(contentType) {
for (const i in schema) {
const currentPath = path ? path + '[' + schema[i].uid : schema[i].uid;
if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') {
findAssets(schema[i].schema, entry, refPath, currentPath);
findAssets(schema[i].schema, entry, refPath, currentPath + '[0]');
} else if (schema[i].data_type === 'blocks') {
for (const block in schema[i].blocks) {
{
Expand Down Expand Up @@ -386,6 +386,14 @@ export function entryCreateScript(contentType) {
assetUrlMapper[asset.url] = res && res.url;
}
};
function handleErrorMsg(err) {
if (err?.errorMessage) {
console.log(err.errorMessage);
} else if (err?.message) {
console.log(err.message);
}
}
const createEntryTask = () => {
return {
Expand Down Expand Up @@ -469,10 +477,12 @@ export function entryCreateScript(contentType) {
let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails }).catch(error => {
throw error;
});
if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
if(createdEntry){
if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
}
await updateEntry(createdEntry, entryDetails);
}
await updateEntry(createdEntry, entryDetails);
});
} catch (error) {
throw error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ export function entryCreateUpdateScript(contentType) {
return path.split('[').reduce((o, key) => o && o[key.replace(/\]$/, '')], obj);
}
function updateValueByPath(obj, path, newValue, type, index) {
function updateValueByPath(obj, path, newValue, type, fileIndex) {
path.split('[').reduce((o, key, index, arr) => {
if (index === arr.length - 1) {
if (type === 'file') {
o[key.replace(/]$/, '')][index] = newValue;
o[key.replace(/]$/, '')][fileIndex] = newValue;
} else {
o[key.replace(/]$/, '')][0].uid = newValue;
}
Expand Down Expand Up @@ -103,7 +103,7 @@ export function entryCreateUpdateScript(contentType) {
for (const i in schema) {
const currentPath = path ? path + '[' + schema[i].uid : schema[i].uid;
if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') {
findAssets(schema[i].schema, entry, refPath, currentPath);
findAssets(schema[i].schema, entry, refPath, currentPath + '[0]');
} else if (schema[i].data_type === 'blocks') {
for (const block in schema[i].blocks) {
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ export function entryUpdateScript(contentType) {
return path.split('[').reduce((o, key) => o && o[key.replace(/\]$/, '')], obj);
}
function updateValueByPath(obj, path, newValue, type, index) {
function updateValueByPath(obj, path, newValue, type, fileIndex) {
path.split('[').reduce((o, key, index, arr) => {
if (index === arr.length - 1) {
if (type === 'file') {
o[key.replace(/]$/, '')][index] = newValue;
o[key.replace(/]$/, '')][fileIndex] = newValue;
} else {
o[key.replace(/]$/, '')][0].uid = newValue;
}
Expand Down Expand Up @@ -103,7 +103,7 @@ export function entryUpdateScript(contentType) {
for (const i in schema) {
const currentPath = path ? path + '[' + schema[i].uid : schema[i].uid;
if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') {
findAssets(schema[i].schema, entry, refPath, currentPath);
findAssets(schema[i].schema, entry, refPath, currentPath + '[0]');
} else if (schema[i].data_type === 'blocks') {
for (const block in schema[i].blocks) {
{
Expand Down

0 comments on commit 2b24712

Please sign in to comment.