@contentstack/cli-cm-import 0.1.1-beta.1 → 0.1.1-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,13 +10,12 @@ const _ = require('lodash')
10
10
  const mkdirp = require('mkdirp')
11
11
  const chalk = require('chalk')
12
12
 
13
- const request = require('../util/request')
14
13
  const helper = require('../util/fs')
15
14
  const {addlogs} = require('../util/log')
16
15
  const lookupReplaceAssets = require('../util/lookupReplaceAssets')
17
16
  const lookupReplaceEntries = require('../util/lookupReplaceEntries')
18
- const supress = require('../util/supress-mandatory-fields')
19
- const extension_supress = require('../util/extensionsUidReplace')
17
+ const suppress = require('../util/supress-mandatory-fields')
18
+ const extension_suppress = require('../util/extensionsUidReplace')
20
19
  const util = require('../util')
21
20
  let config = util.getConfig()
22
21
  const stack = require('../util/contentstack-management-sdk')
@@ -37,12 +36,10 @@ let uniqueUidMapperPath
37
36
  let modifiedSchemaPath
38
37
  let createdEntriesWOUidPath
39
38
  let failedWOPath
40
- let publishEntryUid
39
+ let masterLanguage
41
40
 
42
-
43
- let masterLanguage = config.master_locale
44
41
  let skipFiles = ['__master.json', '__priority.json', 'schema.json']
45
- let entryBatchLimit = eConfig.batchLimit || 16
42
+ let entryBatchLimit = config.rateLimit || 10
46
43
 
47
44
  function importEntries() {
48
45
  let self = this
@@ -74,38 +71,21 @@ function importEntries() {
74
71
  // Entries that failed to get created OR updated
75
72
  this.fails = []
76
73
 
77
- this.languages = helper.readFile(lPath)
78
-
79
74
  let files = fs.readdirSync(ctPath)
80
-
81
75
  this.environment = helper.readFile(environmentPath)
82
-
83
76
  for (let index in files) {
84
- try {
85
- if (skipFiles.indexOf(files[index]) === -1) {
86
- if (files[index] != 'field_rules_uid.json') {
87
- let schema = require(path.resolve(path.join(ctPath, files[index])))
88
- self.ctSchemas[schema.uid] = schema
77
+ if (index) {
78
+ try {
79
+ if (skipFiles.indexOf(files[index]) === -1) {
80
+ if (files[index] != 'field_rules_uid.json') {
81
+ let schema = require(path.resolve(path.join(ctPath, files[index])))
82
+ self.ctSchemas[schema.uid] = schema
83
+ }
89
84
  }
85
+ } catch (error) {
86
+ console.error(error)
87
+ process.exit(0)
90
88
  }
91
- } catch (error) {
92
- console.error(error)
93
- process.exit(0)
94
- }
95
- }
96
-
97
- this.mappedAssetUids = helper.readFile(mappedAssetUidPath)
98
- this.mappedAssetUrls = helper.readFile(mappedAssetUrlPath)
99
-
100
- this.mappedAssetUids = this.mappedAssetUids || {}
101
- this.mappedAssetUrls = this.mappedAssetUrls || {}
102
-
103
- this.requestOptionTemplate = {
104
- // /v3/content_types/
105
- uri: config.host + config.apis.content_types,
106
- headers: config.headers,
107
- json: {
108
- entry: {}
109
89
  }
110
90
  }
111
91
  }
@@ -114,71 +94,81 @@ importEntries.prototype = {
114
94
  /**
115
95
  * Start point for entry import
116
96
  * @return promise
117
- */
97
+ */
118
98
  start: async function (credentialConfig) {
119
99
  let self = this
120
100
  config = credentialConfig
121
101
  client = stack.Client(config)
122
- addlogs(config, 'Migrating entry', 'success')
123
- return new Promise(async function (resolve, reject) {
102
+ masterLanguage = config.master_locale
103
+ addlogs(config, 'Migrating entries', 'success')
104
+ let languages = helper.readFile(lPath)
105
+ return new Promise(function (resolve, reject) {
124
106
  let langs = [masterLanguage.code]
125
- for (let i in self.languages) {
126
- langs.push(self.languages[i].code)
107
+ for (let i in languages) {
108
+ if (i) {
109
+ langs.push(languages[i].code)
110
+ }
127
111
  }
128
112
 
113
+ // Step 1: Removes filed rules from content type
114
+ // This allows to handle cases like self references and circular reference
115
+ // if mandatory reference fields are not filed in entries then avoids the error
116
+ // Also remove field visibility rules
129
117
  return self.supressFields().then(async function () {
118
+ let mappedAssetUids = helper.readFile(mappedAssetUidPath) || {}
119
+ let mappedAssetUrls = helper.readFile(mappedAssetUrlPath) || {}
120
+
121
+ // Step 2: Iterate over available languages to create entries in each.
130
122
  let counter = 0
131
123
  return Promise.map(langs, async function () {
132
124
  let lang = langs[counter]
133
- if ((config.hasOwnProperty('onlylocales') && config.onlylocales.indexOf(lang) !== -1) || !
134
- config.hasOwnProperty('onlylocales')) {
135
- await self.createEntries(lang)
136
- // .then(async function () {
137
- await self.getCreatedEntriesWOUid()
138
- // .then(async function () {
139
- await self.repostEntries(lang)
140
- // .then(function () {
141
- addlogs(config, 'Successfully imported \'' + lang + '\' entries!', 'success')
142
- counter++
143
- // })
144
- // })
145
- // })
125
+ if ((config.hasOwnProperty('onlylocales') && config.onlylocales.indexOf(lang) !== -1) || !config.hasOwnProperty('onlylocales')) {
126
+ await self.createEntries(lang, mappedAssetUids, mappedAssetUrls)
127
+ await self.getCreatedEntriesWOUid()
128
+ await self.repostEntries(lang)
129
+ addlogs(config, 'Successfully imported \'' + lang + '\' entries!', 'success')
130
+ counter++
146
131
  } else {
147
132
  addlogs(config, lang + ' has not been configured for import, thus skipping it', 'success')
148
- counter++
133
+ counter++
149
134
  }
150
135
  }, {
151
- concurrency: 1
136
+ concurrency: 1,
152
137
  }).then(async function () {
153
- await self.unSupressFields()
154
- //.then(function () {
155
- await self.removeBuggedEntries()
156
- //.then(async function () {
157
- let ct_field_visibility_uid = helper.readFile(path.join(ctPath + '/field_rules_uid.json'))
158
- let ct_files = fs.readdirSync(ctPath)
159
- if (ct_field_visibility_uid && ct_field_visibility_uid != 'undefined') {
160
- for (let index = 0; index < ct_field_visibility_uid.length; index++) {
161
- if (ct_files.indexOf(ct_field_visibility_uid[index] + '.json') > -1) {
162
- let schema = require(path.resolve(ctPath, ct_field_visibility_uid[index]))
163
- await self.field_rules_update(schema)
164
- }
165
- }
138
+ // Step 3: Revert all the changes done in content type in step 1
139
+ await self.unSuppressFields()
140
+ await self.removeBuggedEntries()
141
+ let ct_field_visibility_uid = helper.readFile(path.join(ctPath + '/field_rules_uid.json'))
142
+ let ct_files = fs.readdirSync(ctPath)
143
+ if (ct_field_visibility_uid && ct_field_visibility_uid != 'undefined') {
144
+ for (let index = 0; index < ct_field_visibility_uid.length; index++) {
145
+ if (ct_files.indexOf(ct_field_visibility_uid[index] + '.json') > -1) {
146
+ let schema = require(path.resolve(ctPath, ct_field_visibility_uid[index]))
147
+ await self.field_rules_update(schema)
166
148
  }
167
- addlogs(config, chalk.green('Entries have been imported successfully!'), 'success')
149
+ }
150
+ }
151
+ addlogs(config, chalk.green('Entries have been imported successfully!'), 'success')
152
+ if (config.entriesPublish) {
153
+ return self.publish(langs).then(function () {
154
+ addlogs(config, chalk.green('All the entries have been published successfully'), 'success')
168
155
  return resolve()
169
- // })
170
- // })
156
+ }).catch(errors => {
157
+ addlogs(config, chalk.error('Some entries might have failed to publish.'), 'error')
158
+ return reject(errors)
159
+ })
160
+ }
161
+ return resolve()
171
162
  })
172
163
  }).catch(function (error) {
173
164
  return reject(error)
174
165
  })
175
- }).catch(error => {
176
166
  })
177
167
  },
178
168
 
179
- createEntries: function (lang) {
169
+ createEntries: function (lang, mappedAssetUids, mappedAssetUrls) {
180
170
  let self = this
181
- return new Promise(async function (resolve, reject) {
171
+ return new Promise(function (resolve, reject) {
182
172
  let contentTypeUids = Object.keys(self.ctSchemas)
183
173
  if (fs.existsSync(entryUidMapperPath)) {
184
174
  self.mappedUids = helper.readFile(entryUidMapperPath)
@@ -196,84 +186,118 @@ importEntries.prototype = {
196
186
  let failedEntryLogPath = path.join(eLogFolderPath, 'fails.json')
197
187
  let createdEntriesPath = path.join(eLogFolderPath, 'created-entries.json')
198
188
  let createdEntries = {}
189
+ let stack = client.stack({api_key: config.target_stack, management_token: config.management_token})
190
+
199
191
  if (fs.existsSync(createdEntriesPath)) {
200
192
  createdEntries = helper.readFile(createdEntriesPath)
201
193
  createdEntries = createdEntries || {}
202
194
  }
203
195
  if (fs.existsSync(eFilePath)) {
204
196
  let entries = helper.readFile(eFilePath)
205
- if (!_.isPlainObject(entries)) {
197
+ if (!_.isPlainObject(entries) || _.isEmpty(entries)) {
206
198
  addlogs(config, chalk.white('No entries were found for Content type:\'' + ctUid + '\' in \'' + lang +
207
- '\' language!'), 'success')
208
- return resolve()
209
- }
210
- for (let eUid in entries) {
211
- // will replace all old asset uid/urls with new ones
212
- entries[eUid] = lookupReplaceAssets({
213
- content_type: self.ctSchemas[ctUid],
214
- entry: entries[eUid]
215
- }, self.mappedAssetUids, self.mappedAssetUrls, eLangFolderPath)
216
- }
217
- let eUids = Object.keys(entries)
218
- let batches = []
219
-
220
- // Run entry creation in batches of ~16~ entries
221
- for (let i = 0; i < eUids.length; i += entryBatchLimit) {
222
- batches.push(eUids.slice(i, i + entryBatchLimit))
223
- }
199
+ '\' language!'), 'success')
200
+ } else {
201
+ addlogs(config, `Creating entries for content type ${ctUid} in language ${lang} ...`, 'success')
202
+ for (let eUid in entries) {
203
+ if (eUid) {
204
+ // will replace all old asset uid/urls with new ones
205
+ entries[eUid] = lookupReplaceAssets({
206
+ content_type: self.ctSchemas[ctUid],
207
+ entry: entries[eUid],
208
+ }, mappedAssetUids, mappedAssetUrls, eLangFolderPath)
209
+ }
210
+ }
211
+ let eUids = Object.keys(entries)
212
+ let batches = []
224
213
 
225
- return Promise.map(batches, async function (batch) {
226
- return Promise.map(batch, async function (eUid) {
227
- //if entry is already created
228
- if (createdEntries.hasOwnProperty(eUid)) {
229
- addlogs(config, ('Skipping ' + JSON.stringify({
230
- content_type: ctUid,
231
- locale: lang,
232
- oldEntryUid: eUid,
233
- newEntryUid: createdEntries[eUid]
234
- }) + ' as it is already created'), 'success')
235
- self.success[ctUid] = createdEntries[eUid]
236
- // if its a non-master language, i.e. the entry isn't present in the master language
237
- if (lang !== masterLanguage) {
238
- self.uniqueUids[eUid] = self.uniqueUids[eUid] || {}
239
- if (self.uniqueUids[eUid].locales) {
240
- self.uniqueUids[eUid].locales.push(lang)
241
- } else {
242
- self.uniqueUids[eUid].locales = [lang]
214
+ // Run entry creation in batches of ~16~ entries
215
+ for (let i = 0; i < eUids.length; i += Math.round(entryBatchLimit / 3)) {
216
+ batches.push(eUids.slice(i, i + Math.round(entryBatchLimit / 3)))
217
+ }
218
+ return Promise.map(batches, async function (batch) {
219
+ return Promise.map(batch, async function (eUid) {
220
+ // if entry is already created
221
+ if (createdEntries.hasOwnProperty(eUid)) {
222
+ addlogs(config, ('Skipping ' + JSON.stringify({
223
+ content_type: ctUid,
224
+ locale: lang,
225
+ oldEntryUid: eUid,
226
+ newEntryUid: createdEntries[eUid],
227
+ }) + ' as it is already created'), 'success')
228
+ self.success[ctUid] = createdEntries[eUid]
229
+ // if its a non-master language, i.e. the entry isn't present in the master language
230
+ if (lang !== masterLanguage) {
231
+ self.uniqueUids[eUid] = self.uniqueUids[eUid] || {}
232
+ if (self.uniqueUids[eUid].locales) {
233
+ self.uniqueUids[eUid].locales.push(lang)
234
+ } else {
235
+ self.uniqueUids[eUid].locales = [lang]
236
+ }
237
+ self.uniqueUids[eUid].content_type = ctUid
243
238
  }
244
- self.uniqueUids[eUid].content_type = ctUid
239
+ return
245
240
  }
246
- return
247
- }
248
- let requestObject = {
249
- qs: {
250
- locale: lang
251
- },
252
- json: {
253
- entry: entries[eUid]
241
+ let requestObject = {
242
+ qs: {
243
+ locale: lang,
244
+ },
245
+ json: {
246
+ entry: entries[eUid],
247
+ },
254
248
  }
255
- }
256
-
257
- if (self.mappedUids.hasOwnProperty(eUid)) {
258
- return client.stack({api_key: config.target_stack, management_token: config.management_token}).contentType(ctUid).entry(self.mappedUids[eUid]).fetch()
259
- .then(entryToUpdate => {
260
- Object.assign(entryToUpdate, _.cloneDeep(requestObject.json.entry))
261
- return entryToUpdate.update({locale: entryToUpdate.locale}).then(async result => {
262
- if (config.entriesPublish) {
263
- if (entries[eUid].publish_details.length > 0) {
264
- if (self.mappedUids.hasOwnProperty(eUid)) {
265
- publishEntryUid = self.mappedUids[eUid]
249
+ if (self.mappedUids.hasOwnProperty(eUid)) {
250
+ let entryToUpdate = stack.contentType(ctUid).entry(self.mappedUids[eUid])
251
+ Object.assign(entryToUpdate, _.cloneDeep(entries[eUid]))
252
+ return entryToUpdate.update({locale: entryToUpdate.locale}).then(async entryResponse => {
253
+ self.success[ctUid] = self.success[ctUid] || []
254
+ self.success[ctUid].push(entries[eUid])
255
+ if (!self.mappedUids.hasOwnProperty(eUid)) {
256
+ self.mappedUids[eUid] = entryResponse.uid
257
+ createdEntries = entryResponse
258
+ // if its a non-master language, i.e. the entry isn't present in the master language
259
+ if (lang !== masterLanguage) {
260
+ self.uniqueUids[eUid] = self.uniqueUids[eUid] || {}
261
+ if (self.uniqueUids[eUid].locales) {
262
+ self.uniqueUids[eUid].locales.push(lang)
263
+ } else {
264
+ self.uniqueUids[eUid].locales = [lang]
265
+ }
266
+ self.uniqueUids[eUid].content_type = ctUid
267
+ }
268
+ }
269
+ }).catch(function (err) {
270
+ let error = JSON.parse(err.message)
271
+ addlogs(config, chalk.red('Error updating entry', JSON.stringify(error)), 'error')
272
+ self.fails.push({
273
+ content_type: ctUid,
274
+ locale: lang,
275
+ entry: entries[eUid],
276
+ error: error,
277
+ })
278
+ return err
279
+ })
280
+ }
281
+ delete requestObject.json.entry.publish_details
282
+ return client.stack({api_key: config.target_stack, management_token: config.management_token}).contentType(ctUid).entry().create(requestObject.json)
283
+ .then(async entryResponse => {
284
+ self.success[ctUid] = self.success[ctUid] || []
285
+ self.success[ctUid].push(entries[eUid])
286
+ if (!self.mappedUids.hasOwnProperty(eUid)) {
287
+ self.mappedUids[eUid] = entryResponse.uid
288
+ createdEntries = entryResponse
289
+ // if its a non-master language, i.e. the entry isn't present in the master language
290
+ if (lang !== masterLanguage) {
291
+ self.uniqueUids[eUid] = self.uniqueUids[eUid] || {}
292
+ if (self.uniqueUids[eUid].locales) {
293
+ self.uniqueUids[eUid].locales.push(lang)
266
294
  } else {
267
- publishEntryUid = createdEntries.uid
295
+ self.uniqueUids[eUid].locales = [lang]
268
296
  }
269
- await self.publish(publishEntryUid, ctUid, lang, entries[eUid])
270
- // .then(function () {
271
- // })
297
+ self.uniqueUids[eUid].content_type = ctUid
272
298
  }
273
299
  }
274
- return
275
- }).catch(function (err) {
276
- let error = JSON.parse(err.message)
300
+ }).catch(function (error) {
277
301
  if (error.hasOwnProperty('error_code') && error.error_code === 119) {
278
302
  if (error.errors.title) {
279
303
  addlogs(config, 'Entry ' + eUid + ' already exist, skip to avoid creating a duplicate entry', 'error')
@@ -284,10 +308,10 @@ importEntries.prototype = {
284
308
  content_type: ctUid,
285
309
  locale: lang,
286
310
  entry: entries[eUid],
287
- error: error
311
+ error: error,
288
312
  })
289
313
  helper.writeFile(createdEntriesWOUidPath, self.createdEntriesWOUid)
290
- return;
314
+ return
291
315
  }
292
316
  // TODO: if status code: 422, check the reason
293
317
  // 429 for rate limit
@@ -296,98 +320,40 @@ importEntries.prototype = {
296
320
  content_type: ctUid,
297
321
  locale: lang,
298
322
  entry: entries[eUid],
299
- error: error
323
+ error: error,
300
324
  })
301
325
  })
302
- })
303
- } else {
304
- return client.stack({api_key: config.target_stack, management_token: config.management_token}).contentType(ctUid).entry().create(requestObject.json)
305
- .then(async entryResponse => {
306
- self.success[ctUid] = self.success[ctUid] || []
307
- self.success[ctUid].push(entries[eUid])
308
- if (!self.mappedUids.hasOwnProperty(eUid)) {
309
- self.mappedUids[eUid] = entryResponse.uid
310
- createdEntries = entryResponse
311
- // if its a non-master language, i.e. the entry isn't present in the master language
312
- if (lang !== masterLanguage) {
313
- self.uniqueUids[eUid] = self.uniqueUids[eUid] || {}
314
- if (self.uniqueUids[eUid].locales) {
315
- self.uniqueUids[eUid].locales.push(lang)
316
- } else {
317
- self.uniqueUids[eUid].locales = [lang]
318
- }
319
- self.uniqueUids[eUid].content_type = ctUid
320
- }
321
- }
322
326
 
323
- if (config.entriesPublish) {
324
- if (entries[eUid].publish_details.length > 0) {
325
- if (self.mappedUids.hasOwnProperty(eUid)) {
326
- publishEntryUid = self.mappedUids[eUid]
327
- } else {
328
- publishEntryUid = createdEntries.uid
329
- }
330
- await self.publish(publishEntryUid, ctUid, lang, entries[eUid])
331
- // .then(function () {
332
- // })
333
- }
334
- }
335
- return;
336
- }).catch(function (error) {
337
- // let error = JSON.parse(err.message)
338
- if (error.hasOwnProperty('error_code') && error.error_code === 119) {
339
- if (error.errors.title) {
340
- addlogs(config, 'Entry ' + eUid + ' already exist, skip to avoid creating a duplicate entry', 'error')
341
- } else {
342
- addlogs(config, chalk.red('Error creating entry due to: ' + JSON.stringify(error)), 'error')
343
- }
344
- self.createdEntriesWOUid.push({
345
- content_type: ctUid,
346
- locale: lang,
347
- entry: entries[eUid],
348
- error: error
349
- })
350
- helper.writeFile(createdEntriesWOUidPath, self.createdEntriesWOUid)
351
- return;
352
- }
353
- // TODO: if status code: 422, check the reason
354
- // 429 for rate limit
355
- addlogs(config, chalk.red('Error creating entry', JSON.stringify(error)), 'error')
356
- self.fails.push({
357
- content_type: ctUid,
358
- locale: lang,
359
- entry: entries[eUid],
360
- error: error
361
- })
327
+ // create/update 5 entries at a time
328
+ }, {
329
+ concurrency: 1,
330
+ }).then(function () {
331
+ helper.writeFile(successEntryLogPath, self.success[ctUid])
332
+ helper.writeFile(failedEntryLogPath, self.fails[ctUid])
333
+ helper.writeFile(entryUidMapperPath, self.mappedUids)
334
+ helper.writeFile(uniqueUidMapperPath, self.uniqueUids)
335
+ helper.writeFile(createdEntriesPath, createdEntries)
362
336
  })
363
- }
364
- // create/update 5 entries at a time
337
+ // process one batch at a time
365
338
  }, {
366
- concurrency: reqConcurrency
339
+ concurrency: 1,
367
340
  }).then(function () {
368
- helper.writeFile(successEntryLogPath, self.success[ctUid])
369
- helper.writeFile(failedEntryLogPath, self.fails[ctUid])
370
- helper.writeFile(entryUidMapperPath, self.mappedUids)
371
- helper.writeFile(uniqueUidMapperPath, self.uniqueUids)
372
- helper.writeFile(createdEntriesPath, createdEntries)
341
+ if (self.success && self.success[ctUid] && self.success[ctUid].length > 0)
342
+ addlogs(config, self.success[ctUid].length + ' entries created successfully in ' + ctUid + ' content type in ' + lang +
343
+ ' locale!', 'success')
344
+ if (self.fails && self.fails[ctUid] && self.fails[ctUid].length > 0)
345
+ addlogs(config, self.fails[ctUid].length + ' entries failed to create in ' + ctUid + ' content type in ' + lang +
346
+ ' locale!', 'error')
347
+ self.success[ctUid] = []
348
+ self.fails[ctUid] = []
373
349
  })
374
- // process one batch at a time
375
- }, {
376
- concurrency: reqConcurrency
377
- }).then(function () {
378
- addlogs(config, 'Entries created successfully in ' + ctUid + ' content type in ' + lang +
379
- ' locale!', 'success')
380
- self.success[ctUid] = []
381
- self.fails[ctUid] = []
382
-
383
- })
350
+ }
384
351
  } else {
385
- addlogs(config, chalk.red('Unable to find entry file path for ' + ctUid + ' content type!\nThe file \'' +
386
- eFilePath + '\' does not exist!'), 'error')
387
-
352
+ addlogs(config, chalk.white('Unable to find entry file path for ' + ctUid + ' content type!\nThe file \'' +
353
+ eFilePath + '\' does not exist!'), 'error')
388
354
  }
389
355
  }, {
390
- concurrency: reqConcurrency
356
+ concurrency: reqConcurrency,
391
357
  }).then(function () {
392
358
  addlogs(config, chalk.green('Entries created successfully in \'' + lang + '\' language'), 'success')
393
359
  return resolve()
@@ -402,20 +368,19 @@ importEntries.prototype = {
402
368
  return new Promise(function (resolve) {
403
369
  self.createdEntriesWOUid = helper.readFile(createdEntriesWOUidPath)
404
370
  self.failedWO = []
405
- if (_.isArray(self.createdEntriesWOUid) && self.createdEntriesWOUid.length) {
371
+ if (_.isArray(self.createdEntriesWOUid) && self.createdEntriesWOUid.length > 0) {
406
372
  return Promise.map(self.createdEntriesWOUid, function (entry) {
407
373
  return self.fetchEntry(entry)
408
374
  }, {
409
- concurrency: reqConcurrency
375
+ concurrency: reqConcurrency,
410
376
  }).then(function () {
411
377
  helper.writeFile(failedWOPath, self.failedWO)
412
378
  addlogs(config, 'Mapped entries without mapped uid successfully!', 'success')
413
379
  return resolve()
414
380
  })
415
- } else {
416
- addlogs(config, 'No entries without mapped uid found!', 'success')
417
- return resolve()
418
381
  }
382
+ addlogs(config, 'No entries without mapped uid found!', 'success')
383
+ return resolve()
419
384
  })
420
385
  },
421
386
  repostEntries: function (lang) {
@@ -431,14 +396,14 @@ importEntries.prototype = {
431
396
 
432
397
  if (!fs.existsSync(eSuccessFilePath)) {
433
398
  addlogs(config, 'Success file was not found at: ' + eSuccessFilePath, 'success')
434
- return resolve()
399
+ return
435
400
  }
436
401
 
437
402
  let entries = helper.readFile(eSuccessFilePath)
438
403
  entries = entries || []
439
404
  if (entries.length === 0) {
440
405
  addlogs(config, 'No entries were created to be updated in \'' + lang + '\' language!', 'success')
441
- return resolve()
406
+ return
442
407
  }
443
408
 
444
409
  // Keep track of entries that have their references updated
@@ -459,185 +424,173 @@ importEntries.prototype = {
459
424
  let uid = entry.uid
460
425
  let _entry = lookupReplaceEntries({
461
426
  content_type: schema,
462
- entry: entry
427
+ entry: entry,
463
428
  }, _.clone(self.mappedUids), refUidMapperPath)
464
429
  // if there's self references, the uid gets replaced
465
430
  _entry.uid = uid
466
431
  return _entry
467
432
  } catch (error) {
468
433
  console.error(error)
434
+ return error
469
435
  }
470
436
  })
471
437
 
472
438
  // Run entry creation in batches of ~16~ entries
473
- for (let i = 0; i < entries.length; i += entryBatchLimit) {
474
- batches.push(entries.slice(i, i + entryBatchLimit))
439
+ for (let i = 0; i < entries.length; i += Math.round(entryBatchLimit / 3)) {
440
+ batches.push(entries.slice(i, i + Math.round(entryBatchLimit / 3)))
475
441
  }
476
- return Promise.map(batches, function (batch, index) {
477
- return Promise.map(batch, function (entry) {
442
+ return Promise.map(batches, async function (batch, index) {
443
+ return Promise.map(batch, async function (entry) {
478
444
  entry.uid = self.mappedUids[entry.uid]
479
445
  if (refsUpdatedUids.indexOf(entry.uid) !== -1) {
480
446
  addlogs(config, 'Entry: ' + entry.uid + ' in Content Type: ' + ctUid + ' in lang: ' +
481
- lang + ' references fields are already updated.', 'success')
482
- return;
483
- }
484
-
485
- let requestObject = {
486
- qs: {
487
- locale: lang
488
- },
489
- json: {
490
- entry: entry
491
- }
447
+ lang + ' references fields are already updated.', 'success')
448
+ return
492
449
  }
493
450
 
494
- client.stack({api_key: config.target_stack, management_token: config.management_token}).contentType(ctUid).entry(entry.uid).fetch(requestObject.qs)
495
- .then(entryResponse => {
496
- Object.assign(entryResponse, _.cloneDeep(entry))
451
+ let promiseResult = new Promise((resolve, reject) => {
452
+ let entryResponse = client.stack({api_key: config.target_stack, management_token: config.management_token}).contentType(ctUid).entry(entry.uid)
453
+ Object.assign(entryResponse, entry)
497
454
  delete entryResponse.publish_details
498
- return entryResponse.update()
499
- })
500
- .then(response => {
501
- for (let j = 0; j < entries.length; j++) {
502
- if (entries[j].uid === response.uid) {
503
- entries[j] = response
504
- break;
505
- }
506
- }
507
- if (config.entriesPublish) {
508
- if (entry.publish_details.length > 0) {
509
- let entryUid = response
510
- return self.publish(entryUid.uid, ctUid, lang, entry).then(function () {
511
- return
512
- })
455
+ return entryResponse.update({locale: lang})
456
+ .then(response => {
457
+ for (let j = 0; j < entries.length; j++) {
458
+ if (entries[j].uid === response.uid) {
459
+ entries[j] = response
460
+ break
461
+ }
513
462
  }
514
- }
515
- refsUpdatedUids.push(response.uid)
516
- })
517
- .catch(function (error) {
518
- addlogs(config, chalk.red('Entry Uid: ' + entry.uid + ' of Content Type: ' + ctUid +
519
- ' failed to update in locale: ' + lang), 'error')
520
-
521
- addlogs(config, error, 'error')
522
- refsUpdateFailed.push({
523
- content_type: ctUid,
524
- entry: entry,
525
- locale: lang,
526
- error: error
463
+ refsUpdatedUids.push(response.uid)
464
+ return resolve()
465
+ })
466
+ .catch(function (error) {
467
+ addlogs(config, chalk.red('Entry Uid: ' + entry.uid + ' of Content Type: ' + ctUid +
468
+ ' failed to update in locale: ' + lang), 'error')
469
+
470
+ addlogs(config, error, 'error')
471
+ refsUpdateFailed.push({
472
+ content_type: ctUid,
473
+ entry: entry,
474
+ locale: lang,
475
+ error: error,
476
+ })
477
+ return reject(error)
527
478
  })
528
- })
479
+ })
480
+ await promiseResult
529
481
  }, {
530
- concurrency: reqConcurrency
482
+ concurrency: reqConcurrency,
531
483
  }).then(function () {
532
484
  // batch completed successfully
533
485
  helper.writeFile(path.join(eFolderPath, 'success.json'), entries)
534
486
  helper.writeFile(path.join(eFolderPath, 'refsUpdatedUids.json'), refsUpdatedUids)
535
487
  helper.writeFile(path.join(eFolderPath, 'refsUpdateFailed.json'), refsUpdateFailed)
536
- addlogs(config, 'Completed batch no: ' + (index + 1) + ' successfully!', 'success')
537
-
488
+ addlogs(config, 'Completed re-post entries batch no: ' + (index + 1) + ' successfully!', 'success')
538
489
  }).catch(function (error) {
539
490
  // error while executing entry in batch
540
- addlogs(config, chalk.red('Failed at batch no: ' + (index + 1)), 'error')
491
+ addlogs(config, chalk.red('Failed re-post entries at batch no: ' + (index + 1)), 'error')
541
492
  throw error
542
493
  })
543
494
  }, {
544
- concurrency: reqConcurrency
495
+ concurrency: reqConcurrency,
545
496
  }).then(function () {
546
497
  // finished updating entries with references
547
498
  addlogs(config, 'Imported entries of Content Type: \'' + ctUid + '\' in language: \'' + lang +
548
- '\' successfully!', 'success')
549
-
499
+ '\' successfully!', 'success')
550
500
  }).catch(function (error) {
551
501
  // error while updating entries with references
552
502
  addlogs(config, chalk.red('Failed while importing entries of Content Type: \'' + ctUid + '\' in language: \'' +
553
- lang + '\' successfully!'), 'error')
503
+ lang + '\' successfully!'), 'error')
554
504
  throw error
555
505
  })
556
506
  }, {
557
- concurrency: reqConcurrency
507
+ concurrency: reqConcurrency,
558
508
  }).then(function () {
559
509
  // completed updating entry references
560
510
  addlogs(config, chalk.green('Imported entries in \'' + lang + '\' language successfully!'), 'success')
561
511
  return resolve()
562
512
  }).catch(function (error) {
563
513
  // error while updating entry references
564
- addlogs(config, chalk.red('Failed to import entries in ' + lang + ' language'), 'error')
514
+ addlogs(config, chalk.red('Failed to re post entries in ' + lang + ' language'), 'error')
565
515
  return reject(error)
566
516
  })
567
517
  })
568
518
  },
569
- supressFields: function () {
519
+ supressFields: async function () {
520
+ addlogs(config, chalk.white('Suppressing content type fields...'), 'success')
570
521
  let self = this
571
522
  return new Promise(function (resolve, reject) {
572
523
  let modifiedSchemas = []
573
- let supressedSchemas = []
524
+ let suppressedSchemas = []
574
525
 
575
526
  for (let uid in self.ctSchemas) {
576
- let contentTypeSchema = _.cloneDeep(self.ctSchemas[uid])
577
- let flag = {
578
- supressed: false,
579
- references: false
580
- }
581
- if (contentTypeSchema.field_rules) {
582
- delete contentTypeSchema.field_rules
583
- }
584
- supress(contentTypeSchema.schema, flag)
585
- // check if supress modified flag
586
- if (flag.supressed) {
587
- supressedSchemas.push(contentTypeSchema)
588
- modifiedSchemas.push(self.ctSchemas[uid])
589
- }
527
+ if (uid) {
528
+ let contentTypeSchema = _.cloneDeep(self.ctSchemas[uid])
529
+ let flag = {
530
+ suppressed: false,
531
+ references: false,
532
+ }
533
+ if (contentTypeSchema.field_rules) {
534
+ delete contentTypeSchema.field_rules
535
+ }
590
536
 
591
- if (flag.references) {
592
- self.refSchemas.push(uid)
593
- }
537
+ // Set mandatory or unique flag to false
538
+ suppress(contentTypeSchema.schema, flag)
539
+ // Check if suppress modified flag
540
+ if (flag.suppressed) {
541
+ suppressedSchemas.push(contentTypeSchema)
542
+ modifiedSchemas.push(self.ctSchemas[uid])
543
+ }
544
+
545
+ if (flag.references) {
546
+ self.refSchemas.push(uid)
547
+ }
594
548
 
595
- extension_supress(contentTypeSchema.schema, config.preserveStackVersion)
549
+ // Replace extensions with new UID
550
+ extension_suppress(contentTypeSchema.schema, config.preserveStackVersion)
551
+ }
596
552
  }
597
553
 
554
+ // write modified schema in backup file
598
555
  helper.writeFile(modifiedSchemaPath, modifiedSchemas)
599
556
 
600
- return Promise.map(supressedSchemas, function (schema) {
601
-
602
- client.stack({api_key: config.target_stack, management_token: config.management_token}).contentType(schema.uid).fetch()
603
- .then(contentTypeResponse => {
604
- Object.assign(contentTypeResponse, _.cloneDeep(schema))
605
- return contentTypeResponse.update()
606
- })
557
+ return Promise.map(suppressedSchemas, async function (schema) {
558
+ let contentTypeResponse = client.stack({api_key: config.target_stack, management_token: config.management_token}).contentType(schema.uid)
559
+ Object.assign(contentTypeResponse, _.cloneDeep(schema))
560
+ return contentTypeResponse.update()
607
561
  .then(UpdatedcontentType => {
608
- return
562
+
609
563
  }).catch(function (error) {
610
564
  addlogs(config, chalk.red('Failed to modify mandatory field of \'' + schema.uid + '\' content type'), 'error')
611
- throw error
612
565
  })
613
566
  // update 5 content types at a time
614
567
  }, {
615
- concurrency: reqConcurrency
568
+ // update reqConcurrency content types at a time
569
+ concurrency: reqConcurrency,
616
570
  }).then(function () {
617
571
  return resolve()
618
572
  }).catch(function (error) {
619
- addlogs(config, chalk.red('Error while supressing mandatory field schemas'), 'error')
573
+ addlogs(config, chalk.red('Error while suppressing mandatory field schemas'), 'error')
620
574
  return reject(error)
621
575
  })
622
576
  })
623
577
  },
624
578
  fetchEntry: function (query) {
625
579
  let self = this
626
- return new Promise(function (resolve) {
580
+ return new Promise(function (resolve, reject) {
627
581
  let requestObject = {
628
582
  qs: {
629
583
  query: {
630
- title: query.entry.title
584
+ title: query.entry.title,
631
585
  },
632
- locale: query.locale
633
- }
586
+ locale: query.locale,
587
+ },
634
588
  }
635
589
 
636
- return client.stack({ api_key: config.target_stack, management_token: config.management_token}).contentType(query.content_type).entry().query(requestObject.qs).find()
590
+ return client.stack({api_key: config.target_stack, management_token: config.management_token}).contentType(query.content_type).entry().query(requestObject.qs).find()
637
591
  .then(function (response) {
638
- if (!response.body.entries.length) {
592
+ if (response.body.entries.length <= 0) {
639
593
  addlogs(config, 'Unable to map entry WO uid: ' + query.entry.uid, 'error')
640
- // log.debug('Request:\n' + JSON.stringify(requestObject))
641
594
  self.failedWO.push(query)
642
595
  return resolve()
643
596
  }
@@ -646,46 +599,52 @@ importEntries.prototype = {
646
599
  let entries = helper.readFile(_ePath)
647
600
  entries.push(query.entry)
648
601
  helper.writeFile(_ePath, entries)
649
- addlogs(config, 'Completed mapping entry wo uid: ' + query.entry.uid + ': ' + response.body.entries[0].uid, 'success')
602
+ addlogs(config, 'Completed mapping entry wo uid: ' + query.entry.uid + ': ' + response.body.entries[0].uid, 'clientsuccess')
650
603
  return resolve()
651
- }).catch(function () {
604
+ }).catch(function (error) {
652
605
  return resolve()
653
606
  })
654
607
  })
655
608
  },
656
- unSupressFields: function () {
657
- let self = this
658
- return new Promise(async function (resolve, reject) {
609
+ unSuppressFields: function () {
610
+ return new Promise(function (resolve, reject) {
659
611
  let modifiedSchemas = helper.readFile(modifiedSchemaPath)
660
612
  let modifiedSchemasUids = []
661
613
  let updatedExtensionUidsSchemas = []
662
614
  for (let uid in modifiedSchemas) {
663
- let _contentTypeSchema = _.cloneDeep(modifiedSchemas[uid])
664
- if (_contentTypeSchema.field_rules) {
665
- delete _contentTypeSchema.field_rules
615
+ if (uid) {
616
+ let _contentTypeSchema = _.cloneDeep(modifiedSchemas[uid])
617
+ if (_contentTypeSchema.field_rules) {
618
+ delete _contentTypeSchema.field_rules
619
+ }
620
+ extension_suppress(_contentTypeSchema.schema, config.preserveStackVersion)
621
+ updatedExtensionUidsSchemas.push(_contentTypeSchema)
666
622
  }
667
- extension_supress(_contentTypeSchema.schema, config.preserveStackVersion)
668
- updatedExtensionUidsSchemas.push(_contentTypeSchema)
669
623
  }
670
624
 
671
- return Promise.map(updatedExtensionUidsSchemas, function (schema) {
672
- client.stack({api_key: config.target_stack, management_token: config.management_token}).contentType(schema.uid).fetch()
673
- .then(contentTypeResponse => {
674
- contentTypeResponse.schema = schema.schema
625
+ return Promise.map(updatedExtensionUidsSchemas, async function (schema) {
626
+ let promise = new Promise((resolve, reject) => {
627
+ client.stack({api_key: config.target_stack, management_token: config.management_token}).contentType(schema.uid).fetch()
628
+ .then(contentTypeResponse => {
629
+ contentTypeResponse.schema = schema.schema
675
630
  contentTypeResponse.update()
676
- .then(UpdatedcontentType => {
677
- modifiedSchemasUids.push(schema.uid)
678
- //addlogs(config, (chalk.white('Content type: \'' + schema.uid + '\' has been restored to its previous glory!'))
679
- return
631
+ .then(UpdatedcontentType => {
632
+ modifiedSchemasUids.push(schema.uid)
633
+ addlogs(config, (chalk.white('Content type: \'' + schema.uid + '\' has been restored to its previous glory!')))
634
+ return resolve()
635
+ }).catch(function (error) {
636
+ addlogs(config, chalk.red('Failed to re-update ' + schema.uid), 'error')
637
+ addlogs(config, error, 'error')
638
+ return reject(error)
639
+ })
680
640
  }).catch(function (error) {
681
- addlogs(config, chalk.red('Failed to re-update ' + schema.uid), 'error')
682
641
  addlogs(config, error, 'error')
642
+ return reject(error)
683
643
  })
684
- }).catch(function (error) {
685
- addlogs(config, error, 'error')
686
644
  })
645
+ await promise
687
646
  }, {
688
- concurrency: reqConcurrency
647
+ concurrency: reqConcurrency,
689
648
  }).then(function () {
690
649
  for (let i = 0; i < modifiedSchemas.length; i++) {
691
650
  if (modifiedSchemasUids.indexOf(modifiedSchemas[i].uid) !== -1) {
@@ -713,39 +672,25 @@ importEntries.prototype = {
713
672
  if (entries[uid].locales.indexOf(masterLanguage.code) === -1) {
714
673
  bugged.push({
715
674
  content_type: entries[uid].content_type,
716
- uid: uid
675
+ uid: uid,
717
676
  })
718
677
  }
719
678
  }
720
679
 
721
680
  return Promise.map(bugged, function (entry) {
722
- // let requestObject = {
723
- // uri: self.requestOptionTemplate.uri + entry.content_type + config.apis.entries + self.mappedUids[
724
- // entry.uid],
725
- // method: 'DELETE',
726
- // qs: {
727
- // locale: masterLanguage.code
728
- // },
729
- // headers: self.requestOptionTemplate.headers,
730
- // json: true
731
- // }
732
-
733
- return client.stack({api_key: config.source_stack, management_token: config.management_token}).contentType(entry.content_type).entry(self.mappedUids[entry.uid]).delete({locale: masterLanguage.code})
681
+ return client.stack({api_key: config.target_stack, management_token: config.management_token}).contentType(entry.content_type).entry(self.mappedUids[entry.uid]).delete({locale: masterLanguage.code})
734
682
  .then(function () {
735
683
  removed.push(self.mappedUids[entry.uid])
736
- addlogs(config, 'Removed bugged entry from master ' + JSON.stringify(entry), 'success')
684
+ addlogs(config, 'Removed bugged entry from master ' + JSON.stringify(entry), 'success')
737
685
  })
738
686
  .catch(function (error) {
739
687
  addlogs(config, chalk.red('Failed to remove bugged entry from master language'), 'error')
740
688
  addlogs(config, error, 'error')
741
689
  addlogs(config, JSON.stringify(entry), 'error')
742
-
743
690
  })
744
-
745
691
  }, {
746
- concurrency: reqConcurrency
692
+ concurrency: reqConcurrency,
747
693
  }).then(function () {
748
-
749
694
  for (let i = 0; i < bugged.length; i++) {
750
695
  if (removed.indexOf(bugged[i].uid) !== -1) {
751
696
  bugged.splice(i, 1)
@@ -765,75 +710,147 @@ importEntries.prototype = {
765
710
  })
766
711
  },
767
712
  field_rules_update: function (schema) {
768
- let self = this
769
713
  return new Promise(function (resolve, reject) {
770
714
  if (schema.field_rules) {
771
- let field_rules_array = []
772
- for (let k = 0; k < schema.field_rules.length; k++) {
773
- for (let i = 0; i < schema.field_rules[k].conditions.length; i++) {
715
+ let fieldRuleLength = schema.field_rules.length
716
+ for (let k = 0; k < fieldRuleLength; k++) {
717
+ let fieldRuleConditionLength = schema.field_rules[k].conditions.length
718
+ for (let i = 0; i < fieldRuleConditionLength; i++) {
774
719
  if (schema.field_rules[k].conditions[i].operand_field === 'reference') {
775
- let field_rules_value = schema.field_rules[k].conditions[i].value
776
- field_rules_array = field_rules_value.split('.')
777
- let updated_value = []
778
- for (let j = 0; j < field_rules_array.length; j++) {
779
- let splited_field_rules_value = field_rules_array[j]
780
- let old_uid = helper.readFile(path.join(entryUidMapperPath))
781
- if (old_uid.hasOwnProperty(splited_field_rules_value)) {
782
- updated_value.push(old_uid[splited_field_rules_value])
720
+ let fieldRulesValue = schema.field_rules[k].conditions[i].value
721
+ let fieldRulesArray = fieldRulesValue.split('.')
722
+ let updatedValue = []
723
+ for (let j = 0; j < fieldRulesArray.length; j++) {
724
+ let splitedFieldRulesValue = fieldRulesArray[j]
725
+ let oldUid = helper.readFile(path.join(entryUidMapperPath))
726
+ if (oldUid.hasOwnProperty(splitedFieldRulesValue)) {
727
+ updatedValue.push(oldUid[splitedFieldRulesValue])
783
728
  } else {
784
- updated_value.push(field_rules_array[j])
729
+ updatedValue.push(fieldRulesArray[j])
785
730
  }
786
731
  }
787
- let append_all_values = updated_value.join('.')
788
- schema.field_rules[k].conditions[i]['value'] = append_all_values
732
+ schema.field_rules[k].conditions[i].value = updatedValue.join('.')
789
733
  }
790
734
  }
791
735
  }
792
736
  } else {
793
- console.log('field_rules is not available')
737
+ addlogs(config, 'field_rules is not available...', 'error')
794
738
  }
795
739
 
796
- return client.stack({api_key: config.target_stack, management_token: config.management_token}).contentType(schema.uid).fetch()
797
- .then(contentTypeResponse => {
798
- contentTypeResponse.schema = schema.schema
740
+ client.stack({ api_key: config.target_stack, management_token: config.management_token }).contentType(schema.uid).fetch()
741
+ .then((contentTypeResponse) => {
742
+ // Object.assign(ctObj, _.cloneDeep(schema))
743
+ contentTypeResponse.field_rules = schema.field_rules
799
744
  contentTypeResponse.update()
800
- return resolve();
745
+ })
746
+ .then(() => {
747
+ return resolve()
801
748
  }).catch(function (error) {
749
+ return reject(error)
802
750
  })
803
751
  })
804
752
  },
805
- publish: function (eUid, ctUid, lang, entryObj) {
753
+ publish: function (langs) {
806
754
  let self = this
807
- let envId = []
808
- let locales = []
809
755
  let requestObject = {
810
- entry: {}
756
+ entry: {},
811
757
  }
812
-
758
+
759
+ let contentTypeUids = Object.keys(self.ctSchemas)
760
+ let entryMapper = helper.readFile(entryUidMapperPath)
761
+
813
762
  return new Promise(function (resolve, reject) {
814
- _.forEach(entryObj.publish_details, function (pubObject) {
815
- if (self.environment.hasOwnProperty(pubObject.environment)) {
816
- envId.push(self.environment[pubObject.environment].name)
817
- let idx = _.indexOf(locales, pubObject.locale)
818
- if (idx === -1) {
819
- locales.push(pubObject.locale)
763
+ return Promise.map(langs, function (_lang, counter) {
764
+ let lang = langs[counter]
765
+ return Promise.map(contentTypeUids, function (ctUid) {
766
+ let eFilePath = path.resolve(ePath, ctUid, lang + '.json')
767
+ let entries = helper.readFile(eFilePath)
768
+
769
+ let eUids = Object.keys(entries)
770
+ let batches = []
771
+
772
+ if (eUids.length > 0) {
773
+ for (let i = 0; i < eUids.length; i += entryBatchLimit) {
774
+ batches.push(eUids.slice(i, i + entryBatchLimit))
775
+ }
776
+ } else {
777
+ return
820
778
  }
821
- }
822
- })
823
- requestObject.entry['environments'] = envId
824
- requestObject.entry['locales'] = locales
825
-
826
- client.stack({api_key: config.target_stack, management_token: config.management_token}).contentType(ctUid).entry(eUid).publish({ publishDetails: requestObject.entry, locale: lang})
827
- .then(result => {
828
- addlogs(config, chalk.green('Entry ' + eUid + ' published successfully in ' + ctUid + ' content type'), 'success')
779
+
780
+ return Promise.map(batches, async function (batch) {
781
+ return Promise.map(batch, async function (eUid) {
782
+ let entry = entries[eUid]
783
+ let envId = []
784
+ let locales = []
785
+ if (entry.publish_details && entry.publish_details.length > 0) {
786
+ _.forEach(entries[eUid].publish_details, function (pubObject) {
787
+ if (self.environment.hasOwnProperty(pubObject.environment) && _.indexOf(envId, self.environment[pubObject.environment].name) === -1) {
788
+ envId.push(self.environment[pubObject.environment].name)
789
+ }
790
+ if (pubObject.locale) {
791
+ let idx = _.indexOf(locales, pubObject.locale)
792
+ if (idx === -1) {
793
+ locales.push(pubObject.locale)
794
+ }
795
+ }
796
+ })
797
+
798
+ let entryUid = entryMapper[eUid]
799
+ if (entryUid) {
800
+ requestObject.entry.environments = envId
801
+ requestObject.entry.locales = locales
802
+ let publishPromiseResult = new Promise((resolve, reject) => {
803
+ client.stack({api_key: config.target_stack, management_token: config.management_token}).contentType(ctUid).entry(entryUid).publish({publishDetails: requestObject.entry, locale: lang})
804
+ // eslint-disable-next-line max-nested-callbacks
805
+ .then(result => {
806
+ // addlogs(config, 'Entry ' + eUid + ' published successfully in ' + ctUid + ' content type', 'success')
807
+ console.log('Entry ' + eUid + ' published successfully in ' + ctUid + ' content type');
808
+ return resolve(result)
809
+ // eslint-disable-next-line max-nested-callbacks
810
+ }).catch(function (err) {
811
+ // addlogs(config, 'Entry ' + eUid + ' not published successfully in ' + ctUid + ' content type', 'error')
812
+ console.log('Entry ' + eUid + ' not published successfully in ' + ctUid + ' content type')
813
+ return reject(err.errorMessage)
814
+ })
815
+ })
816
+ return publishPromiseResult
817
+ }
818
+ } else {
819
+ return {}
820
+ }
821
+ }, {
822
+ concurrency: reqConcurrency,
823
+ }).then(function () {
824
+ }).catch(function (error) {
825
+ // error while executing entry in batch
826
+ addlogs(config, error, 'error')
827
+ return error
828
+ })
829
+ }, {
830
+ concurrency: 1,
831
+ }).then(function () {
832
+ // addlogs(config, 'Entries published successfully in ' + ctUid + ' content type', 'success')
833
+ console.log('Entries published successfully in ' + ctUid + ' content type')
834
+ }).catch(function (error) {
835
+ addlogs(config, 'Failed some of the Entry publishing in ' + ctUid + ' content type, go through logs for details.', 'error')
836
+ return error
837
+ })
838
+ }, {
839
+ concurrency: 1,
840
+ }).then(function () {
841
+
842
+ }).catch(function (error) {
843
+ return error
844
+ })
845
+ }, {
846
+ concurrency: 1,
847
+ }).then(function () {
829
848
  return resolve()
830
- })
831
- .catch(function (err) {
832
- let error = JSON.parse(err.message)
849
+ }).catch(error => {
833
850
  return reject(error)
834
851
  })
835
852
  })
836
853
  },
837
854
  }
838
855
 
839
- module.exports = new importEntries()
856
+ module.exports = new importEntries()