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

Global field #26

Merged
merged 13 commits into from
Apr 17, 2020
9 changes: 4 additions & 5 deletions config/default.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
versioning: true,
versioning: false,
// pass locale, only to migrate entries from that locale
// not passing `locale` will migrate all the locales present
// locales: ['fr-fr'],
Expand Down Expand Up @@ -115,10 +115,9 @@ module.exports = {
stacks: '/stacks/',
labels: '/labels/'
},
preserveStackVersion: false
// if exisstingContentDir exists, no backup folder will be created
// rather, its value(path) will be used instead
// useBackedupDir: './_backup_413',
preserveStackVersion: false,
concurrency: 1
// , useBackedupDir: './_backup_617'
// is the no. of files to be copied/backed up concurrently
// backupConcurrency: 10,
};
13 changes: 8 additions & 5 deletions lib/import/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var log = require('../util/log');
var util = require('../util/');

var config = util.getConfig();
var reqConcurrency = config.concurrency;
var assetsConfig = config.modules.assets;
var assetsFolderPath = path.join(config.data, config.modules.assets.dirName);
var mapperDirPath = path.resolve(config.data, 'mapper', 'assets');
Expand Down Expand Up @@ -123,7 +124,7 @@ importAssets.prototype = {
return;
});
}, {
concurrency: 1
concurrency: reqConcurrency
}).then(function () {
log.success('Asset import completed successfully!');
// TODO: if there are failures, retry
Expand Down Expand Up @@ -173,7 +174,7 @@ importAssets.prototype = {
}).catch(reject);
}
}, {
concurrency: 1
concurrency: reqConcurrency
}).then(function () {
self.uidMapping[uid] = uidContainer[uid];
for (var url in urlContainer) {
Expand Down Expand Up @@ -259,12 +260,14 @@ importAssets.prototype = {
uidContainer[metadata.uid] = response.body.asset.uid;
urlContainer[metadata.url] = response.body.asset.url;
return resolve();
}).catch(function(error){
}).catch(function(error) {
// eslint-disable-next-line no-console
console.log(error);
log.error(error);
return reject(error);
});
});
},

importFolders: function () {
var self = this;
return new Promise(function (resolve, reject) {
Expand Down Expand Up @@ -303,7 +306,7 @@ importAssets.prototype = {
return;
}).catch(reject);
}, {
concurrency: 1
concurrency: reqConcurrency
}).then(function () {
self.mappedFolderUids = helper.readFile(mappedFolderPath);
// completed creating folders
Expand Down
62 changes: 58 additions & 4 deletions lib/import/content_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ var path = require('path');
var _ = require('lodash');
var Promise = require('bluebird');


var helper = require('../util/fs');
var request = require('../util/request');
var util = require('../util/');
var log = require('../util/log');
var supress = require('../util/extensionsUidReplace');
var config = util.getConfig();

var config = util.getConfig();
var reqConcurrency = config.concurrency;
var contentTypeConfig = config.modules.content_types;
var globalFieldConfig = config.modules.globalfields;
var globalfieldsFolderPath = path.resolve(config.data, globalFieldConfig.dirName);
var contentTypesFolderPath = path.resolve(config.data, contentTypeConfig.dirName);
var mapperFolderPath = path.join(config.data, 'mapper', 'content_types');
var globalFieldMapperFolderpath = helper.readFile(path.join(config.data, 'mapper', 'global_fields', 'success.json'));
var globalFieldUpdateFile = path.join(config.data, 'mapper', 'global_fields', 'success.json');
var skipFiles = ['__master.json', '__priority.json', 'schema.json'];
var fileNames = fs.readdirSync(path.join(contentTypesFolderPath));
var field_rules_ct = [];
Expand All @@ -28,6 +34,7 @@ var field_rules_ct = [];
function importContentTypes() {
var self = this;
this.contentTypes = [];
this.globalfields = helper.readFile(path.resolve(globalfieldsFolderPath, globalFieldConfig.fileName));
for (var index in fileNames) {
if (skipFiles.indexOf(fileNames[index]) === -1) {
this.contentTypes.push(helper.readFile(path.join(contentTypesFolderPath, fileNames[index])));
Expand Down Expand Up @@ -66,10 +73,12 @@ importContentTypes.prototype = {
return Promise.map(self.contentTypeUids, function(contentTypeUid) {
return self.seedContentTypes(contentTypeUid).then(function() {
return;
}).catch(reject);
}).catch(function(error) {
reject(error);
});
}, {
// seed 3 content types at a time
concurrency: 3
concurrency: reqConcurrency
}).then(function() {
// content type seeidng completed
self.requestOptions.method = 'PUT';
Expand All @@ -87,7 +96,10 @@ importContentTypes.prototype = {
}
log.success('Content types have been imported successfully!');
// content types have been successfully imported
return resolve();
return self.updateGlobalfields().then(function() {
return resolve();
}).catch(reject);

}).catch(reject);
}).catch(reject);
});
Expand Down Expand Up @@ -132,6 +144,48 @@ importContentTypes.prototype = {
return reject(error);
});
});
},

updateGlobalfields: function() {
var self = this;
return new Promise(function(resolve, reject) {
// eslint-disable-next-line no-undef
return Promise.map(_globalField_pending, function (globalfield) {
var lenGlobalField = (self.globalfields).length;
for(var i=0; i < lenGlobalField; i++) {
if(self.globalfields[i].uid == globalfield) {
self.requestGlobalfieldOptions = {
uri: config.host + config.apis.globalfields+globalfield,
headers: config.headers,
method: 'PUT',
json: {
global_field: self.globalfields[i]
}
};
return request(self.requestGlobalfieldOptions).then(function (response) {
var updateObjpos = _.findIndex(globalFieldMapperFolderpath, function(successobj) {
var global_field_uid = response.body.global_field.uid;
return global_field_uid == successobj;
});
globalFieldMapperFolderpath.splice(updateObjpos, 1, self.globalfields[i]);
helper.writeFile(globalFieldUpdateFile, globalFieldMapperFolderpath);
return;
}).catch(function (error) {
// eslint-disable-next-line no-console
log.error('Globalfield failed to update '+ JSON.stringify(error.errors));
return;
});
}
}
}, {
concurrency: reqConcurrency
}).then(function() {
return resolve();
}).catch(function(error) {
// failed to update modified schemas back to their original form
return reject(error);
});
});
}
};

Expand Down
24 changes: 12 additions & 12 deletions lib/import/entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var extension_supress = require('../util/extensionsUidReplace');
var util = require('../util/');
var config = util.getConfig();

// var config = getConfig();
var reqConcurrency = config.concurrency;
var eConfig = config.modules.entries;
var ePath = path.resolve(config.data, eConfig.dirName);
var ctPath = path.resolve(config.data, config.modules.content_types.dirName);
Expand Down Expand Up @@ -294,7 +294,7 @@ importEntries.prototype = {
});
// create/update 5 entries at a time
}, {
concurrency: 1
concurrency: reqConcurrency
}).then(function() {
helper.writeFile(successEntryLogPath, self.success[ctUid]);
helper.writeFile(failedEntryLogPath, self.fails[ctUid]);
Expand All @@ -305,7 +305,7 @@ importEntries.prototype = {
});
// process one batch at a time
}, {
concurrency: 1
concurrency: reqConcurrency
}).then(function() {
log.success('Entries created successfully in ' + ctUid + ' content type in ' + lang +
' locale!');
Expand All @@ -318,7 +318,7 @@ importEntries.prototype = {
eFilePath + '\' does not exist!');
}
}, {
concurrency: 1
concurrency: reqConcurrency
}).then(function() {
log.success('Entries created successfully in \'' + lang + '\' language');
return resolve();
Expand All @@ -337,7 +337,7 @@ importEntries.prototype = {
return Promise.map(self.createdEntriesWOUid, function(entry) {
return self.fetchEntry(entry);
}, {
concurrency: 1
concurrency: reqConcurrency
}).then(function() {
helper.writeFile(failedWOPath, self.failedWO);
log.success('Mapped entries without mapped uid successfully!');
Expand Down Expand Up @@ -447,7 +447,7 @@ importEntries.prototype = {
return;
});
}, {
concurrency: 1
concurrency: reqConcurrency
}).then(function() {
// batch completed successfully
helper.writeFile(path.join(eFolderPath, 'success.json'), entries);
Expand All @@ -461,7 +461,7 @@ importEntries.prototype = {
throw error;
});
}, {
concurrency: 1
concurrency: reqConcurrency
}).then(function() {
// finished updating entries with references
log.success('Imported entries of Content Type: \'' + ctUid + '\' in language: \'' + lang +
Expand All @@ -474,7 +474,7 @@ importEntries.prototype = {
throw error;
});
}, {
concurrency: 1
concurrency: reqConcurrency
}).then(function() {
// completed updating entry references
log.success('Imported entries in \'' + lang + '\' language successfully!');
Expand Down Expand Up @@ -527,7 +527,7 @@ importEntries.prototype = {
content_type: schema
}
};

return request(requestObject).then(function() {
return;
}).catch(function(error) {
Expand All @@ -537,7 +537,7 @@ importEntries.prototype = {
});
// update 5 content types at a time
}, {
concurrency: 3
concurrency: reqConcurrency
}).then(function() {
return resolve();
}).catch(function(error) {
Expand Down Expand Up @@ -615,7 +615,7 @@ importEntries.prototype = {
return;
});
}, {
concurrency: 3
concurrency: reqConcurrency
}).then(function() {
for (var i = 0; i < modifiedSchemas.length; i++) {
if (modifiedSchemasUids.indexOf(modifiedSchemas[i].uid) !== -1) {
Expand Down Expand Up @@ -672,7 +672,7 @@ importEntries.prototype = {
});

}, {
concurrency: 3
concurrency: reqConcurrency
}).then(function() {

for (var i = 0; i < bugged.length; i++) {
Expand Down
8 changes: 5 additions & 3 deletions lib/import/environments.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ importEnvironments.prototype = {
helper.writeFile(envUidMapperPath, self.envUidMapper);
return;
}).catch(function (error) {
self.fails.push(env);
// eslint-disable-next-line no-console
log.error('Environment: \'' + env.name + '\' failed to be imported\n ' + JSON.stringify(error.errors));
if(error.errors.name[0]) {
log.success('Environment: \'' + env.name + '\' already exists');
} else {
log.error('Environment: \'' + env.name + '\' failed to be import\n ' + JSON.stringify(error.errors));
}
return;
});
} else {
Expand Down
7 changes: 4 additions & 3 deletions lib/import/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ var request = require('../util/request');
var helper = require('../util/fs');
var log = require('../util/log');
var util = require('../util/');

var config = util.getConfig();
var reqConcurrency = config.concurrency;
var extensionsConfig = config.modules.extensions;
var extensionsFolderPath = path.resolve(config.data, extensionsConfig.dirName);
var extMapperPath = path.resolve(config.data, 'mapper', 'extensions');
Expand Down Expand Up @@ -73,7 +75,7 @@ importExtensions.prototype = {
return;
}).catch(function (error) {
self.fails.push(ext);
log.error('Extension: \'' + ext.title + '\' failed to be imported\n '+ JSON.stringify(error.errors));
log.error('Extension: \'' + ext.title + '\' failed to be import\n '+ JSON.stringify(error.errors));
return;
});
} else {
Expand All @@ -84,7 +86,7 @@ importExtensions.prototype = {
}
// import 2 extensions at a time
}, {
concurrency: 2
concurrency: reqConcurrency
}).then(function () {
// extensions have imported successfully
helper.writeFile(extSuccessPath, self.success);
Expand All @@ -94,7 +96,6 @@ importExtensions.prototype = {
// error while importing extensions
helper.writeFile(extFailsPath, self.fails);
log.error('Extension import failed');
console.log("errrr", JSON.stringify(error));
return reject(error);
});
});
Expand Down
Loading