Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / components / import / cm / csvUpdates.js
index 0f36c1b..18cc448 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5ed0=['hasOwnProperty','trim','replace','isValid','scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)','isNaN','isNumber','agent\x20not\x20exists','email','dateOfBirth','YYYY-MM-DD','dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)','firstName','\x20not\x20specified','itemTypeId','description','SystemRow','Abort\x20parser','abort','SystemError','step','CREATE\x20TABLE\x20','\x20LIKE\x20cm_contacts;',',\x20scheduledAt\x20=\x20NOW()','each','contactId','contactTypeId','orderBy','all','DROP\x20TABLE\x20','finish','affectedRows','emit','contact:import:','unlink','complete','argv','arguments\x20<filename>\x20<parameters>\x20<agents>','existsSync','file\x20doesn\x27t\x20exists','ListId\x20is\x20mandatory','body\x20id\x20mandatory','map','SIGINT','uncaughtException','lodash','papaparse','util','bluebird','moment','squel','ioredis','../../../mysqldb','../../../config/logger','defaults','redis','localhost','socket.io-emitter','YYYY-MM-DD\x20HH:mm:ss','format','YYYYMMDDHHmmss','test','select','field','phone','from','\x20=\x20','where','.dialCheckDuplicateType\x20IN\x20(','sequelize','query','spread','length','AdditionalPhones','push','catch','error','message','isNil','split','filter','CmContactHasItem','findOne','then','updated','create','PHONE','inserted','update','cm_contacts.id','cm_contacts.ListId','cm_contacts.priority','cm_contacts.UserId','insert','into','cm_hopper','fromQuery','scheduledat','ContactId','ListId','createdAt','updatedAt','priority','UserId','fields','join','cm_contacts','cm_contacts.ListId\x20=\x20','.CmListId','.id\x20=\x20','.CmListId\x20=\x20?','cm_contacts.createdAt\x20=\x20?','cm_contacts.phone\x20NOT\x20IN\x20(?)','\x22always\x22','\x22onlyIfOpen\x22','toString','cm_contacts.phone','cm_contacts.createdAt','cm_contacts.updatedAt','cm_hopper_black','\x20=\x20?','cm_hopper.id','cm_contact_has_items.item','cm_contact_has_items.OrderBy','cm_contact_has_items.createdAt','cm_contact_has_items.updatedAt','cm_hopper_additional_phones','CmHopperId','OrderBy','cm_contacts.id\x20=\x20cm_hopper.ContactId','keys','CompanyId',')\x20NOT\x20IN\x20?','ListId\x20=\x20?','id\x20IN\x20?','MIN(id)','min_id','group','info','Received\x20SIGINT','exit','errors','main','stringify','send','start','binding','clone','root','server/files/tmp','name','header','writeFileSync','parse','createReadStream','rows','data','find'];(function(_0x17bdd1,_0x4e368e){var _0x4f79dc=function(_0x748d7b){while(--_0x748d7b){_0x17bdd1['push'](_0x17bdd1['shift']());}};_0x4f79dc(++_0x4e368e);}(_0x5ed0,0xcb));var _0x05ed=function(_0x33deb0,_0x4619f7){_0x33deb0=_0x33deb0-0x0;var _0x3682c8=_0x5ed0[_0x33deb0];return _0x3682c8;};'use strict';var fs=require('fs');var path=require('path');var _=require(_0x05ed('0x0'));var Papa=require(_0x05ed('0x1'));var util=require(_0x05ed('0x2'));var BPromise=require(_0x05ed('0x3'));var moment=require(_0x05ed('0x4'));var squel=require(_0x05ed('0x5'));var Redis=require(_0x05ed('0x6'));var db=require(_0x05ed('0x7'))['db'];var config=require('../../../config/environment');var logger=require(_0x05ed('0x8'))('import');config['redis']=_[_0x05ed('0x9')](config[_0x05ed('0xa')],{'host':_0x05ed('0xb'),'port':0x18eb});var socket=require(_0x05ed('0xc'))(new Redis(config[_0x05ed('0xa')]));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var promisesAdditionalPhones=[];var promisesContact=[];var orderBy=0x0;var updatedRows=0x0;var stopped=![];var NOW=moment()['format'](_0x05ed('0xd'));var tempTableName='cm_contacts_temp_'+moment()[_0x05ed('0xe')](_0x05ed('0xf'));var contactItemTypes=[];var phoneDescriptions=[];var hasAdditionalPhones=![];function isEmail(_0x4dd2e4){return/^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/[_0x05ed('0x10')](_0x4dd2e4);}function selectNotIn(_0x1c6502,_0x4fdba5,_0x23e227,_0x2a50e3,_0x18954b){return squel[_0x05ed('0x11')]()[_0x05ed('0x12')](_0x05ed('0x13'))[_0x05ed('0x14')](_0x2a50e3)['join'](_0x4fdba5,null,_0x4fdba5+'.id\x20=\x20'+_0x2a50e3+'.'+_0x23e227)['where'](_0x2a50e3+'.'+_0x23e227+_0x05ed('0x15')+_0x1c6502+'.'+_0x23e227)[_0x05ed('0x16')](_0x4fdba5+_0x05ed('0x17')+_0x18954b['join']()+')');}function handleAdditionalPhones(){return new Promise(function(_0x227853,_0x22aa5c){promisesAdditionalPhones=[];promisesContact=[];return db[_0x05ed('0x18')][_0x05ed('0x19')]('select\x20*\x20from\x20'+tempTableName)[_0x05ed('0x1a')](function(_0x3ccf0b){if(_0x3ccf0b!==null){var _0x19dcff=[];for(var _0x5aa57c=0x0;_0x5aa57c<_0x3ccf0b[_0x05ed('0x1b')];_0x5aa57c++){var _0x258da6=_0x3ccf0b[_0x5aa57c];if(!_['isNil'](_0x258da6[_0x05ed('0x13')])){if(!_['isNil'](_0x258da6[_0x05ed('0x1c')]))_0x19dcff[_0x05ed('0x1d')](insertAdditionalPhones(_0x258da6));promisesContact[_0x05ed('0x1d')]({'contact':_0x258da6});}}}Promise['all'](_0x19dcff)['then'](function(){_0x227853({'val':0x1});});})[_0x05ed('0x1e')](function(_0xe7ee13){logger[_0x05ed('0x1f')](_0xe7ee13[_0x05ed('0x20')]);});});}function insertAdditionalPhones(_0x397a45){return new Promise(function(_0x3b023c,_0xd0e6ba){var _0x4cb6a9=_0x397a45[_0x05ed('0x1c')];if(_[_0x05ed('0x21')](_0x4cb6a9))_0xd0e6ba({'val':0x0});else{var _0x13eba9=_0x4cb6a9['split'](';');var _0x2a3302=[];orderBy=0x0;for(var _0x52aa1a=0x0;_0x52aa1a<_0x13eba9[_0x05ed('0x1b')];_0x52aa1a++){_0x2a3302['push'](splitAdditionalPhone(_0x397a45['id'],_0x13eba9[_0x52aa1a]));}Promise['all'](_0x2a3302)['then'](function(){_0x3b023c({'val':_0x13eba9['length']});});}});}function splitAdditionalPhone(_0x26e6b1,_0x278678){return new Promise(function(_0x3acd60,_0x45e18e){var _0x559b60=_0x278678['split'](':');var _0x3eceda=_0x559b60[0x0];var _0x307321=_0x559b60[0x1];if(_0x307321!==''){var _0x1477c9=_0x307321[_0x05ed('0x22')]('|');var _0x20ff35=[];for(var _0x3c8516=0x0;_0x3c8516<_0x1477c9[_0x05ed('0x1b')];_0x3c8516++){if(_0x1477c9[_0x3c8516]!==''){var _0x141c8f=_[_0x05ed('0x23')](promisesAdditionalPhones,{'contactId':_0x26e6b1,'phone':_0x1477c9[_0x3c8516]});if(_0x141c8f['length']==0x0){orderBy++;promisesAdditionalPhones['push']({'contactId':_0x26e6b1,'contactTypeId':_0x3eceda,'phone':_0x1477c9[_0x3c8516],'orderBy':orderBy});}}}_0x3acd60({'ok':0x1});}else _0x3acd60({'res':0x0});});}function createAdditionalPhone(_0x5cfc0d,_0x1400ad,_0x5854cc,_0x23e3e1){var _0x350c15='';var _0x47384f='';var _0x4db7f4=_0x5854cc['split']('§');_0x350c15=_0x4db7f4[0x0];if(_0x4db7f4[_0x05ed('0x1b')]==0x2)_0x47384f=_0x4db7f4[0x1];return new Promise(function(_0x4d2889,_0xc49b2a){return db[_0x05ed('0x24')][_0x05ed('0x25')]({'where':{'CmContactId':_0x5cfc0d,'item':_0x350c15}})[_0x05ed('0x26')](function(_0x548ded){if(_0x548ded){return db[_0x05ed('0x24')]['update']({'ItemTypeId':_0x1400ad,'description':_0x47384f,'OrderBy':_0x23e3e1},{'where':{'CmContactId':_0x5cfc0d,'item':_0x350c15}})['then'](function(_0x3ca946){_0x4d2889({'res':_0x05ed('0x27')});});}else{return db[_0x05ed('0x24')][_0x05ed('0x28')]({'CmContactId':_0x5cfc0d,'item':_0x350c15,'ItemTypeId':_0x1400ad,'description':_0x47384f,'OrderBy':_0x23e3e1,'ItemClass':_0x05ed('0x29')})[_0x05ed('0x26')](function(_0x2d5e62){_0x4d2889({'res':_0x05ed('0x2a')});});}});});}function updateContact(_0x513fc1){return new Promise(function(_0x2343d2,_0x4611cb){var _0x5b7b25=_0x513fc1['id'];delete _0x513fc1['id'];return db['CmContact']['update'](_0x513fc1,{'where':{'id':_0x5b7b25}})[_0x05ed('0x26')](function(_0x26569b){updatedRows+=0x1;return db['CmHopper'][_0x05ed('0x2b')]({'phone':_0x513fc1[_0x05ed('0x13')]},{'where':{'ContactId':_0x5b7b25}})[_0x05ed('0x26')](function(_0x1ac463){_0x2343d2({'ret':'OK'});});});});}function insertCmHopper(_0x151b00,_0x3f3089,_0x3454f7,_0x40bb15,_0x91805d){var _0x13cedb=['cm_contacts.phone','cm_contacts.scheduledat',_0x05ed('0x2c'),_0x05ed('0x2d'),_0x3f3089+'.'+_0x40bb15,'cm_contacts.createdAt','cm_contacts.updatedAt',_0x05ed('0x2e'),_0x05ed('0x2f'),'\x22'+_0x91805d+'\x22'];return squel[_0x05ed('0x30')]()[_0x05ed('0x31')](_0x05ed('0x32'))[_0x05ed('0x33')]([_0x05ed('0x13'),_0x05ed('0x34'),_0x05ed('0x35'),_0x05ed('0x36'),_0x40bb15,_0x05ed('0x37'),_0x05ed('0x38'),_0x05ed('0x39'),_0x05ed('0x3a'),'recallme'],squel[_0x05ed('0x11')]()[_0x05ed('0x3b')](_0x13cedb)[_0x05ed('0x14')](_0x3f3089)[_0x05ed('0x3c')](_0x05ed('0x3d'),null,_0x05ed('0x3e')+_0x3f3089+_0x05ed('0x3f'))[_0x05ed('0x3c')](_0x3454f7,null,_0x3454f7+_0x05ed('0x40')+_0x3f3089+'.'+_0x40bb15)['where'](_0x3f3089+_0x05ed('0x41'),_0x151b00)[_0x05ed('0x16')](_0x05ed('0x42'),NOW)[_0x05ed('0x16')](_0x05ed('0x43'),selectNotIn(_0x3f3089,_0x3454f7,_0x40bb15,_0x05ed('0x32'),[_0x05ed('0x44'),_0x05ed('0x45')]))[_0x05ed('0x16')](_0x05ed('0x43'),selectNotIn(_0x3f3089,_0x3454f7,_0x40bb15,_0x05ed('0x32'),[_0x05ed('0x44')])))[_0x05ed('0x46')]();}function insertCmHopperBlack(_0x43b8c8,_0x1b65ca,_0x4dc982,_0xc6bee3){var _0x40e3c5=[_0x05ed('0x47'),_0x05ed('0x2c'),_0x05ed('0x2d'),_0x1b65ca+'.'+_0xc6bee3,_0x05ed('0x48'),_0x05ed('0x49')];return squel[_0x05ed('0x30')]()[_0x05ed('0x31')](_0x05ed('0x4a'))[_0x05ed('0x33')]([_0x05ed('0x13'),'ContactId','ListId',_0xc6bee3,_0x05ed('0x37'),'updatedAt'],squel[_0x05ed('0x11')]()[_0x05ed('0x3b')](_0x40e3c5)[_0x05ed('0x14')](_0x1b65ca)[_0x05ed('0x3c')](_0x05ed('0x3d'),null,_0x05ed('0x3e')+_0x1b65ca+_0x05ed('0x3f'))[_0x05ed('0x3c')](_0x4dc982,null,_0x4dc982+_0x05ed('0x40')+_0x1b65ca+'.'+_0xc6bee3)[_0x05ed('0x16')](_0x1b65ca+_0x05ed('0x41'),_0x43b8c8)[_0x05ed('0x16')]('cm_contacts.createdAt\x20=\x20?',NOW)[_0x05ed('0x16')](_0x05ed('0x43'),squel[_0x05ed('0x11')]()[_0x05ed('0x12')](_0x05ed('0x13'))[_0x05ed('0x14')]('cm_hopper_black')[_0x05ed('0x16')]('ListId\x20=\x20?',_0x43b8c8)[_0x05ed('0x16')](_0xc6bee3+_0x05ed('0x4b'),_0x1b65ca+'.'+_0xc6bee3)))[_0x05ed('0x46')]();}function insertCmHopperAdditionalPhones(_0x140ecc){var _0xb4b917=[_0x05ed('0x4c'),_0x05ed('0x4d'),_0x05ed('0x4e'),_0x05ed('0x4f'),_0x05ed('0x50')];return squel['insert']()[_0x05ed('0x31')](_0x05ed('0x51'))['fromQuery']([_0x05ed('0x52'),'phone',_0x05ed('0x53'),'createdAt',_0x05ed('0x38')],squel[_0x05ed('0x11')]()[_0x05ed('0x3b')](_0xb4b917)[_0x05ed('0x14')]('cm_hopper')[_0x05ed('0x3c')](_0x05ed('0x3d'),null,_0x05ed('0x54'))[_0x05ed('0x3c')]('cm_contact_has_items',null,'cm_contacts.id\x20=\x20cm_contact_has_items.CmContactId')[_0x05ed('0x16')]('cm_hopper.ListId\x20=\x20?',_0x140ecc)[_0x05ed('0x16')](_0x05ed('0x42'),NOW))['toString']();}function insertCmContact(_0x208700,_0x16a4ce,_0x13b246,_0x1cfa79){var _0x1fe3eb=_['concat'](_[_0x05ed('0x55')](_0x1cfa79),[_0x05ed('0x36'),_0x05ed('0x56'),_0x05ed('0x37'),_0x05ed('0x38')]);return squel[_0x05ed('0x30')]()[_0x05ed('0x31')](_0x05ed('0x3d'))[_0x05ed('0x33')](_0x1fe3eb,squel[_0x05ed('0x11')]()['fields'](_0x1fe3eb)['from'](_0x16a4ce)[_0x05ed('0x16')]('('+_0x13b246[_0x05ed('0x3c')](',')+_0x05ed('0x57'),squel['select']()[_0x05ed('0x3b')](_0x13b246)[_0x05ed('0x14')](_0x05ed('0x3d'))['where'](_0x05ed('0x58'),_0x208700))[_0x05ed('0x16')](_0x05ed('0x59'),squel['select']()[_0x05ed('0x12')](_0x05ed('0x5a'),_0x05ed('0x5b'))['from'](_0x16a4ce)[_0x05ed('0x5c')](_0x13b246['join'](','))))[_0x05ed('0x46')]();}function handleStop(){logger[_0x05ed('0x5d')](_0x05ed('0x5e'));stopped=!![];}function handleUncaughtException(_0x5ac294){logger['error'](_0x5ac294[_0x05ed('0x20')]);process[_0x05ed('0x5f')](0x1);}function handleError(_0x2d9a61,_0x17729f){stats[_0x05ed('0x60')]['push']({'name':_0x17729f['code'],'message':_0x17729f[_0x05ed('0x20')],'row':_0x2d9a61});}function handleQuery(_0x1c8fd6){logger['info'](_0x1c8fd6);return db[_0x05ed('0x18')][_0x05ed('0x19')](_0x1c8fd6)[_0x05ed('0x1a')](function(_0x30a355){results[_0x05ed('0x1d')](_0x30a355);})[_0x05ed('0x1e')](function(_0x161d48){logger[_0x05ed('0x1f')](_0x161d48['message']);});}function main(_0x4d002e,_0x1bac7a,_0x2e3846,_0x5b5542){logger[_0x05ed('0x5d')](_0x05ed('0x61'),_0x4d002e,JSON[_0x05ed('0x62')](_0x1bac7a));process[_0x05ed('0x63')](_0x05ed('0x64'));var _0x5c4cca=_0x1bac7a[_0x05ed('0x65')];var _0x1da310=_[_0x05ed('0x66')](_0x5c4cca);var _0x319476=_0x1bac7a['socket_timestamp'];var _0x273c75=path['join'](config[_0x05ed('0x67')],_0x05ed('0x68'),_0x319476+'.csv');logger['info']('body',_0x1bac7a);db['ContactItemType']['findAll']({'raw':!![],'attributes':['id','name']})[_0x05ed('0x26')](function(_0x3b611e){for(var _0x1736e3=0x0;_0x1736e3<_0x3b611e[_0x05ed('0x1b')];_0x1736e3++){if(_0x3b611e[_0x1736e3][_0x05ed('0x69')]in _0x5c4cca){contactItemTypes[_0x05ed('0x1d')](_0x3b611e[_0x1736e3]);delete _0x1da310[_0x3b611e[_0x1736e3][_0x05ed('0x69')]];hasAdditionalPhones=!![];}for(var _0x2dfd72 in _0x5c4cca){if(_0x3b611e[_0x1736e3]['name']+'_description'===_0x2dfd72){phoneDescriptions[_0x05ed('0x1d')]({'itemTypeId':_0x3b611e[_0x1736e3]['id'],'description':_0x2dfd72});delete _0x1da310[_0x2dfd72];}}}if(hasAdditionalPhones)_0x1da310[_0x05ed('0x1c')]='';var _0x142fb4=_[_0x05ed('0x55')](_0x1da310)['join']();logger[_0x05ed('0x5d')](_0x05ed('0x6a'),_0x142fb4);fs[_0x05ed('0x6b')](_0x273c75,_0x142fb4+'\x0a');Papa[_0x05ed('0x6c')](fs[_0x05ed('0x6d')](_0x4d002e),{'header':!![],'skipEmptyLines':!![],'step':function(_0x28835c,_0x161c6b){try{for(var _0x230e7f=0x0,_0x2af65c=[];_0x230e7f<_0x28835c['data']['length'];_0x230e7f++){stats[_0x05ed('0x6e')]+=0x1;if(_0x28835c[_0x05ed('0x60')][_0x230e7f]){handleError(_0x28835c[_0x05ed('0x6f')][_0x230e7f],_0x28835c[_0x05ed('0x60')][_0x230e7f]);}else{var _0x1c3fa1=[];var _0x3c98ce=[];var _0x1c2aac={};for(var _0x330fa5 in _0x5c4cca){let _0x1e86ec=contactItemTypes['find'](_0x2c14fa=>_0x2c14fa['name']===_0x330fa5);let _0x591060=contactItemTypes[_0x05ed('0x70')](_0x1f90da=>_0x1f90da[_0x05ed('0x69')]+'_description'===_0x330fa5);if(_[_0x05ed('0x21')](_0x1e86ec)&&_[_0x05ed('0x21')](_0x591060)){if(_0x5c4cca[_0x05ed('0x71')](_0x330fa5)){if(_0x28835c[_0x05ed('0x6f')][_0x230e7f][_0x5c4cca[_0x330fa5]]){var _0x37d73d=_[_0x05ed('0x72')](_0x28835c[_0x05ed('0x6f')][_0x230e7f][_0x5c4cca[_0x330fa5]][_0x05ed('0x73')](/"/g,'\x27'));switch(_0x330fa5){case'scheduledat':var _0x111d98=moment(_0x37d73d,_0x05ed('0xd'),!![]);if(_0x111d98[_0x05ed('0x74')]()){_0x2af65c['push']('\x22'+_0x37d73d+'\x22');}else{_0x1c3fa1['push'](_0x05ed('0x75'));}break;case _0x05ed('0x39'):var _0x168fb6=parseInt(_0x37d73d);_0x37d73d=_[_0x05ed('0x76')](_0x168fb6)||_0x168fb6<0x0||_0x168fb6>0x4?_0x5b5542?0x3:0x2:_0x168fb6;_0x2af65c[_0x05ed('0x1d')]('\x22'+_0x37d73d+'\x22');break;case _0x05ed('0x3a'):var _0x54b71d=parseInt(_0x37d73d);if(_[_0x05ed('0x77')](_0x54b71d)&&_['includes'](_0x2e3846,_0x54b71d)){_0x2af65c[_0x05ed('0x1d')]('\x22'+_0x54b71d+'\x22');}else{_0x1c3fa1['push'](_0x05ed('0x78'));}break;case _0x05ed('0x79'):if(isEmail(_0x37d73d)){_0x2af65c[_0x05ed('0x1d')]('\x22'+_0x37d73d+'\x22');}else{_0x1c3fa1[_0x05ed('0x1d')]('email\x20wrong\x20format');}break;case _0x05ed('0x7a'):var _0x122561=moment(_0x37d73d,_0x05ed('0x7b'),!![]);if(_0x122561[_0x05ed('0x74')]()){_0x2af65c[_0x05ed('0x1d')]('\x22'+_0x37d73d+'\x22');}else{_0x1c3fa1['push'](_0x05ed('0x7c'));}break;default:_0x2af65c[_0x05ed('0x1d')]('\x22'+_0x37d73d+'\x22');}}else{switch(_0x330fa5){case _0x05ed('0x7d'):case _0x05ed('0x13'):_0x1c3fa1[_0x05ed('0x1d')](_0x330fa5+_0x05ed('0x7e'));break;default:_0x2af65c[_0x05ed('0x1d')]('\x22\x22');}}}}else{var _0x523bd6='';if(!_[_0x05ed('0x21')](_0x1e86ec)){if(!_0x1c2aac['hasOwnProperty'](_0x1e86ec['id'])){for(var _0x517f51=0x0;_0x517f51<_0x5c4cca[_0x330fa5]['length'];_0x517f51++){var _0x37d73d=_[_0x05ed('0x72')](_0x28835c[_0x05ed('0x6f')][_0x230e7f][_0x5c4cca[_0x330fa5][_0x517f51]][_0x05ed('0x73')](/"/g,'\x27'));var _0x3a1ef6=phoneDescriptions['find'](_0x58847a=>_0x58847a[_0x05ed('0x7f')]===_0x1e86ec['id']);if(!_[_0x05ed('0x21')](_0x3a1ef6)){var _0x31ba8f=_[_0x05ed('0x72')](_0x28835c[_0x05ed('0x6f')][_0x230e7f][_0x5c4cca[_0x3a1ef6[_0x05ed('0x80')]][0x0]][_0x05ed('0x73')](/"/g,'\x27'));if(!_[_0x05ed('0x21')](_0x31ba8f))_0x37d73d=_0x37d73d+'§'+_0x31ba8f;}if(_0x523bd6=='')_0x523bd6=_0x37d73d;else _0x523bd6+='|'+_0x37d73d;}_0x3c98ce['push'](_0x1e86ec['id']+':'+_0x523bd6);_0x1c2aac[_0x1e86ec['id']]=0x1;}}}}if(hasAdditionalPhones){_0x2af65c['push']('\x22'+_0x3c98ce[_0x05ed('0x3c')](';')+'\x22');}if(_0x1c3fa1[_0x05ed('0x1b')]){handleError(_0x28835c[_0x05ed('0x6f')][_0x230e7f],{'code':_0x05ed('0x81'),'message':_0x1c3fa1[_0x05ed('0x3c')]()});}else{fs['appendFileSync'](_0x273c75,_0x2af65c[_0x05ed('0x3c')]()+'\x0a');}_0x2af65c=[];}if(!(stats[_0x05ed('0x6e')]%0xc8)){socket['emit']('contact:import:'+_0x319476,stats);stats['errors']=[];}}if(stopped){logger['info'](_0x05ed('0x82'));_0x161c6b[_0x05ed('0x83')]();}}catch(_0x315ba3){handleError(_0x28835c[_0x05ed('0x6f')][_0x230e7f],{'code':_0x05ed('0x84'),'message':_0x315ba3[_0x05ed('0x20')]});logger[_0x05ed('0x1f')](_0x05ed('0x85'),_0x315ba3[_0x05ed('0x20')]);}},'complete':function(){try{var _0x26a785=[];var _0x5c0189=tempTableName;_0x26a785[_0x05ed('0x1d')](_0x05ed('0x86')+_0x5c0189+_0x05ed('0x87'));logger[_0x05ed('0x5d')]('CIS\x20len',contactItemTypes['length']);var _0x20592f=util[_0x05ed('0xe')]('LOAD\x20DATA\x20LOCAL\x20INFILE\x20\x27%s\x27\x20INTO\x20TABLE\x20%s\x20CHARACTER\x20SET\x20UTF8\x20FIELDS\x20TERMINATED\x20BY\x20\x27,\x27\x20ENCLOSED\x20BY\x20\x27\x22\x27\x20LINES\x20TERMINATED\x20BY\x20\x27\x0a\x27\x20IGNORE\x201\x20ROWS\x20(%s)\x20SET\x20ListId\x20=\x20%s,\x20CompanyId\x20=\x20%s,\x20createdAt\x20=\x20\x27%s\x27,\x20updatedAt\x20=\x20\x27%s\x27',_0x273c75,_0x5c0189,_0x142fb4,_0x1bac7a[_0x05ed('0x36')],_0x1bac7a[_0x05ed('0x56')]||null,NOW,NOW);if(_[_0x05ed('0x21')](_0x5c4cca[_0x05ed('0x34')])){_0x20592f+=_0x05ed('0x88');}_0x26a785[_0x05ed('0x1d')](_0x20592f);BPromise[_0x05ed('0x89')](_0x26a785,handleQuery)[_0x05ed('0x26')](function(_0x44e236){BPromise['all']([handleAdditionalPhones()])['then'](function(){_0x26a785=[];for(var _0x330844=0x0;_0x330844<promisesContact[_0x05ed('0x1b')];_0x330844++){_0x26a785[_0x05ed('0x1d')](updateContact(promisesContact[_0x330844]['contact']));}BPromise['all'](_0x26a785)[_0x05ed('0x26')](function(){_0x26a785=[];for(var _0x1d9170=0x0;_0x1d9170<promisesAdditionalPhones[_0x05ed('0x1b')];_0x1d9170++){_0x26a785['push'](createAdditionalPhone(promisesAdditionalPhones[_0x1d9170][_0x05ed('0x8a')],promisesAdditionalPhones[_0x1d9170][_0x05ed('0x8b')],promisesAdditionalPhones[_0x1d9170][_0x05ed('0x13')],promisesAdditionalPhones[_0x1d9170][_0x05ed('0x8c')]));}BPromise[_0x05ed('0x8d')](_0x26a785)['then'](function(){_0x26a785=[];_0x26a785[_0x05ed('0x1d')](insertCmHopperAdditionalPhones(_0x1bac7a[_0x05ed('0x36')]));_0x26a785[_0x05ed('0x1d')](_0x05ed('0x8e')+_0x5c0189+';');BPromise[_0x05ed('0x89')](_0x26a785,handleQuery)[_0x05ed('0x26')](function(_0x3efeb3){stats[_0x05ed('0x8f')]=!![];stats[_0x05ed('0x90')]=updatedRows;socket[_0x05ed('0x91')](_0x05ed('0x92')+_0x319476,stats);fs['unlink'](_0x4d002e);fs[_0x05ed('0x93')](_0x273c75);process[_0x05ed('0x5f')](0x0);})[_0x05ed('0x1e')](function(_0x1f4ab0){logger[_0x05ed('0x1f')](_0x1f4ab0[_0x05ed('0x20')]);process[_0x05ed('0x5f')](0x1);});});});});})[_0x05ed('0x1e')](function(_0x194bc9){logger[_0x05ed('0x1f')](_0x194bc9[_0x05ed('0x20')]);process[_0x05ed('0x5f')](0x1);});}catch(_0x2895bb){logger[_0x05ed('0x1f')](_0x05ed('0x94'),_0x2895bb['message']);process[_0x05ed('0x5f')](0x1);}},'error':function(_0x58d80a,_0x30bd46,_0x44227d,_0x61773){throw new Error(_0x61773);}});});}function validate(){if(process[_0x05ed('0x95')]&&process[_0x05ed('0x95')][_0x05ed('0x1b')]<0x4){throw new Error(_0x05ed('0x96'));}var _0x5833dd=path[_0x05ed('0x3c')](config['root'],_0x05ed('0x68'),process[_0x05ed('0x95')][0x2]);if(!fs[_0x05ed('0x97')](_0x5833dd)){throw new Error(_0x05ed('0x98'));}var _0x124f43={};try{_0x124f43=JSON[_0x05ed('0x6c')](process[_0x05ed('0x95')][0x3]);if(!_0x124f43['binding']){throw new Error('binding\x20doesn\x27t\x20exists');}var _0x3c810b=0x0;if(_0x124f43[_0x05ed('0x65')]['UserId']){_0x3c810b=0x1;}if(!_0x124f43['ListId']){throw new Error(_0x05ed('0x99'));}}catch(_0x4853b1){throw new Error(_0x05ed('0x9a'));}var _0x4aaa10=[];try{_0x4aaa10=_[_0x05ed('0x9b')](JSON[_0x05ed('0x6c')](process['argv'][0x4]),'id');}catch(_0x39c8a9){logger['info']('No\x20agent\x20available');}main(_0x5833dd,_0x124f43,_0x4aaa10,_0x3c810b);}validate();process['on'](_0x05ed('0x9c'),handleStop);process['on'](_0x05ed('0x9d'),handleUncaughtException);
\ No newline at end of file
+var _0x2106=['No\x20agent\x20available','SIGINT','uncaughtException','lodash','papaparse','util','bluebird','moment','squel','ioredis','../../../config/environment','../../../config/logger','redis','defaults','localhost','socket.io-emitter','format','YYYY-MM-DD\x20HH:mm:ss','cm_contacts_temp_','test','field','phone','from','join','.id\x20=\x20','where','\x20=\x20','.dialCheckDuplicateType\x20IN\x20(','sequelize','query','spread','length','isNil','AdditionalPhones','push','all','then','error','message','split','filter','CmContactHasItem','findOne','update','create','PHONE','inserted','CmContact','CmHopper','cm_contacts.phone','cm_contacts.scheduledat','cm_contacts.ListId','cm_contacts.createdAt','into','cm_hopper','fromQuery','scheduledat','ContactId','ListId','createdAt','updatedAt','UserId','recallme','select','fields','cm_contacts','cm_contacts.createdAt\x20=\x20?','cm_contacts.phone\x20NOT\x20IN\x20(?)','\x22always\x22','toString','cm_contacts.id','cm_contacts.updatedAt','insert','cm_contacts.ListId\x20=\x20','cm_hopper_black','\x20=\x20?','cm_hopper.id','cm_contact_has_items.updatedAt','OrderBy','cm_contacts.id\x20=\x20cm_hopper.ContactId','cm_contact_has_items','cm_contacts.id\x20=\x20cm_contact_has_items.CmContactId','cm_hopper.ListId\x20=\x20?','concat','keys','CompanyId',')\x20NOT\x20IN\x20?','ListId\x20=\x20?','id\x20IN\x20?','info','Received\x20SIGINT','exit','errors','code','catch','main','stringify','send','start','binding','clone','root','body','ContactItemType','findAll','name','_description','writeFileSync','createReadStream','data','rows','find','trim','replace','isValid','scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)','priority','email','email\x20wrong\x20format','dateOfBirth','dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)','firstName','hasOwnProperty','description','appendFileSync','emit','Abort\x20parser','abort','SystemError','step','\x20LIKE\x20cm_contacts;','CIS\x20len','LOAD\x20DATA\x20LOCAL\x20INFILE\x20\x27%s\x27\x20INTO\x20TABLE\x20%s\x20CHARACTER\x20SET\x20UTF8\x20FIELDS\x20TERMINATED\x20BY\x20\x27,\x27\x20ENCLOSED\x20BY\x20\x27\x22\x27\x20LINES\x20TERMINATED\x20BY\x20\x27\x0a\x27\x20IGNORE\x201\x20ROWS\x20(%s)\x20SET\x20ListId\x20=\x20%s,\x20CompanyId\x20=\x20%s,\x20createdAt\x20=\x20\x27%s\x27,\x20updatedAt\x20=\x20\x27%s\x27',',\x20scheduledAt\x20=\x20NOW()','contact','contactId','contactTypeId','orderBy','DROP\x20TABLE\x20','each','finish','affectedRows','contact:import:','unlink','argv','arguments\x20<filename>\x20<parameters>\x20<agents>','server/files/tmp','file\x20doesn\x27t\x20exists','parse','ListId\x20is\x20mandatory','body\x20id\x20mandatory','map'];(function(_0x382f18,_0x18161c){var _0x2d08da=function(_0x1ed348){while(--_0x1ed348){_0x382f18['push'](_0x382f18['shift']());}};_0x2d08da(++_0x18161c);}(_0x2106,0x133));var _0x6210=function(_0xa1eeae,_0x447d5e){_0xa1eeae=_0xa1eeae-0x0;var _0x417be6=_0x2106[_0xa1eeae];return _0x417be6;};'use strict';var fs=require('fs');var path=require('path');var _=require(_0x6210('0x0'));var Papa=require(_0x6210('0x1'));var util=require(_0x6210('0x2'));var BPromise=require(_0x6210('0x3'));var moment=require(_0x6210('0x4'));var squel=require(_0x6210('0x5'));var Redis=require(_0x6210('0x6'));var db=require('../../../mysqldb')['db'];var config=require(_0x6210('0x7'));var logger=require(_0x6210('0x8'))('import');config[_0x6210('0x9')]=_[_0x6210('0xa')](config[_0x6210('0x9')],{'host':_0x6210('0xb'),'port':0x18eb});var socket=require(_0x6210('0xc'))(new Redis(config[_0x6210('0x9')]));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var promisesAdditionalPhones=[];var promisesContact=[];var orderBy=0x0;var updatedRows=0x0;var stopped=![];var NOW=moment()[_0x6210('0xd')](_0x6210('0xe'));var tempTableName=_0x6210('0xf')+moment()['format']('YYYYMMDDHHmmss');var contactItemTypes=[];var phoneDescriptions=[];var hasAdditionalPhones=![];function isEmail(_0xe4b9e6){return/^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/[_0x6210('0x10')](_0xe4b9e6);}function selectNotIn(_0x4941cf,_0x4896a0,_0x42fbe8,_0x131d83,_0x3310aa){return squel['select']()[_0x6210('0x11')](_0x6210('0x12'))[_0x6210('0x13')](_0x131d83)[_0x6210('0x14')](_0x4896a0,null,_0x4896a0+_0x6210('0x15')+_0x131d83+'.'+_0x42fbe8)[_0x6210('0x16')](_0x131d83+'.'+_0x42fbe8+_0x6210('0x17')+_0x4941cf+'.'+_0x42fbe8)[_0x6210('0x16')](_0x4896a0+_0x6210('0x18')+_0x3310aa['join']()+')');}function handleAdditionalPhones(){return new Promise(function(_0x2dd886,_0x363888){promisesAdditionalPhones=[];promisesContact=[];return db[_0x6210('0x19')][_0x6210('0x1a')]('select\x20*\x20from\x20'+tempTableName)[_0x6210('0x1b')](function(_0x329fae){if(_0x329fae!==null){var _0x3af4ee=[];for(var _0xfe3fc0=0x0;_0xfe3fc0<_0x329fae[_0x6210('0x1c')];_0xfe3fc0++){var _0x2c7757=_0x329fae[_0xfe3fc0];if(!_[_0x6210('0x1d')](_0x2c7757[_0x6210('0x12')])){if(!_[_0x6210('0x1d')](_0x2c7757[_0x6210('0x1e')]))_0x3af4ee['push'](insertAdditionalPhones(_0x2c7757));promisesContact[_0x6210('0x1f')]({'contact':_0x2c7757});}}}Promise[_0x6210('0x20')](_0x3af4ee)[_0x6210('0x21')](function(){_0x2dd886({'val':0x1});});})['catch'](function(_0x12cc1b){logger[_0x6210('0x22')](_0x12cc1b[_0x6210('0x23')]);});});}function insertAdditionalPhones(_0x443d6c){return new Promise(function(_0x257645,_0x37b0ce){var _0x34d2c0=_0x443d6c[_0x6210('0x1e')];if(_['isNil'](_0x34d2c0))_0x37b0ce({'val':0x0});else{var _0x5eda55=_0x34d2c0[_0x6210('0x24')](';');var _0x2177c0=[];orderBy=0x0;for(var _0x287599=0x0;_0x287599<_0x5eda55[_0x6210('0x1c')];_0x287599++){_0x2177c0[_0x6210('0x1f')](splitAdditionalPhone(_0x443d6c['id'],_0x5eda55[_0x287599]));}Promise[_0x6210('0x20')](_0x2177c0)[_0x6210('0x21')](function(){_0x257645({'val':_0x5eda55[_0x6210('0x1c')]});});}});}function splitAdditionalPhone(_0x30ca85,_0x1805e3){return new Promise(function(_0x281d77,_0xd6b63e){var _0x20992a=_0x1805e3[_0x6210('0x24')](':');var _0x475aa5=_0x20992a[0x0];var _0x39492e=_0x20992a[0x1];if(_0x39492e!==''){var _0x16a077=_0x39492e[_0x6210('0x24')]('|');var _0x171bf4=[];for(var _0x38fe09=0x0;_0x38fe09<_0x16a077[_0x6210('0x1c')];_0x38fe09++){if(_0x16a077[_0x38fe09]!==''){var _0x1ea1cb=_[_0x6210('0x25')](promisesAdditionalPhones,{'contactId':_0x30ca85,'phone':_0x16a077[_0x38fe09]});if(_0x1ea1cb[_0x6210('0x1c')]==0x0){orderBy++;promisesAdditionalPhones['push']({'contactId':_0x30ca85,'contactTypeId':_0x475aa5,'phone':_0x16a077[_0x38fe09],'orderBy':orderBy});}}}_0x281d77({'ok':0x1});}else _0x281d77({'res':0x0});});}function createAdditionalPhone(_0x42c485,_0x35b4e2,_0x508173,_0x2b5932){var _0x2c255e='';var _0x4224ff='';var _0x600286=_0x508173[_0x6210('0x24')]('§');_0x2c255e=_0x600286[0x0];if(_0x600286[_0x6210('0x1c')]==0x2)_0x4224ff=_0x600286[0x1];return new Promise(function(_0x3175ce,_0x33937d){return db[_0x6210('0x26')][_0x6210('0x27')]({'where':{'CmContactId':_0x42c485,'item':_0x2c255e}})[_0x6210('0x21')](function(_0x1ae97d){if(_0x1ae97d){return db['CmContactHasItem'][_0x6210('0x28')]({'ItemTypeId':_0x35b4e2,'description':_0x4224ff,'OrderBy':_0x2b5932},{'where':{'CmContactId':_0x42c485,'item':_0x2c255e}})[_0x6210('0x21')](function(_0xe8651d){_0x3175ce({'res':'updated'});});}else{return db[_0x6210('0x26')][_0x6210('0x29')]({'CmContactId':_0x42c485,'item':_0x2c255e,'ItemTypeId':_0x35b4e2,'description':_0x4224ff,'OrderBy':_0x2b5932,'ItemClass':_0x6210('0x2a')})['then'](function(_0x450e07){_0x3175ce({'res':_0x6210('0x2b')});});}});});}function updateContact(_0x5135d0){return new Promise(function(_0x19e69b,_0x339abe){var _0x5c24ef=_0x5135d0['id'];delete _0x5135d0['id'];return db[_0x6210('0x2c')][_0x6210('0x28')](_0x5135d0,{'where':{'id':_0x5c24ef}})[_0x6210('0x21')](function(_0x34f29b){updatedRows+=0x1;return db[_0x6210('0x2d')][_0x6210('0x28')]({'phone':_0x5135d0[_0x6210('0x12')]},{'where':{'ContactId':_0x5c24ef}})[_0x6210('0x21')](function(_0x500434){_0x19e69b({'ret':'OK'});});});});}function insertCmHopper(_0x3e5dd5,_0x4f652b,_0x4c824f,_0xc28b72,_0x399758){var _0x48a5ab=[_0x6210('0x2e'),_0x6210('0x2f'),'cm_contacts.id',_0x6210('0x30'),_0x4f652b+'.'+_0xc28b72,_0x6210('0x31'),'cm_contacts.updatedAt','cm_contacts.priority','cm_contacts.UserId','\x22'+_0x399758+'\x22'];return squel['insert']()[_0x6210('0x32')](_0x6210('0x33'))[_0x6210('0x34')]([_0x6210('0x12'),_0x6210('0x35'),_0x6210('0x36'),_0x6210('0x37'),_0xc28b72,_0x6210('0x38'),_0x6210('0x39'),'priority',_0x6210('0x3a'),_0x6210('0x3b')],squel[_0x6210('0x3c')]()[_0x6210('0x3d')](_0x48a5ab)[_0x6210('0x13')](_0x4f652b)[_0x6210('0x14')](_0x6210('0x3e'),null,'cm_contacts.ListId\x20=\x20'+_0x4f652b+'.CmListId')[_0x6210('0x14')](_0x4c824f,null,_0x4c824f+_0x6210('0x15')+_0x4f652b+'.'+_0xc28b72)[_0x6210('0x16')](_0x4f652b+'.CmListId\x20=\x20?',_0x3e5dd5)[_0x6210('0x16')](_0x6210('0x3f'),NOW)[_0x6210('0x16')](_0x6210('0x40'),selectNotIn(_0x4f652b,_0x4c824f,_0xc28b72,_0x6210('0x33'),[_0x6210('0x41'),'\x22onlyIfOpen\x22']))['where'](_0x6210('0x40'),selectNotIn(_0x4f652b,_0x4c824f,_0xc28b72,_0x6210('0x33'),[_0x6210('0x41')])))[_0x6210('0x42')]();}function insertCmHopperBlack(_0x263ae3,_0x56a70c,_0x53c7a5,_0x253b4f){var _0x5554fe=[_0x6210('0x2e'),_0x6210('0x43'),_0x6210('0x30'),_0x56a70c+'.'+_0x253b4f,_0x6210('0x31'),_0x6210('0x44')];return squel[_0x6210('0x45')]()['into']('cm_hopper_black')[_0x6210('0x34')]([_0x6210('0x12'),'ContactId',_0x6210('0x37'),_0x253b4f,_0x6210('0x38'),'updatedAt'],squel[_0x6210('0x3c')]()[_0x6210('0x3d')](_0x5554fe)['from'](_0x56a70c)[_0x6210('0x14')](_0x6210('0x3e'),null,_0x6210('0x46')+_0x56a70c+'.CmListId')[_0x6210('0x14')](_0x53c7a5,null,_0x53c7a5+_0x6210('0x15')+_0x56a70c+'.'+_0x253b4f)[_0x6210('0x16')](_0x56a70c+'.CmListId\x20=\x20?',_0x263ae3)[_0x6210('0x16')](_0x6210('0x3f'),NOW)[_0x6210('0x16')](_0x6210('0x40'),squel[_0x6210('0x3c')]()[_0x6210('0x11')](_0x6210('0x12'))[_0x6210('0x13')](_0x6210('0x47'))[_0x6210('0x16')]('ListId\x20=\x20?',_0x263ae3)[_0x6210('0x16')](_0x253b4f+_0x6210('0x48'),_0x56a70c+'.'+_0x253b4f)))[_0x6210('0x42')]();}function insertCmHopperAdditionalPhones(_0x47ff53){var _0x3fe3c0=[_0x6210('0x49'),'cm_contact_has_items.item','cm_contact_has_items.OrderBy','cm_contact_has_items.createdAt',_0x6210('0x4a')];return squel[_0x6210('0x45')]()[_0x6210('0x32')]('cm_hopper_additional_phones')[_0x6210('0x34')](['CmHopperId','phone',_0x6210('0x4b'),'createdAt',_0x6210('0x39')],squel[_0x6210('0x3c')]()[_0x6210('0x3d')](_0x3fe3c0)[_0x6210('0x13')](_0x6210('0x33'))[_0x6210('0x14')](_0x6210('0x3e'),null,_0x6210('0x4c'))[_0x6210('0x14')](_0x6210('0x4d'),null,_0x6210('0x4e'))[_0x6210('0x16')](_0x6210('0x4f'),_0x47ff53)['where']('cm_contacts.createdAt\x20=\x20?',NOW))[_0x6210('0x42')]();}function insertCmContact(_0x5727b6,_0x4c2bcf,_0x45466f,_0x3f9e59){var _0x12f3af=_[_0x6210('0x50')](_[_0x6210('0x51')](_0x3f9e59),[_0x6210('0x37'),_0x6210('0x52'),_0x6210('0x38'),_0x6210('0x39')]);return squel[_0x6210('0x45')]()[_0x6210('0x32')](_0x6210('0x3e'))[_0x6210('0x34')](_0x12f3af,squel[_0x6210('0x3c')]()[_0x6210('0x3d')](_0x12f3af)[_0x6210('0x13')](_0x4c2bcf)[_0x6210('0x16')]('('+_0x45466f[_0x6210('0x14')](',')+_0x6210('0x53'),squel[_0x6210('0x3c')]()[_0x6210('0x3d')](_0x45466f)['from'](_0x6210('0x3e'))[_0x6210('0x16')](_0x6210('0x54'),_0x5727b6))['where'](_0x6210('0x55'),squel[_0x6210('0x3c')]()[_0x6210('0x11')]('MIN(id)','min_id')['from'](_0x4c2bcf)['group'](_0x45466f[_0x6210('0x14')](','))))[_0x6210('0x42')]();}function handleStop(){logger[_0x6210('0x56')](_0x6210('0x57'));stopped=!![];}function handleUncaughtException(_0x2581e1){logger['error'](_0x2581e1[_0x6210('0x23')]);process[_0x6210('0x58')](0x1);}function handleError(_0xa54be,_0x58073c){stats[_0x6210('0x59')]['push']({'name':_0x58073c[_0x6210('0x5a')],'message':_0x58073c[_0x6210('0x23')],'row':_0xa54be});}function handleQuery(_0x501818){logger[_0x6210('0x56')](_0x501818);return db[_0x6210('0x19')][_0x6210('0x1a')](_0x501818)[_0x6210('0x1b')](function(_0x446ab5){results[_0x6210('0x1f')](_0x446ab5);})[_0x6210('0x5b')](function(_0x9415f6){logger[_0x6210('0x22')](_0x9415f6[_0x6210('0x23')]);});}function main(_0x1219bd,_0x59efc7,_0x31bf0b,_0x359a91){logger[_0x6210('0x56')](_0x6210('0x5c'),_0x1219bd,JSON[_0x6210('0x5d')](_0x59efc7));process[_0x6210('0x5e')](_0x6210('0x5f'));var _0xc9924d=_0x59efc7[_0x6210('0x60')];var _0xe13afb=_[_0x6210('0x61')](_0xc9924d);var _0x5218ff=_0x59efc7['socket_timestamp'];var _0xf4a508=path[_0x6210('0x14')](config[_0x6210('0x62')],'server/files/tmp',_0x5218ff+'.csv');logger[_0x6210('0x56')](_0x6210('0x63'),_0x59efc7);db[_0x6210('0x64')][_0x6210('0x65')]({'raw':!![],'attributes':['id',_0x6210('0x66')]})[_0x6210('0x21')](function(_0x18d734){for(var _0x22c236=0x0;_0x22c236<_0x18d734[_0x6210('0x1c')];_0x22c236++){if(_0x18d734[_0x22c236]['name']in _0xc9924d){contactItemTypes[_0x6210('0x1f')](_0x18d734[_0x22c236]);delete _0xe13afb[_0x18d734[_0x22c236]['name']];hasAdditionalPhones=!![];}for(var _0x5a591e in _0xc9924d){if(_0x18d734[_0x22c236][_0x6210('0x66')]+_0x6210('0x67')===_0x5a591e){phoneDescriptions[_0x6210('0x1f')]({'itemTypeId':_0x18d734[_0x22c236]['id'],'description':_0x5a591e});delete _0xe13afb[_0x5a591e];}}}if(hasAdditionalPhones)_0xe13afb[_0x6210('0x1e')]='';var _0x29e806=_[_0x6210('0x51')](_0xe13afb)[_0x6210('0x14')]();logger[_0x6210('0x56')]('header',_0x29e806);fs[_0x6210('0x68')](_0xf4a508,_0x29e806+'\x0a');Papa['parse'](fs[_0x6210('0x69')](_0x1219bd),{'header':!![],'skipEmptyLines':!![],'step':function(_0x3007d5,_0x202c75){try{for(var _0x2f320b=0x0,_0x9123b6=[];_0x2f320b<_0x3007d5[_0x6210('0x6a')]['length'];_0x2f320b++){stats[_0x6210('0x6b')]+=0x1;if(_0x3007d5['errors'][_0x2f320b]){handleError(_0x3007d5['data'][_0x2f320b],_0x3007d5[_0x6210('0x59')][_0x2f320b]);}else{var _0x4cc96b=[];var _0x3bbd8b=[];var _0x4483ea={};for(var _0x493eae in _0xc9924d){let _0x5bbe57=contactItemTypes[_0x6210('0x6c')](_0xd45efc=>_0xd45efc['name']===_0x493eae);let _0x4b5e92=contactItemTypes[_0x6210('0x6c')](_0x583f35=>_0x583f35[_0x6210('0x66')]+_0x6210('0x67')===_0x493eae);if(_[_0x6210('0x1d')](_0x5bbe57)&&_['isNil'](_0x4b5e92)){if(_0xc9924d['hasOwnProperty'](_0x493eae)){if(_0x3007d5[_0x6210('0x6a')][_0x2f320b][_0xc9924d[_0x493eae]]){var _0x479d1c=_[_0x6210('0x6d')](_0x3007d5[_0x6210('0x6a')][_0x2f320b][_0xc9924d[_0x493eae]][_0x6210('0x6e')](/"/g,'\x27'));switch(_0x493eae){case _0x6210('0x35'):var _0x1f63a4=moment(_0x479d1c,'YYYY-MM-DD\x20HH:mm:ss',!![]);if(_0x1f63a4[_0x6210('0x6f')]()){_0x9123b6[_0x6210('0x1f')]('\x22'+_0x479d1c+'\x22');}else{_0x4cc96b['push'](_0x6210('0x70'));}break;case _0x6210('0x71'):var _0x306a32=parseInt(_0x479d1c);_0x479d1c=_['isNaN'](_0x306a32)||_0x306a32<0x0||_0x306a32>0x4?_0x359a91?0x3:0x2:_0x306a32;_0x9123b6[_0x6210('0x1f')]('\x22'+_0x479d1c+'\x22');break;case _0x6210('0x3a'):var _0x489a90=parseInt(_0x479d1c);if(_['isNumber'](_0x489a90)&&_['includes'](_0x31bf0b,_0x489a90)){_0x9123b6['push']('\x22'+_0x489a90+'\x22');}else{_0x4cc96b[_0x6210('0x1f')]('agent\x20not\x20exists');}break;case _0x6210('0x72'):if(isEmail(_0x479d1c)){_0x9123b6[_0x6210('0x1f')]('\x22'+_0x479d1c+'\x22');}else{_0x4cc96b[_0x6210('0x1f')](_0x6210('0x73'));}break;case _0x6210('0x74'):var _0x327e95=moment(_0x479d1c,'YYYY-MM-DD',!![]);if(_0x327e95['isValid']()){_0x9123b6[_0x6210('0x1f')]('\x22'+_0x479d1c+'\x22');}else{_0x4cc96b[_0x6210('0x1f')](_0x6210('0x75'));}break;default:_0x9123b6['push']('\x22'+_0x479d1c+'\x22');}}else{switch(_0x493eae){case _0x6210('0x76'):case _0x6210('0x12'):_0x4cc96b[_0x6210('0x1f')](_0x493eae+'\x20not\x20specified');break;default:_0x9123b6[_0x6210('0x1f')]('\x22\x22');}}}}else{var _0x3d2659='';if(!_['isNil'](_0x5bbe57)){if(!_0x4483ea[_0x6210('0x77')](_0x5bbe57['id'])){for(var _0x106358=0x0;_0x106358<_0xc9924d[_0x493eae]['length'];_0x106358++){var _0x479d1c=_[_0x6210('0x6d')](_0x3007d5['data'][_0x2f320b][_0xc9924d[_0x493eae][_0x106358]][_0x6210('0x6e')](/"/g,'\x27'));var _0x5de479=phoneDescriptions[_0x6210('0x6c')](_0x4f8098=>_0x4f8098['itemTypeId']===_0x5bbe57['id']);if(!_[_0x6210('0x1d')](_0x5de479)){var _0x36bf6d=_[_0x6210('0x6d')](_0x3007d5[_0x6210('0x6a')][_0x2f320b][_0xc9924d[_0x5de479[_0x6210('0x78')]][0x0]][_0x6210('0x6e')](/"/g,'\x27'));if(!_['isNil'](_0x36bf6d))_0x479d1c=_0x479d1c+'§'+_0x36bf6d;}if(_0x3d2659=='')_0x3d2659=_0x479d1c;else _0x3d2659+='|'+_0x479d1c;}_0x3bbd8b[_0x6210('0x1f')](_0x5bbe57['id']+':'+_0x3d2659);_0x4483ea[_0x5bbe57['id']]=0x1;}}}}if(hasAdditionalPhones){_0x9123b6[_0x6210('0x1f')]('\x22'+_0x3bbd8b[_0x6210('0x14')](';')+'\x22');}if(_0x4cc96b['length']){handleError(_0x3007d5[_0x6210('0x6a')][_0x2f320b],{'code':'SystemRow','message':_0x4cc96b[_0x6210('0x14')]()});}else{fs[_0x6210('0x79')](_0xf4a508,_0x9123b6['join']()+'\x0a');}_0x9123b6=[];}if(!(stats[_0x6210('0x6b')]%0xc8)){socket[_0x6210('0x7a')]('contact:import:'+_0x5218ff,stats);stats[_0x6210('0x59')]=[];}}if(stopped){logger[_0x6210('0x56')](_0x6210('0x7b'));_0x202c75[_0x6210('0x7c')]();}}catch(_0x503700){handleError(_0x3007d5[_0x6210('0x6a')][_0x2f320b],{'code':_0x6210('0x7d'),'message':_0x503700['message']});logger[_0x6210('0x22')](_0x6210('0x7e'),_0x503700[_0x6210('0x23')]);}},'complete':function(){try{var _0x863613=[];var _0x40db7b=tempTableName;_0x863613[_0x6210('0x1f')]('CREATE\x20TABLE\x20'+_0x40db7b+_0x6210('0x7f'));logger['info'](_0x6210('0x80'),contactItemTypes[_0x6210('0x1c')]);var _0x367d22=util[_0x6210('0xd')](_0x6210('0x81'),_0xf4a508,_0x40db7b,_0x29e806,_0x59efc7[_0x6210('0x37')],_0x59efc7[_0x6210('0x52')]||null,NOW,NOW);if(_[_0x6210('0x1d')](_0xc9924d[_0x6210('0x35')])){_0x367d22+=_0x6210('0x82');}_0x863613[_0x6210('0x1f')](_0x367d22);BPromise['each'](_0x863613,handleQuery)['then'](function(_0x5195dc){BPromise['all']([handleAdditionalPhones()])['then'](function(){_0x863613=[];for(var _0x561a0b=0x0;_0x561a0b<promisesContact[_0x6210('0x1c')];_0x561a0b++){_0x863613[_0x6210('0x1f')](updateContact(promisesContact[_0x561a0b][_0x6210('0x83')]));}BPromise['all'](_0x863613)[_0x6210('0x21')](function(){_0x863613=[];for(var _0xa15b3f=0x0;_0xa15b3f<promisesAdditionalPhones[_0x6210('0x1c')];_0xa15b3f++){_0x863613[_0x6210('0x1f')](createAdditionalPhone(promisesAdditionalPhones[_0xa15b3f][_0x6210('0x84')],promisesAdditionalPhones[_0xa15b3f][_0x6210('0x85')],promisesAdditionalPhones[_0xa15b3f][_0x6210('0x12')],promisesAdditionalPhones[_0xa15b3f][_0x6210('0x86')]));}BPromise['all'](_0x863613)[_0x6210('0x21')](function(){_0x863613=[];_0x863613[_0x6210('0x1f')](insertCmHopperAdditionalPhones(_0x59efc7['ListId']));_0x863613['push'](_0x6210('0x87')+_0x40db7b+';');BPromise[_0x6210('0x88')](_0x863613,handleQuery)[_0x6210('0x21')](function(_0x56c4e1){stats[_0x6210('0x89')]=!![];stats[_0x6210('0x8a')]=updatedRows;socket[_0x6210('0x7a')](_0x6210('0x8b')+_0x5218ff,stats);fs[_0x6210('0x8c')](_0x1219bd);fs[_0x6210('0x8c')](_0xf4a508);process[_0x6210('0x58')](0x0);})[_0x6210('0x5b')](function(_0x3ce79b){logger[_0x6210('0x22')](_0x3ce79b[_0x6210('0x23')]);process[_0x6210('0x58')](0x1);});});});});})[_0x6210('0x5b')](function(_0x412f9b){logger[_0x6210('0x22')](_0x412f9b[_0x6210('0x23')]);process['exit'](0x1);});}catch(_0x2b0090){logger[_0x6210('0x22')]('complete',_0x2b0090[_0x6210('0x23')]);process['exit'](0x1);}},'error':function(_0x371116,_0x63acb7,_0x5abbe9,_0xf6e8b7){throw new Error(_0xf6e8b7);}});});}function validate(){if(process[_0x6210('0x8d')]&&process['argv']['length']<0x4){throw new Error(_0x6210('0x8e'));}var _0x141bc0=path[_0x6210('0x14')](config[_0x6210('0x62')],_0x6210('0x8f'),process[_0x6210('0x8d')][0x2]);if(!fs['existsSync'](_0x141bc0)){throw new Error(_0x6210('0x90'));}var _0x23ef7b={};try{_0x23ef7b=JSON[_0x6210('0x91')](process[_0x6210('0x8d')][0x3]);if(!_0x23ef7b[_0x6210('0x60')]){throw new Error('binding\x20doesn\x27t\x20exists');}var _0x15f889=0x0;if(_0x23ef7b[_0x6210('0x60')][_0x6210('0x3a')]){_0x15f889=0x1;}if(!_0x23ef7b[_0x6210('0x37')]){throw new Error(_0x6210('0x92'));}}catch(_0x24a28e){throw new Error(_0x6210('0x93'));}var _0x1f37e7=[];try{_0x1f37e7=_[_0x6210('0x94')](JSON[_0x6210('0x91')](process['argv'][0x4]),'id');}catch(_0x35261b){logger[_0x6210('0x56')](_0x6210('0x95'));}main(_0x141bc0,_0x23ef7b,_0x1f37e7,_0x15f889);}validate();process['on'](_0x6210('0x96'),handleStop);process['on'](_0x6210('0x97'),handleUncaughtException);
\ No newline at end of file