Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ module.exports = class ImportGlobalFields {
let snipUids = Object.keys(self.globalfields);
return Promise.map(
snipUids,
function (snipUid) {
async function (snipUid) {
let flag = { supressed: false };
let snip = self.globalfields[snipUid];
extension_supress(snip.schema, self.config.preserveStackVersion, self.installedExtensions);
removeReferenceFields(snip.schema, flag);
await removeReferenceFields(snip.schema, flag, self.stackAPIClient);

if (flag.supressed) {
// eslint-disable-next-line no-undef
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var _ = require('lodash');
const _ = require('lodash');

/* eslint-disable no-empty */
var removeReferenceFields = (module.exports = function (schema, flag) {
const removeReferenceFields = (module.exports = async function (schema, flag, stackAPIClient) {
for (let i = 0; i < schema.length; i++) {
if (schema[i].data_type === 'group') {
removeReferenceFields(schema[i].schema, flag);
Expand All @@ -11,27 +11,41 @@ var removeReferenceFields = (module.exports = function (schema, flag) {
}
} else if (schema[i].data_type === 'reference') {
flag.supressed = true;
schema.splice(i, 1);
--i;
if (schema.length < 1) {
schema.push({
data_type: 'text',
display_name: 'dummyTest',
uid: 'dummy_test',
field_metadata: {
description: '',
default_value: '',
version: 3,
},
format: '',
error_messages: {
// Check if content-type exists
// If exists, then no change should be required.
let isContentTypeError = false;
for (let j = 0; j < schema[i].reference_to.length; j++) {
try {
await stackAPIClient.contentType(schema[i].reference_to[j]).fetch();
} catch (error) {
// Else warn and modify the schema object.
isContentTypeError = true;
console.warn(`Content-type ${schema[i].reference_to[j]} does not exist. Removing the field from schema`);
}
}
if (isContentTypeError) {
schema.splice(i, 1);
--i;
if (schema.length < 1) {
schema.push({
data_type: 'text',
display_name: 'dummyTest',
uid: 'dummy_test',
field_metadata: {
description: '',
default_value: '',
version: 3,
},
format: '',
},
multiple: false,
mandatory: false,
unique: false,
non_localizable: false,
});
error_messages: {
format: '',
},
multiple: false,
mandatory: false,
unique: false,
non_localizable: false,
});
}
}
} else if( // handling entry references in json rte
schema[i].data_type === 'json'
Expand Down