@@ -582,10 +582,10 @@ usersApi.deleteExport = function(filename, params, callback) {
582
582
}
583
583
} ;
584
584
585
- var run_command = function ( my_command ) {
585
+ var run_command = function ( my_command , my_args ) {
586
586
return new Promise ( function ( resolve , reject ) {
587
- var child = spawn ( my_command , {
588
- shell : true ,
587
+ var child = spawn ( my_command , my_args , {
588
+ shell : false ,
589
589
cwd : path . resolve ( __dirname , './../../../export/AppUser' ) ,
590
590
detached : false
591
591
} , function ( error ) {
@@ -615,7 +615,7 @@ var run_command = function(my_command) {
615
615
} ;
616
616
var clear_out_empty_files = function ( folder ) {
617
617
return new Promise ( function ( resolve ) {
618
- run_command ( "find " + folder + " -type f -name ' *.json' -size 0 -delete") . then (
618
+ run_command ( "find" , [ folder , " -type" , "f" , " -name" , " *.json" , " -size" , "0" , " -delete"] ) . then (
619
619
function ( ) {
620
620
resolve ( ) ;
621
621
} ,
@@ -727,11 +727,12 @@ usersApi.export = function(app_id, query, params, callback) {
727
727
}
728
728
var export_filename = 'appUser_' + app_id + '_' + eid ;
729
729
730
- var dbstr = "" ;
730
+ var dbargs = [ ] ;
731
731
var export_commands = { } ;
732
732
var db_params = plugins . getDbConnectionParams ( 'countly' ) ;
733
733
for ( var p in db_params ) {
734
- dbstr += " --" + p + " " + db_params [ p ] ;
734
+ dbargs . push ( "--" + p ) ;
735
+ dbargs . push ( db_params [ p ] ) ;
735
736
}
736
737
737
738
plugins . dispatch ( "/systemlogs" , {
@@ -763,16 +764,17 @@ usersApi.export = function(app_id, query, params, callback) {
763
764
}
764
765
} ) . then ( function ( ) {
765
766
//export data from metric_changes
766
- return run_command ( 'mongoexport ' + dbstr + ' --collection metric_changes' + app_id + ' -q \ '{uid:{$in: ["' + res [ 0 ] . uid . join ( '","' ) + '"]}}\' --out ' + export_folder + ' /metric_changes' + app_id + ' .json' ) ;
767
+ return run_command ( 'mongoexport' , [ ... dbargs , " --collection" , " metric_changes" + app_id , "-q" , '{uid:{$in: ["' + res [ 0 ] . uid . join ( '","' ) + '"]}}' , " --out" , export_folder + " /metric_changes" + app_id + " .json" ] ) ;
767
768
} ) . then ( function ( ) {
768
769
//export data from app_users
769
- return run_command ( 'mongoexport ' + dbstr + ' --collection app_users' + app_id + ' -q \ '{uid: {$in: ["' + res [ 0 ] . uid . join ( '","' ) + '"]}}\' --out ' + export_folder + ' /app_users' + app_id + ' .json' ) ;
770
+ return run_command ( 'mongoexport' , [ ... dbargs , " --collection" , " app_users" + app_id , "-q" , '{uid:{$in: ["' + res [ 0 ] . uid . join ( '","' ) + '"]}}' , " --out" , export_folder + " /app_users" + app_id + " .json" ] ) ;
770
771
} ) . then (
771
772
function ( ) {
772
773
//get other export commands from other plugins
773
774
plugins . dispatch ( "/i/app_users/export" , {
774
775
app_id : app_id ,
775
- dbstr : dbstr ,
776
+ dbstr : "" ,
777
+ dbargs : dbargs ,
776
778
export_commands : export_commands ,
777
779
query : query ,
778
780
uids : res [ 0 ] . uid ,
@@ -781,15 +783,15 @@ usersApi.export = function(app_id, query, params, callback) {
781
783
var commands = [ ] ;
782
784
for ( var prop in export_commands ) {
783
785
for ( let k = 0 ; k < export_commands [ prop ] . length ; k ++ ) {
784
- commands . push ( run_command ( export_commands [ prop ] [ k ] ) ) ;
786
+ commands . push ( run_command ( export_commands [ prop ] [ k ] . cmd , export_commands [ prop ] [ k ] . args ) ) ;
785
787
}
786
788
}
787
789
Promise . all ( commands ) . then (
788
790
function ( ) {
789
791
//pack export
790
792
clear_out_empty_files ( path . resolve ( __dirname , './../../../export/AppUser/' + export_filename ) ) //remove empty files
791
793
. then ( function ( ) {
792
- return run_command ( "tar -zcvf " + export_filename + ".tar.gz" + " " + export_filename ) ;
794
+ return run_command ( "tar" , [ " -zcvf" , export_filename + ".tar.gz" , export_filename ] ) ;
793
795
} ) //create archive
794
796
. then ( function ( ) {
795
797
return new Promise ( function ( resolve , reject ) { /*save export in gridFS*/
0 commit comments