-
Notifications
You must be signed in to change notification settings - Fork 7
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
Global field #26
Changes from 4 commits
bda569b
1ef89f3
69f10fa
2138491
814e918
0b46024
ec36a89
ec8fb35
a1f7000
7b4df90
98afcf5
ca88fbb
452858d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,14 @@ var log = require('../util/log'); | |
var supress = require('../util/extensionsUidReplace'); | ||
var config = util.getConfig(); | ||
|
||
var concurrencyNo = 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 = []; | ||
|
@@ -28,6 +33,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]))); | ||
|
@@ -69,7 +75,7 @@ importContentTypes.prototype = { | |
}).catch(reject); | ||
}, { | ||
// seed 3 content types at a time | ||
concurrency: 3 | ||
concurrency: concurrencyNo | ||
}).then(function() { | ||
// content type seeidng completed | ||
self.requestOptions.method = 'PUT'; | ||
|
@@ -87,7 +93,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); | ||
}); | ||
|
@@ -132,6 +141,46 @@ importContentTypes.prototype = { | |
return reject(error); | ||
}); | ||
}); | ||
}, | ||
updateGlobalfields: function() { | ||
var self = this; | ||
return new Promise(function(resolve, reject) { | ||
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 fail to import '+ JSON.stringify(error.errors)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. failed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
return; | ||
}); | ||
} | ||
} | ||
}, { | ||
concurrency: concurrencyNo | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only concurrency works |
||
}).then(function() { | ||
return resolve(); | ||
}).catch(function(error) { | ||
// failed to update modified schemas back to their original form | ||
return reject(error); | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ var extension_supress = require('../util/extensionsUidReplace'); | |
var util = require('../util/'); | ||
var config = util.getConfig(); | ||
|
||
// var config = getConfig(); | ||
var concurrencyNo = 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); | ||
|
@@ -135,7 +135,7 @@ importEntries.prototype = { | |
return; | ||
} | ||
}, { | ||
concurrency: 1 | ||
concurrency: concurrencyNo | ||
}).then(function() { | ||
return self.unSupressFields().then(function() { | ||
return self.removeBuggedEntries().then(async function() { | ||
|
@@ -190,6 +190,9 @@ importEntries.prototype = { | |
return resolve(); | ||
} | ||
for (var eUid in entries) { | ||
// console.log("self contentstypess>>>", self.ctSchemas[ctUid]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove comments if not required |
||
// console.log("self contentstypess>>>", entries[eUid]) | ||
|
||
// will replace all old asset uid/urls with new ones | ||
entries[eUid] = lookupReplaceAssets({ | ||
content_type: self.ctSchemas[ctUid], | ||
|
@@ -288,7 +291,7 @@ importEntries.prototype = { | |
}); | ||
// create/update 5 entries at a time | ||
}, { | ||
concurrency: 1 | ||
concurrency: concurrencyNo | ||
}).then(function() { | ||
helper.writeFile(successEntryLogPath, self.success[ctUid]); | ||
helper.writeFile(failedEntryLogPath, self.fails[ctUid]); | ||
|
@@ -299,7 +302,7 @@ importEntries.prototype = { | |
}); | ||
// process one batch at a time | ||
}, { | ||
concurrency: 1 | ||
concurrency: concurrencyNo | ||
}).then(function() { | ||
log.success('Entries created successfully in ' + ctUid + ' content type in ' + lang + | ||
' locale!'); | ||
|
@@ -312,7 +315,7 @@ importEntries.prototype = { | |
eFilePath + '\' does not exist!'); | ||
} | ||
}, { | ||
concurrency: 1 | ||
concurrency: concurrencyNo | ||
}).then(function() { | ||
log.success('Entries created successfully in \'' + lang + '\' language'); | ||
return resolve(); | ||
|
@@ -331,7 +334,7 @@ importEntries.prototype = { | |
return Promise.map(self.createdEntriesWOUid, function(entry) { | ||
return self.fetchEntry(entry); | ||
}, { | ||
concurrency: 1 | ||
concurrency: concurrencyNo | ||
}).then(function() { | ||
helper.writeFile(failedWOPath, self.failedWO); | ||
log.success('Mapped entries without mapped uid successfully!'); | ||
|
@@ -441,7 +444,7 @@ importEntries.prototype = { | |
return; | ||
}); | ||
}, { | ||
concurrency: 1 | ||
concurrency: concurrencyNo | ||
}).then(function() { | ||
// batch completed successfully | ||
helper.writeFile(path.join(eFolderPath, 'success.json'), entries); | ||
|
@@ -455,7 +458,7 @@ importEntries.prototype = { | |
throw error; | ||
}); | ||
}, { | ||
concurrency: 1 | ||
concurrency: concurrencyNo | ||
}).then(function() { | ||
// finished updating entries with references | ||
log.success('Imported entries of Content Type: \'' + ctUid + '\' in language: \'' + lang + | ||
|
@@ -468,7 +471,7 @@ importEntries.prototype = { | |
throw error; | ||
}); | ||
}, { | ||
concurrency: 1 | ||
concurrency: concurrencyNo | ||
}).then(function() { | ||
// completed updating entry references | ||
log.success('Imported entries in \'' + lang + '\' language successfully!'); | ||
|
@@ -531,7 +534,7 @@ importEntries.prototype = { | |
}); | ||
// update 5 content types at a time | ||
}, { | ||
concurrency: 3 | ||
concurrency: concurrencyNo | ||
}).then(function() { | ||
return resolve(); | ||
}).catch(function(error) { | ||
|
@@ -610,7 +613,7 @@ importEntries.prototype = { | |
return; | ||
}); | ||
}, { | ||
concurrency: 3 | ||
concurrency: concurrencyNo | ||
}).then(function() { | ||
for (var i = 0; i < modifiedSchemas.length; i++) { | ||
if (modifiedSchemasUids.indexOf(modifiedSchemas[i].uid) !== -1) { | ||
|
@@ -667,7 +670,7 @@ importEntries.prototype = { | |
}); | ||
|
||
}, { | ||
concurrency: 3 | ||
concurrency: concurrencyNo | ||
}).then(function() { | ||
|
||
for (var i = 0; i < bugged.length; i++) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 imported\n ' + JSON.stringify(error.errors)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imported >> import There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
return; | ||
}); | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ var helper = require('../util/fs'); | |
var log = require('../util/log'); | ||
var util = require('../util/'); | ||
var extension_supress = require('../util/extensionsUidReplace'); | ||
var removeReferenceFields = require('../util/removeReferenceFields'); | ||
|
||
var config = util.getConfig(); | ||
var globalfieldsConfig = config.modules.globalfields; | ||
var globalfieldsFolderPath = path.resolve(config.data, globalfieldsConfig.dirName); | ||
|
@@ -26,6 +28,8 @@ if (!fs.existsSync(globalfieldsMapperPath)) { | |
mkdirp.sync(globalfieldsMapperPath); | ||
} | ||
|
||
global._globalField_pending = []; | ||
|
||
function importGlobalFields () { | ||
this.fails = []; | ||
this.success = []; | ||
|
@@ -52,8 +56,17 @@ importGlobalFields.prototype = { | |
} | ||
var snipUids = Object.keys(self.globalfields); | ||
return Promise.map(snipUids, function (snipUid) { | ||
var flag = { | ||
supressed: false | ||
}; | ||
var snip = self.globalfields[snipUid]; | ||
extension_supress(snip.schema); | ||
removeReferenceFields(snip.schema, flag); | ||
|
||
if(flag.supressed) { | ||
// eslint-disable-next-line no-undef | ||
_globalField_pending.push(snip.uid); | ||
} | ||
|
||
if (!self.snipUidMapper.hasOwnProperty(snipUid)) { | ||
var requestOption = { | ||
|
@@ -74,9 +87,10 @@ importGlobalFields.prototype = { | |
log.success(global_field_uid +' '+' globalfield created successfully'); | ||
return; | ||
}).catch(function (error) { | ||
if(error.error_code === 115) { | ||
// eslint-disable-next-line no-console | ||
log.error('Globalfield fail to import '+ JSON.stringify(error.errors)); | ||
if(error.errors.title[0]) { | ||
log.error('Globalfield already exists '); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add global field details in error logs |
||
} else { | ||
log.error('Globalfield fail to import '+ JSON.stringify(error.errors)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fail >> failed |
||
} | ||
self.fails.push(snip); | ||
return; | ||
|
@@ -90,8 +104,9 @@ importGlobalFields.prototype = { | |
}, { | ||
concurrency: 2 | ||
}).then(function () { | ||
// console.log("dattatatat", _globalField_pending); | ||
// globalfields have imported successfully | ||
helper.writeFile(globalfieldsSuccessPath, self.success); | ||
helper.writeFile(globalfieldsSuccessPath, self.success); | ||
// log.success('globalfields have been imported successfully!'); | ||
return resolve(); | ||
}).catch(function (error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change var name to concurrency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to reqConcurrency