@@ -32,6 +32,7 @@ class Cloner {
32
32
* @param {* } options.includeSubmissionRevisions - Include submission revisions when cloning submissions.
33
33
* @param {* } options.updateExistingSubmissions - Update existing submissions when found in the destination (performs a complete re-clone).
34
34
* @param {* } options.forms - A comma-separated value of all the Form ID's you wish to clone. If included, then only the provided forms will be cloned.
35
+ * @param {* } options.exclude - A comma-separated value of all the Form ID's you wish to exclude from cloning.
35
36
* @param {* } options.submissionsOnly - Only clone submissions.
36
37
* @param {* } options.apiSource - Flag to define if we need to clone from an API.
37
38
* @param {* } options.key - API Key to be used to authenticate in source.
@@ -48,6 +49,7 @@ class Cloner {
48
49
this . src = null ;
49
50
this . dest = null ;
50
51
this . cloneState = { } ;
52
+ this . exclude = this . options . exclude ? this . options . exclude . split ( ',' ) : [ ] ;
51
53
52
54
if ( this . options . apiSource ) {
53
55
this . requestHeaders = {
@@ -230,14 +232,26 @@ class Cloner {
230
232
* Determine if we should clone the given item.
231
233
* @param {* } srcItem - The source item to check.
232
234
*/
233
- shouldClone ( collection , srcItem ) {
235
+ shouldClone ( collection , srcItem , updatedItem ) {
234
236
if ( this . options . submissionsOnly && collection !== 'submissions' ) {
235
237
return false ;
236
238
}
237
- if ( this . options . createdAfter && srcItem . created < parseInt ( this . options . createdAfter , 10 ) ) {
239
+ const srcCreated = ( srcItem . created instanceof Date ) ? srcItem . created . getTime ( ) : parseInt ( srcItem . created , 10 ) ;
240
+ if ( this . options . createdAfter && srcCreated < parseInt ( this . options . createdAfter , 10 ) ) {
238
241
return false ;
239
242
}
240
- if ( this . options . modifiedAfter && srcItem . modified < parseInt ( this . options . modifiedAfter , 10 ) ) {
243
+ // eslint-disable-next-line max-len
244
+ const srcModified = ( srcItem . modified instanceof Date ) ? srcItem . modified . getTime ( ) : parseInt ( srcItem . modified , 10 ) ;
245
+ if ( this . options . modifiedAfter && srcModified < parseInt ( this . options . modifiedAfter , 10 ) ) {
246
+ return false ;
247
+ }
248
+
249
+ // Make sure to not re-clone the same item it if has not been modified.
250
+ // eslint-disable-next-line max-len
251
+ const updatedCreated = ( updatedItem . created instanceof Date ) ? updatedItem . created . getTime ( ) : parseInt ( updatedItem . created , 10 ) ;
252
+ // eslint-disable-next-line max-len
253
+ const updatedModified = ( updatedItem . modified instanceof Date ) ? updatedItem . modified . getTime ( ) : parseInt ( updatedItem . modified , 10 ) ;
254
+ if ( srcCreated === updatedCreated && srcModified === updatedModified ) {
241
255
return false ;
242
256
}
243
257
return true ;
@@ -324,6 +338,10 @@ class Cloner {
324
338
}
325
339
}
326
340
341
+ if ( collection === 'forms' && this . exclude . includes ( srcItem . _id . toString ( ) ) ) {
342
+ return ;
343
+ }
344
+
327
345
if ( eachItem ) {
328
346
eachItem ( srcItem ) ;
329
347
}
@@ -340,7 +358,7 @@ class Cloner {
340
358
341
359
// Call before handler and then update if it says we should.
342
360
if (
343
- this . shouldClone ( collection , srcItem ) &&
361
+ this . shouldClone ( collection , srcItem , updatedItem ) &&
344
362
await this . before ( collection , beforeEach , srcItem , updatedItem , destItem ) !== false
345
363
) {
346
364
if ( destItem ) {
@@ -869,6 +887,8 @@ class Cloner {
869
887
const srcId = update . settings . role ;
870
888
update . settings . role = await this . getDestinationRoleId ( srcId , destForm . project ) ;
871
889
}
890
+ } , null , ( current ) => {
891
+ return { $or : [ { _id : current . _id } , { machineName : current . machineName } ] } ;
872
892
} ) ;
873
893
}
874
894
@@ -883,7 +903,7 @@ class Cloner {
883
903
let compsWithEncryptedData = [ ] ;
884
904
await this . upsertAll ( 'forms' , this . formQuery ( srcProject ) , ( form ) => {
885
905
process . stdout . write ( '\n' ) ;
886
- process . stdout . write ( `- Form: ${ form . title } ` ) ;
906
+ process . stdout . write ( `- Form: ${ form . title } ( ${ form . _id } ) ` ) ;
887
907
} , async ( src , update , dest ) => {
888
908
if ( this . options . submissionsOnly ) {
889
909
return false ;
@@ -1030,6 +1050,9 @@ class Cloner {
1030
1050
return ;
1031
1051
}
1032
1052
const decryptedDstSettings = dest ? this . decrypt ( this . options . dstDbSecret , dest [ 'settings_encrypted' ] , true ) : { } ;
1053
+ if ( ! decryptedDstSettings ) {
1054
+ return ;
1055
+ }
1033
1056
if ( decryptedDstSettings . secret ) {
1034
1057
this . dstSecret = decryptedDstSettings . secret ;
1035
1058
}
0 commit comments