@@ -413,7 +413,7 @@ module.exports = function(my_db) {
413413 }
414414 }
415415 //new data
416- scripts . push ( { cmd : 'mongodump' , args : [ ...data . dbargs , '--collection' , "events_data" , '-q' , '{ "_id": {"$in":{"$ regex":"^' + data . appid + '_.*"}} }}' , '--out' , data . my_folder ] } ) ;
416+ scripts . push ( { cmd : 'mongodump' , args : [ ...data . dbargs , '--collection' , "events_data" , '-q' , '{ "_id": {"$regex":"^' + data . appid + '_.*"}}' , '--out' , data . my_folder ] } ) ;
417417 if ( plugins . isPluginEnabled ( 'drill' ) ) {
418418 scripts . push ( { cmd : 'mongodump' , args : [ ...data . dbargs_drill , '--collection' , "drill_events" , '-q' , '{ "a": "' + data . appid + '"}' , '--out' , data . my_folder ] } ) ;
419419 }
@@ -1145,6 +1145,60 @@ module.exports = function(my_db) {
11451145 this . update_progress = function ( my_exportid , step , status , dif , reason , reset_progress , more_fields ) {
11461146 update_progress ( my_exportid , step , status , dif , reason , reset_progress , more_fields ) ;
11471147 } ;
1148+
1149+ this . create_export_commands = function ( apps , my_params , passed_db , passed_log ) {
1150+ return new Promise ( function ( resolve , reject ) {
1151+ if ( passed_db ) {
1152+ db = passed_db ;
1153+ }
1154+ if ( my_params ) {
1155+ params = my_params ;
1156+ }
1157+ if ( passed_log ) {
1158+ log = passed_log ;
1159+ }
1160+
1161+ apps = apps . sort ( ) ;
1162+ //clear out duplicates
1163+ for ( let i = 1 ; i < apps . length - 1 ; i ++ ) {
1164+ if ( apps [ i - 1 ] === apps [ i ] ) {
1165+ apps . splice ( i , 1 ) ; i -- ;
1166+ }
1167+ }
1168+
1169+ var scriptobj = [ ] ;
1170+ exportid = crypto . createHash ( 'SHA1' ) . update ( JSON . stringify ( apps ) ) . digest ( 'hex' ) ;
1171+ var my_folder = path . resolve ( __dirname , './../export/' + exportid ) ;
1172+ var image_folder = path . resolve ( my_folder , './countly_app_icons' ) ;
1173+ for ( let i = 0 ; i < apps . length ; i ++ ) {
1174+ let subfolder = path . resolve ( my_folder , './' + apps [ i ] ) ;
1175+ scriptobj . push ( { appid : apps [ i ] , my_folder : subfolder , image_folder : image_folder , additional_files : path . resolve ( my_folder , './countly_symbolication_files' ) } ) ;
1176+ }
1177+
1178+
1179+ Promise . all ( scriptobj . map ( create_export_scripts ) ) . then ( function ( result ) {
1180+ var lines = [ ] ;
1181+ if ( result && Array . isArray ( result ) ) {
1182+ for ( var i = 0 ; i < result . length ; i ++ ) {
1183+ if ( Array . isArray ( result [ i ] ) && result [ i ] . length > 0 ) {
1184+ for ( let j = 0 ; j < result [ i ] . length ; j ++ ) {
1185+ lines . push ( result [ i ] [ j ] . cmd + " '" + result [ i ] [ j ] . args . join ( "' '" ) + "'" ) ;
1186+ }
1187+ }
1188+ }
1189+ }
1190+ var data = lines . join ( "\n" ) ;
1191+ //save document in gridfs
1192+ resolve ( data ) ;
1193+
1194+
1195+ } ) . catch ( function ( err ) {
1196+ log . e ( err ) ;
1197+ reject ( Error ( err . message ) ) ;
1198+ } ) ;
1199+ } ) ;
1200+
1201+ } ;
11481202 this . export_data = function ( apps , my_params , passed_db , passed_log ) {
11491203 return new Promise ( function ( resolve , reject ) {
11501204 if ( passed_db ) {
0 commit comments