@@ -601,7 +601,7 @@ var crypto = require('crypto');
601
601
//update db if one user
602
602
new Promise ( function ( resolve , reject ) {
603
603
if ( single_user )
604
- common . db . collection ( 'app_users' + app_id ) . update ( { "uid" :eid } , { $set :{ "appUserExport" :export_folder + "" } } , { upsert :true } , function ( err , res1 ) {
604
+ common . db . collection ( 'app_users' + app_id ) . update ( { "uid" :eid } , { $set :{ "appUserExport" :export_folder + "" } } , { upsert :false } , function ( err , res1 ) {
605
605
if ( err )
606
606
reject ( err ) ;
607
607
else
@@ -662,9 +662,24 @@ var crypto = require('crypto');
662
662
if ( single_user == true )
663
663
{
664
664
//update user document
665
- common . db . collection ( 'app_users' + app_id ) . update ( { "uid" :eid } , { $set :{ "appUserExport" :export_folder + ".tar.gz" } } , { upsert :true } , function ( err , res1 ) {
666
- plugins . dispatch ( "/systemlogs" , { params :params , action :"export_app_user" , data :{ result :"ok" , uids :res [ 0 ] . uid . join ( ", " ) , app_id :app_id , info :"Export successful" , export_file :export_folder + ".tar.gz" } } ) ;
667
- callback ( null , export_filename + ".tar.gz" ) ;
665
+ common . db . collection ( 'app_users' + app_id ) . update ( { "uid" :eid } , { $set :{ "appUserExport" :export_folder + ".tar.gz" } } , { upsert :false } , function ( err , res1 ) {
666
+ if ( ! err && res1 . result && res1 . result . n != 0 && res1 . result . nModified != 0 )
667
+ {
668
+ plugins . dispatch ( "/systemlogs" , { params :params , action :"export_app_user" , data :{ result :"ok" , uids :res [ 0 ] . uid . join ( ", " ) , app_id :app_id , info :"Export successful" , export_file :export_folder + ".tar.gz" } } ) ;
669
+ callback ( null , export_filename + ".tar.gz" ) ;
670
+ }
671
+ else //not updated (not exist or errored)
672
+ {
673
+ plugins . dispatch ( "/systemlogs" , { params :params , action :"export_app_user" , data :{ result :"error" , uids :res [ 0 ] . uid . join ( ", " ) , app_id :app_id , info :"User not exist" , export_folder :export_folder } } ) ;
674
+ usersApi . deleteExport ( export_filename , params , function ( err , msg ) {
675
+ if ( err )
676
+ callback ( { mesage :"Exporting failed. User does not exist. Unable to clean exported data" , filename :'appUser_' + app_id + '_' + eid } , "" ) ;
677
+ else
678
+ callback ( { mesage :"Exporting failed. User does not exist. Partially exported data deleted." , filename :'appUser_' + app_id + '_' + eid } , "" ) ;
679
+ } ) ;
680
+
681
+ }
682
+
668
683
} ) ;
669
684
}
670
685
else
0 commit comments