Built motion from commit 449495f6.|2.6.27
[motion2.git] / server / components / import / cm / csv2.js
index 7f3971f..f06d9f9 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x9346=['message','exit','errors','code','sequelize','query','spread','push','catch','send','start','binding','root','server/files/tmp','.csv','header','writeFileSync','parse','createReadStream','data','length','rows','hasOwnProperty','trim','YYYY-MM-DD\x20HH:mm:ss','isValid','scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)','isNaN','isNumber','includes','agent\x20not\x20exists','email','dateOfBirth','YYYY-MM-DD','dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)','firstName','appendFileSync','contact:import:','Abort\x20parser','abort','SystemError','step','duplicates','CREATE\x20TABLE\x20','\x20LIKE\x20cm_contacts;','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\x20id\x20=\x20NULL,\x20ListId\x20=\x20%s,\x20CompanyId\x20=\x20%s,\x20createdAt\x20=\x20\x27%s\x27,\x20updatedAt\x20=\x20\x27%s\x27','isNil',',\x20scheduledAt\x20=\x20NOW()','DROP\x20TABLE\x20','voice_queues_has_cm_lists','voice_queues','VoiceQueueId','voice_queues_has_cm_blacklists','campaigns_has_cm_lists','campaigns','CampaignId','campaigns_has_cm_blacklists','each','then','finish','affectedRows','emit','unlink','complete','arguments\x20<filename>\x20<parameters>\x20<agents>','argv','existsSync','file\x20doesn\x27t\x20exists','binding\x20doesn\x27t\x20exists','phone\x20is\x20mandatory','firstName\x20is\x20mandatory','ListId\x20is\x20mandatory','body\x20id\x20mandatory','map','No\x20agent\x20available','SIGINT','uncaughtException','path','util','bluebird','moment','squel','ioredis','../../../mysqldb','../../../config/environment','../../../config/logger','import','redis','defaults','localhost','socket.io-emitter','format','test','select','phone','join','.id\x20=\x20','where','cm_contacts.phone','cm_contacts.scheduledat','cm_contacts.ListId','cm_contacts.updatedAt','cm_contacts.priority','cm_contacts.UserId','into','cm_hopper','fromQuery','scheduledat','ListId','createdAt','updatedAt','priority','UserId','recallme','from','cm_contacts','cm_contacts.ListId\x20=\x20','.CmListId','cm_contacts.createdAt\x20=\x20?','cm_contacts.phone\x20NOT\x20IN\x20(?)','\x22always\x22','\x22onlyIfOpen\x22','toString','cm_contacts.createdAt','insert','cm_hopper_black','ContactId','fields','field','ListId\x20=\x20?','\x20=\x20?','keys','CompanyId','deletedAt\x20IS\x20NULL','group','info','error'];(function(_0x2d7f0e,_0x3e6fbd){var _0x110b07=function(_0x557b00){while(--_0x557b00){_0x2d7f0e['push'](_0x2d7f0e['shift']());}};_0x110b07(++_0x3e6fbd);}(_0x9346,0xd6));var _0x6934=function(_0x2f0336,_0x7eb379){_0x2f0336=_0x2f0336-0x0;var _0x4745b1=_0x9346[_0x2f0336];return _0x4745b1;};'use strict';var fs=require('fs');var path=require(_0x6934('0x0'));var _=require('lodash');var Papa=require('papaparse');var util=require(_0x6934('0x1'));var BPromise=require(_0x6934('0x2'));var moment=require(_0x6934('0x3'));var squel=require(_0x6934('0x4'));var Redis=require(_0x6934('0x5'));var db=require(_0x6934('0x6'))['db'];var config=require(_0x6934('0x7'));var logger=require(_0x6934('0x8'))(_0x6934('0x9'));config[_0x6934('0xa')]=_[_0x6934('0xb')](config[_0x6934('0xa')],{'host':_0x6934('0xc'),'port':0x18eb});var socket=require(_0x6934('0xd'))(new Redis(config[_0x6934('0xa')]));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var stopped=![];var NOW=moment()[_0x6934('0xe')]('YYYY-MM-DD\x20HH:mm:ss');function isEmail(_0x5e51b6){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))*$/[_0x6934('0xf')](_0x5e51b6);}function selectNotIn(_0x2f2ce5,_0x203ba6,_0xa6de0d,_0x1850e4,_0x34298c){return squel[_0x6934('0x10')]()['field'](_0x6934('0x11'))['from'](_0x1850e4)[_0x6934('0x12')](_0x203ba6,null,_0x203ba6+_0x6934('0x13')+_0x1850e4+'.'+_0xa6de0d)['where'](_0x1850e4+'.'+_0xa6de0d+'\x20=\x20'+_0x2f2ce5+'.'+_0xa6de0d)[_0x6934('0x14')](_0x203ba6+'.dialCheckDuplicateType\x20IN\x20('+_0x34298c[_0x6934('0x12')]()+')');}function insertCmHopper(_0x151434,_0x3bdd67,_0x2fbbd8,_0x388568,_0x4867c5){var _0x503832=[_0x6934('0x15'),_0x6934('0x16'),'cm_contacts.id',_0x6934('0x17'),_0x3bdd67+'.'+_0x388568,'cm_contacts.createdAt',_0x6934('0x18'),_0x6934('0x19'),_0x6934('0x1a'),'\x22'+_0x4867c5+'\x22'];return squel['insert']()[_0x6934('0x1b')](_0x6934('0x1c'))[_0x6934('0x1d')]([_0x6934('0x11'),_0x6934('0x1e'),'ContactId',_0x6934('0x1f'),_0x388568,_0x6934('0x20'),_0x6934('0x21'),_0x6934('0x22'),_0x6934('0x23'),_0x6934('0x24')],squel[_0x6934('0x10')]()['fields'](_0x503832)[_0x6934('0x25')](_0x3bdd67)[_0x6934('0x12')](_0x6934('0x26'),null,_0x6934('0x27')+_0x3bdd67+_0x6934('0x28'))[_0x6934('0x12')](_0x2fbbd8,null,_0x2fbbd8+'.id\x20=\x20'+_0x3bdd67+'.'+_0x388568)[_0x6934('0x14')](_0x3bdd67+'.CmListId\x20=\x20?',_0x151434)[_0x6934('0x14')](_0x6934('0x29'),NOW)[_0x6934('0x14')](_0x6934('0x2a'),selectNotIn(_0x3bdd67,_0x2fbbd8,_0x388568,_0x6934('0x1c'),[_0x6934('0x2b'),_0x6934('0x2c')]))['where'](_0x6934('0x2a'),selectNotIn(_0x3bdd67,_0x2fbbd8,_0x388568,_0x6934('0x1c'),[_0x6934('0x2b')])))[_0x6934('0x2d')]();}function insertCmHopperBlack(_0x4f6789,_0x36a5d6,_0x217b42,_0x34a032){var _0x16c34d=[_0x6934('0x15'),'cm_contacts.id',_0x6934('0x17'),_0x36a5d6+'.'+_0x34a032,_0x6934('0x2e'),'cm_contacts.updatedAt'];return squel[_0x6934('0x2f')]()[_0x6934('0x1b')](_0x6934('0x30'))[_0x6934('0x1d')](['phone',_0x6934('0x31'),_0x6934('0x1f'),_0x34a032,_0x6934('0x20'),_0x6934('0x21')],squel['select']()[_0x6934('0x32')](_0x16c34d)['from'](_0x36a5d6)[_0x6934('0x12')](_0x6934('0x26'),null,'cm_contacts.ListId\x20=\x20'+_0x36a5d6+_0x6934('0x28'))[_0x6934('0x12')](_0x217b42,null,_0x217b42+'.id\x20=\x20'+_0x36a5d6+'.'+_0x34a032)[_0x6934('0x14')](_0x36a5d6+'.CmListId\x20=\x20?',_0x4f6789)[_0x6934('0x14')](_0x6934('0x29'),NOW)['where'](_0x6934('0x2a'),squel[_0x6934('0x10')]()[_0x6934('0x33')](_0x6934('0x11'))[_0x6934('0x25')](_0x6934('0x30'))[_0x6934('0x14')](_0x6934('0x34'),_0x4f6789)[_0x6934('0x14')](_0x34a032+_0x6934('0x35'),_0x36a5d6+'.'+_0x34a032)))[_0x6934('0x2d')]();}function insertCmContact(_0x554e82,_0x38fa81,_0x3c7911,_0x5a4680){var _0x1e9f14=_['concat'](_[_0x6934('0x36')](_0x5a4680),[_0x6934('0x1f'),_0x6934('0x37'),_0x6934('0x20'),_0x6934('0x21')]);return squel[_0x6934('0x2f')]()[_0x6934('0x1b')](_0x6934('0x26'))[_0x6934('0x1d')](_0x1e9f14,squel[_0x6934('0x10')]()[_0x6934('0x32')](_0x1e9f14)[_0x6934('0x25')](_0x38fa81)['where']('('+_0x3c7911['join'](',')+')\x20NOT\x20IN\x20?',squel['select']()[_0x6934('0x32')](_0x3c7911)[_0x6934('0x25')](_0x6934('0x26'))[_0x6934('0x14')](_0x6934('0x34'),_0x554e82)[_0x6934('0x14')](_0x6934('0x38')))[_0x6934('0x14')]('id\x20IN\x20?',squel[_0x6934('0x10')]()[_0x6934('0x33')]('MIN(id)','min_id')[_0x6934('0x25')](_0x38fa81)[_0x6934('0x39')](_0x3c7911['join'](','))))[_0x6934('0x2d')]();}function handleStop(){logger[_0x6934('0x3a')]('Received\x20SIGINT');stopped=!![];}function handleUncaughtException(_0x499040){logger[_0x6934('0x3b')](_0x499040[_0x6934('0x3c')]);process[_0x6934('0x3d')](0x1);}function handleError(_0x310c14,_0x3e35e5){stats[_0x6934('0x3e')]['push']({'name':_0x3e35e5[_0x6934('0x3f')],'message':_0x3e35e5['message'],'row':_0x310c14});}function handleQuery(_0x2e9c44){logger[_0x6934('0x3a')](_0x2e9c44);return db[_0x6934('0x40')][_0x6934('0x41')](_0x2e9c44)[_0x6934('0x42')](function(_0x3b5509){results[_0x6934('0x43')](_0x3b5509);})[_0x6934('0x44')](function(_0x34bcd0){logger[_0x6934('0x3b')](_0x34bcd0[_0x6934('0x3c')]);});}function main(_0x234bd6,_0x4d9fc8,_0x5cfdc3,_0x58296d){logger[_0x6934('0x3a')]('main',_0x234bd6,JSON['stringify'](_0x4d9fc8));process[_0x6934('0x45')](_0x6934('0x46'));var _0xec47bb=_0x4d9fc8[_0x6934('0x47')];var _0x1868bd=_0x4d9fc8['socket_timestamp'];var _0x5ce2df=path[_0x6934('0x12')](config[_0x6934('0x48')],_0x6934('0x49'),_0x1868bd+_0x6934('0x4a'));var _0x2ce23f=_['keys'](_0xec47bb)['join']();logger[_0x6934('0x3a')](_0x6934('0x4b'),_0x2ce23f);fs[_0x6934('0x4c')](_0x5ce2df,_0x2ce23f+'\x0a');Papa[_0x6934('0x4d')](fs[_0x6934('0x4e')](_0x234bd6),{'header':!![],'skipEmptyLines':!![],'step':function(_0x10144f,_0x1c287d){try{for(var _0xa20cf3=0x0,_0x156b18=[];_0xa20cf3<_0x10144f[_0x6934('0x4f')][_0x6934('0x50')];_0xa20cf3++){stats[_0x6934('0x51')]+=0x1;if(_0x10144f[_0x6934('0x3e')][_0xa20cf3]){handleError(_0x10144f[_0x6934('0x4f')][_0xa20cf3],_0x10144f['errors'][_0xa20cf3]);}else{var _0x19805a=[];for(var _0x5aa493 in _0xec47bb){if(_0xec47bb[_0x6934('0x52')](_0x5aa493)){if(_0x10144f[_0x6934('0x4f')][_0xa20cf3][_0xec47bb[_0x5aa493]]){var _0x2cfb52=_[_0x6934('0x53')](_0x10144f['data'][_0xa20cf3][_0xec47bb[_0x5aa493]]['replace'](/"/g,'\x27'));switch(_0x5aa493){case _0x6934('0x1e'):var _0x422e82=moment(_0x2cfb52,_0x6934('0x54'),!![]);if(_0x422e82[_0x6934('0x55')]()){_0x156b18[_0x6934('0x43')]('\x22'+_0x2cfb52+'\x22');}else{_0x19805a[_0x6934('0x43')](_0x6934('0x56'));}break;case _0x6934('0x22'):var _0x1d535d=parseInt(_0x2cfb52);_0x2cfb52=_[_0x6934('0x57')](_0x1d535d)||_0x1d535d<0x0||_0x1d535d>0x4?_0x58296d?0x3:0x2:_0x1d535d;_0x156b18[_0x6934('0x43')]('\x22'+_0x2cfb52+'\x22');break;case _0x6934('0x23'):var _0x3574d0=parseInt(_0x2cfb52);if(_[_0x6934('0x58')](_0x3574d0)&&_[_0x6934('0x59')](_0x5cfdc3,_0x3574d0)){_0x156b18[_0x6934('0x43')]('\x22'+_0x3574d0+'\x22');}else{_0x19805a['push'](_0x6934('0x5a'));}break;case _0x6934('0x5b'):if(isEmail(_0x2cfb52)){_0x156b18[_0x6934('0x43')]('\x22'+_0x2cfb52+'\x22');}else{_0x19805a[_0x6934('0x43')]('email\x20wrong\x20format');}break;case _0x6934('0x5c'):var _0x5c7878=moment(_0x2cfb52,_0x6934('0x5d'),!![]);if(_0x5c7878[_0x6934('0x55')]()){_0x156b18[_0x6934('0x43')]('\x22'+_0x2cfb52+'\x22');}else{_0x19805a['push'](_0x6934('0x5e'));}break;default:_0x156b18[_0x6934('0x43')]('\x22'+_0x2cfb52+'\x22');}}else{switch(_0x5aa493){case _0x6934('0x5f'):case _0x6934('0x11'):_0x19805a[_0x6934('0x43')](_0x5aa493+'\x20not\x20specified');break;default:_0x156b18[_0x6934('0x43')]('\x22\x22');}}}}if(_0x19805a[_0x6934('0x50')]){handleError(_0x10144f[_0x6934('0x4f')][_0xa20cf3],{'code':'SystemRow','message':_0x19805a[_0x6934('0x12')]()});}else{fs[_0x6934('0x60')](_0x5ce2df,_0x156b18[_0x6934('0x12')]()+'\x0a');}_0x156b18=[];}if(!(stats[_0x6934('0x51')]%0xc8)){socket['emit'](_0x6934('0x61')+_0x1868bd,stats);stats['errors']=[];}}if(stopped){logger[_0x6934('0x3a')](_0x6934('0x62'));_0x1c287d[_0x6934('0x63')]();}}catch(_0x4d3ca4){handleError(_0x10144f[_0x6934('0x4f')][_0xa20cf3],{'code':_0x6934('0x64'),'message':_0x4d3ca4[_0x6934('0x3c')]});logger[_0x6934('0x3b')](_0x6934('0x65'),_0x4d3ca4[_0x6934('0x3c')]);}},'complete':function(){try{var _0x336eee=[];var _0x230c4b='cm_contacts';if(_0x4d9fc8[_0x6934('0x66')]&&_0x4d9fc8[_0x6934('0x66')][_0x6934('0x50')]){_0x230c4b='cm_contacts_'+_0x1868bd;_0x336eee[_0x6934('0x43')](_0x6934('0x67')+_0x230c4b+_0x6934('0x68'));}var _0x54401f=util[_0x6934('0xe')](_0x6934('0x69'),_0x5ce2df,_0x230c4b,_0x2ce23f,_0x4d9fc8[_0x6934('0x1f')],_0x4d9fc8[_0x6934('0x37')]||null,NOW,NOW);if(_[_0x6934('0x6a')](_0xec47bb[_0x6934('0x1e')])){_0x54401f+=_0x6934('0x6b');}_0x336eee[_0x6934('0x43')](_0x54401f);if(_0x4d9fc8[_0x6934('0x66')]&&_0x4d9fc8['duplicates'][_0x6934('0x50')]){_0x336eee[_0x6934('0x43')](insertCmContact(_0x4d9fc8['ListId'],_0x230c4b,_0x4d9fc8[_0x6934('0x66')],_0xec47bb));_0x336eee['push'](_0x6934('0x6c')+_0x230c4b+';');}_0x336eee[_0x6934('0x43')](insertCmHopper(_0x4d9fc8[_0x6934('0x1f')],_0x6934('0x6d'),_0x6934('0x6e'),_0x6934('0x6f'),_0x58296d));_0x336eee[_0x6934('0x43')](insertCmHopperBlack(_0x4d9fc8[_0x6934('0x1f')],_0x6934('0x70'),_0x6934('0x6e'),_0x6934('0x6f')));_0x336eee['push'](insertCmHopper(_0x4d9fc8[_0x6934('0x1f')],_0x6934('0x71'),_0x6934('0x72'),_0x6934('0x73'),_0x58296d));_0x336eee[_0x6934('0x43')](insertCmHopperBlack(_0x4d9fc8[_0x6934('0x1f')],_0x6934('0x74'),_0x6934('0x72'),_0x6934('0x73')));BPromise[_0x6934('0x75')](_0x336eee,handleQuery)[_0x6934('0x76')](function(_0x564734){stats[_0x6934('0x77')]=!![];stats['affectedRows']=_0x4d9fc8[_0x6934('0x66')]&&_0x4d9fc8[_0x6934('0x66')][_0x6934('0x50')]?results[0x2]['affectedRows']:results[0x0][_0x6934('0x78')];socket[_0x6934('0x79')](_0x6934('0x61')+_0x1868bd,stats);fs[_0x6934('0x7a')](_0x234bd6);fs[_0x6934('0x7a')](_0x5ce2df);process['exit'](0x0);})[_0x6934('0x44')](function(_0x37e212){logger['error'](_0x37e212['message']);process[_0x6934('0x3d')](0x1);});}catch(_0x21bede){logger[_0x6934('0x3b')](_0x6934('0x7b'),_0x21bede[_0x6934('0x3c')]);process[_0x6934('0x3d')](0x1);}},'error':function(_0x4c99c6,_0x57adbf,_0x548e65,_0x25c796){throw new Error(_0x25c796);}});}function validate(){if(process['argv']&&process['argv']['length']<0x4){throw new Error(_0x6934('0x7c'));}var _0x403d53=path[_0x6934('0x12')](config[_0x6934('0x48')],'server/files/tmp',process[_0x6934('0x7d')][0x2]);if(!fs[_0x6934('0x7e')](_0x403d53)){throw new Error(_0x6934('0x7f'));}var _0x21600e={};try{_0x21600e=JSON[_0x6934('0x4d')](process[_0x6934('0x7d')][0x3]);if(!_0x21600e[_0x6934('0x47')]){throw new Error(_0x6934('0x80'));}if(!_0x21600e[_0x6934('0x47')]['phone']){throw new Error(_0x6934('0x81'));}if(!_0x21600e[_0x6934('0x47')][_0x6934('0x5f')]){throw new Error(_0x6934('0x82'));}var _0x3772c7=0x0;if(_0x21600e[_0x6934('0x47')][_0x6934('0x23')]){_0x3772c7=0x1;}if(!_0x21600e[_0x6934('0x1f')]){throw new Error(_0x6934('0x83'));}}catch(_0x356458){throw new Error(_0x6934('0x84'));}var _0x51992c=[];try{_0x51992c=_[_0x6934('0x85')](JSON[_0x6934('0x4d')](process['argv'][0x4]),'id');}catch(_0x5114cb){logger[_0x6934('0x3a')](_0x6934('0x86'));}main(_0x403d53,_0x21600e,_0x51992c,_0x3772c7);}validate();process['on'](_0x6934('0x87'),handleStop);process['on'](_0x6934('0x88'),handleUncaughtException);
\ No newline at end of file
+var _0x375b=['filter','CmContactHasItem','update','updated','create','inserted','cm_contacts.scheduledat','cm_contacts.id','cm_contacts.ListId','cm_contacts.createdAt','cm_contacts.updatedAt','cm_contacts.priority','cm_contacts.UserId','fromQuery','scheduledat','ContactId','ListId','createdAt','UserId','fields','cm_contacts','cm_contacts.ListId\x20=\x20','.CmListId','join','cm_contacts.createdAt\x20=\x20?','cm_contacts.phone\x20NOT\x20IN\x20(?)','cm_hopper','\x22onlyIfOpen\x22','\x22always\x22','toString','insert','into','updatedAt','.CmListId\x20=\x20?','ListId\x20=\x20?','cm_contacts.phone','date_add(cm_contacts.scheduledat,interval\x20','.offset-cm_contacts.utcOffset\x20minute)','priority','recallme','cm_hopper_black','cm_hopper.id','cm_contact_has_items.OrderBy','cm_contact_has_items.createdAt','cm_contact_has_items.updatedAt','cm_hopper_additional_phones','CmHopperId','cm_hopper.ListId\x20=\x20?','concat','keys','CompanyId','scheduledAt',')\x20NOT\x20IN\x20?','deletedAt\x20IS\x20NULL','id\x20IN\x20?','MIN(id)','min_id','group','info','Received\x20SIGINT','error','errors','message','sequelize','query','catch','campaigns.id','campaigns.dialTimezone','campaigns','campaigns_has_cm_lists','campaigns.id\x20=\x20campaigns_has_cm_lists.CampaignId','campaigns_has_cm_lists.CmListId=','spread','voice_queues.id','voice_queues.dialTimezone','voice_queues.id\x20=\x20voice_queues_has_cm_lists.VoiceQueueId','timezones','dialTimezone','utcOffset','set','main','stringify','send','start','clone','socket_timestamp','root','server/files/tmp','includes','header','name','writeFileSync','parse','createReadStream','rows','find','_description','hasOwnProperty','data','trim','replace','isValid','isNaN','isNumber','agent\x20not\x20exists','dateOfBirth','YYYY-MM-DD','dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)','firstName','\x20not\x20specified','itemTypeId','description','SystemRow','appendFileSync','emit','contact:import:','Abort\x20parser','SystemError','step','duplicates','cm_contacts_','CREATE\x20TABLE\x20','campaigns_','voice_queues_','(id\x20int,dialTimezone\x20varchar(255),offset\x20int);','each','dialTimezone,utcOffset','format','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\x20id\x20=\x20NULL,\x20ListId\x20=\x20%s,\x20CompanyId\x20=\x20%s,\x20createdAt\x20=\x20\x27%s\x27,\x20updatedAt\x20=\x20\x27%s\x27','contactId','contactTypeId','voice_queues','VoiceQueueId','voice_queues_has_cm_blacklists','CampaignId','campaigns_has_cm_blacklists','voice_queues_has_cm_lists','DROP\x20TABLE\x20','finish','affectedRows','unlink','exit','complete','argv','arguments\x20<filename>\x20<parameters>\x20<agents>','file\x20doesn\x27t\x20exists','binding\x20doesn\x27t\x20exists','binding','ListId\x20is\x20mandatory','body\x20id\x20mandatory','map','SIGINT','uncaughtException','lodash','papaparse','bluebird','moment','squel','ioredis','../../../config/environment','../../../config/environment/shared','../../../config/logger','import','redis','localhost','YYYY-MM-DD\x20HH:mm:ss','test','select','field','phone','from','.id\x20=\x20','where','\x20=\x20','.dialCheckDuplicateType\x20IN\x20(','CmContact','findAll','AdditionalPhones','then','length','push','all','split','isNil'];(function(_0x3af039,_0x28d762){var _0x19aa9f=function(_0x375d26){while(--_0x375d26){_0x3af039['push'](_0x3af039['shift']());}};_0x19aa9f(++_0x28d762);}(_0x375b,0x99));var _0xb375=function(_0x47548c,_0x19d9bb){_0x47548c=_0x47548c-0x0;var _0x4a75b1=_0x375b[_0x47548c];return _0x4a75b1;};'use strict';var fs=require('fs');var path=require('path');var _=require(_0xb375('0x0'));var Papa=require(_0xb375('0x1'));var util=require('util');var BPromise=require(_0xb375('0x2'));var moment=require(_0xb375('0x3'));var squel=require(_0xb375('0x4'));var Redis=require(_0xb375('0x5'));var db=require('../../../mysqldb')['db'];var config=require(_0xb375('0x6'));var shared=require(_0xb375('0x7'));var logger=require(_0xb375('0x8'))(_0xb375('0x9'));config[_0xb375('0xa')]=_['defaults'](config[_0xb375('0xa')],{'host':_0xb375('0xb'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xb375('0xa')]));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var promisesAdditionalPhones=[];var orderBy=0x0;var stopped=![];var NOW=moment()['format'](_0xb375('0xc'));var contactItemTypes=[];var phoneDescriptions=[];var hasAdditionalPhones=![];var tmp_voice_queues;var tmp_campaigns;var tzOffset=0x0;var hasTZ;var NOW=moment()['format'](_0xb375('0xc'));function isEmail(_0x319de2){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))*$/[_0xb375('0xd')](_0x319de2);}function selectNotIn(_0x58d3e9,_0x45350d,_0x24b72b,_0x3539b9,_0x79b905){return squel[_0xb375('0xe')]()[_0xb375('0xf')](_0xb375('0x10'))[_0xb375('0x11')](_0x3539b9)['join'](_0x45350d,null,_0x45350d+_0xb375('0x12')+_0x3539b9+'.'+_0x24b72b)[_0xb375('0x13')](_0x3539b9+'.'+_0x24b72b+_0xb375('0x14')+_0x58d3e9+'.'+_0x24b72b)[_0xb375('0x13')](_0x45350d+_0xb375('0x15')+_0x79b905['join']()+')');}function handleAdditionalPhones(){return new Promise(function(_0x3c627f,_0x2f2112){promisesAdditionalPhones=[];return db[_0xb375('0x16')][_0xb375('0x17')]({'raw':!![],'attributes':['id',_0xb375('0x18')],'where':{'createdAt':NOW,'AdditionalPhones':{'$ne':null}}})[_0xb375('0x19')](function(_0x5c14f1){if(_0x5c14f1!==null){var _0x4ec8ee=[];for(var _0x13d551=0x0;_0x13d551<_0x5c14f1[_0xb375('0x1a')];_0x13d551++){var _0x5ab7ea=_0x5c14f1[_0x13d551];_0x4ec8ee[_0xb375('0x1b')](insertAdditionalPhones(_0x5ab7ea));}}Promise[_0xb375('0x1c')](_0x4ec8ee)[_0xb375('0x19')](function(){_0x3c627f({'val':0x1});});});});}function insertAdditionalPhones(_0x37abf4){return new Promise(function(_0xa1b84d,_0x1a7b87){var _0x4f0ceb=_0x37abf4[_0xb375('0x18')];var _0x140814=_0x4f0ceb[_0xb375('0x1d')](';');var _0x5ca614=[];orderBy=0x0;for(var _0x5be2aa=0x0;_0x5be2aa<_0x140814[_0xb375('0x1a')];_0x5be2aa++){_0x5ca614['push'](splitAdditionalPhone(_0x37abf4['id'],_0x140814[_0x5be2aa]));}Promise[_0xb375('0x1c')](_0x5ca614)[_0xb375('0x19')](function(){_0xa1b84d({'val':_0x140814['length']});});});}function splitAdditionalPhone(_0x186b42,_0x400fd9){return new Promise(function(_0x10227d,_0x126803){var _0x653bd6=_0x400fd9[_0xb375('0x1d')](':');var _0x2dcc2e=_0x653bd6[0x0];var _0x1e8ffe=_0x653bd6[0x1];if(!_[_0xb375('0x1e')](_0x1e8ffe)){var _0x22a0ee=_0x1e8ffe[_0xb375('0x1d')]('|');var _0x35e392=[];for(var _0x473e13=0x0;_0x473e13<_0x22a0ee[_0xb375('0x1a')];_0x473e13++){if(_0x22a0ee[_0x473e13]!==''){var _0x3d5313=_[_0xb375('0x1f')](promisesAdditionalPhones,{'contactId':_0x186b42,'phone':_0x22a0ee[_0x473e13]});if(_0x3d5313[_0xb375('0x1a')]==0x0){orderBy++;promisesAdditionalPhones[_0xb375('0x1b')]({'contactId':_0x186b42,'contactTypeId':_0x2dcc2e,'phone':_0x22a0ee[_0x473e13],'orderBy':orderBy});}}}_0x10227d({'ok':0x1});}else _0x10227d({'res':0x0});});}function createAdditionalPhone(_0x36bf11,_0x5a2cf4,_0x5a38d6,_0x30707a){var _0x407703='';var _0x4f1569='';var _0x4f6ef1=_0x5a38d6[_0xb375('0x1d')]('§');_0x407703=_0x4f6ef1[0x0];if(_0x4f6ef1['length']==0x2)_0x4f1569=_0x4f6ef1[0x1];return new Promise(function(_0x10ee6d,_0x387084){return db['CmContactHasItem']['findOne']({'where':{'CmContactId':_0x36bf11,'item':_0x407703}})[_0xb375('0x19')](function(_0xf1de04){if(_0xf1de04){return db[_0xb375('0x20')][_0xb375('0x21')]({'ItemTypeId':_0x5a2cf4,'description':_0x4f1569,'OrderBy':_0x30707a},{'where':{'CmContactId':_0x36bf11,'item':_0x407703}})['then'](function(_0x19bcf1){_0x10ee6d({'res':_0xb375('0x22')});});}else{return db[_0xb375('0x20')][_0xb375('0x23')]({'CmContactId':_0x36bf11,'item':_0x407703,'description':_0x4f1569,'ItemTypeId':_0x5a2cf4,'OrderBy':_0x30707a,'ItemClass':'PHONE'})[_0xb375('0x19')](function(_0x25aed){_0x10ee6d({'res':_0xb375('0x24')});});}});});}function insertCmHopper(_0x34982e,_0x50b64c,_0xffc6dc,_0x3a7e24,_0x5f5b54){var _0x345db5=['cm_contacts.phone',_0xb375('0x25'),_0xb375('0x26'),_0xb375('0x27'),_0x50b64c+'.'+_0x3a7e24,_0xb375('0x28'),_0xb375('0x29'),_0xb375('0x2a'),_0xb375('0x2b'),'\x22'+_0x5f5b54+'\x22'];return squel['insert']()['into']('cm_hopper')[_0xb375('0x2c')](['phone',_0xb375('0x2d'),_0xb375('0x2e'),_0xb375('0x2f'),_0x3a7e24,_0xb375('0x30'),'updatedAt','priority',_0xb375('0x31'),'recallme'],squel[_0xb375('0xe')]()[_0xb375('0x32')](_0x345db5)[_0xb375('0x11')](_0x50b64c)['join'](_0xb375('0x33'),null,_0xb375('0x34')+_0x50b64c+_0xb375('0x35'))[_0xb375('0x36')](_0xffc6dc,null,_0xffc6dc+'.id\x20=\x20'+_0x50b64c+'.'+_0x3a7e24)[_0xb375('0x13')](_0x50b64c+'.CmListId\x20=\x20?',_0x34982e)['where'](_0xb375('0x37'),NOW)[_0xb375('0x13')](_0xb375('0x38'),selectNotIn(_0x50b64c,_0xffc6dc,_0x3a7e24,_0xb375('0x39'),['\x22always\x22',_0xb375('0x3a')]))[_0xb375('0x13')](_0xb375('0x38'),selectNotIn(_0x50b64c,_0xffc6dc,_0x3a7e24,'cm_hopper',[_0xb375('0x3b')])))[_0xb375('0x3c')]();}function insertCmHopperBlack(_0x3c53e4,_0x5885d0,_0x283ba3,_0x2a651a){var _0x5942e8=['cm_contacts.phone',_0xb375('0x26'),_0xb375('0x27'),_0x5885d0+'.'+_0x2a651a,_0xb375('0x28'),'cm_contacts.updatedAt'];return squel[_0xb375('0x3d')]()[_0xb375('0x3e')]('cm_hopper_black')['fromQuery'](['phone','ContactId','ListId',_0x2a651a,_0xb375('0x30'),_0xb375('0x3f')],squel[_0xb375('0xe')]()[_0xb375('0x32')](_0x5942e8)[_0xb375('0x11')](_0x5885d0)[_0xb375('0x36')]('cm_contacts',null,_0xb375('0x34')+_0x5885d0+_0xb375('0x35'))[_0xb375('0x36')](_0x283ba3,null,_0x283ba3+'.id\x20=\x20'+_0x5885d0+'.'+_0x2a651a)[_0xb375('0x13')](_0x5885d0+_0xb375('0x40'),_0x3c53e4)[_0xb375('0x13')](_0xb375('0x37'),NOW)[_0xb375('0x13')](_0xb375('0x38'),squel['select']()['field'](_0xb375('0x10'))[_0xb375('0x11')]('cm_hopper_black')[_0xb375('0x13')](_0xb375('0x41'),_0x3c53e4)[_0xb375('0x13')](_0x2a651a+_0xb375('0x14')+_0x5885d0+'.'+_0x2a651a)))[_0xb375('0x3c')]();}function insertTzCmHopper(_0x1cdae0,_0x2e3faf,_0x32793c,_0x324686,_0x2a36b1,_0x2e3fd7){var _0x44c61f=[_0xb375('0x42'),_0xb375('0x43')+_0x2e3fd7+_0xb375('0x44'),_0xb375('0x26'),_0xb375('0x27'),_0x2e3faf+'.'+_0x324686,_0xb375('0x28'),_0xb375('0x29'),_0xb375('0x2a'),_0xb375('0x2b'),'\x22'+_0x2a36b1+'\x22'];var _0x9f444=squel[_0xb375('0x3d')]()[_0xb375('0x3e')](_0xb375('0x39'))[_0xb375('0x2c')]([_0xb375('0x10'),'scheduledat','ContactId',_0xb375('0x2f'),_0x324686,'createdAt',_0xb375('0x3f'),_0xb375('0x45'),_0xb375('0x31'),_0xb375('0x46')],squel['select']()[_0xb375('0x32')](_0x44c61f)[_0xb375('0x11')](_0x2e3faf)[_0xb375('0x36')](_0xb375('0x33'),null,_0xb375('0x34')+_0x2e3faf+_0xb375('0x35'))['join'](_0x32793c,null,_0x32793c+_0xb375('0x12')+_0x2e3faf+'.'+_0x324686)[_0xb375('0x36')](_0x2e3fd7,null,_0x2e3fd7+'.id\x20=\x20'+_0x2e3faf+'.'+_0x324686)[_0xb375('0x13')](_0x2e3faf+_0xb375('0x40'),_0x1cdae0)[_0xb375('0x13')](_0xb375('0x37'),NOW)[_0xb375('0x13')](_0xb375('0x38'),selectNotIn(_0x2e3faf,_0x32793c,_0x324686,_0xb375('0x39'),[_0xb375('0x3b'),_0xb375('0x3a')]))['where'](_0xb375('0x38'),selectNotIn(_0x2e3faf,_0x32793c,_0x324686,'cm_hopper',[_0xb375('0x3b')])))[_0xb375('0x3c')]();return _0x9f444;}function insertTzCmHopperBlack(_0x86cc37,_0xcafaa7,_0x29aa23,_0x37ed61){var _0x274fcc=[_0xb375('0x42'),_0xb375('0x26'),_0xb375('0x27'),_0xcafaa7+'.'+_0x37ed61,_0xb375('0x28'),_0xb375('0x29')];return squel['insert']()[_0xb375('0x3e')](_0xb375('0x47'))[_0xb375('0x2c')]([_0xb375('0x10'),_0xb375('0x2e'),_0xb375('0x2f'),_0x37ed61,_0xb375('0x30'),_0xb375('0x3f')],squel['select']()[_0xb375('0x32')](_0x274fcc)['from'](_0xcafaa7)[_0xb375('0x36')](_0xb375('0x33'),null,_0xb375('0x34')+_0xcafaa7+'.CmListId')[_0xb375('0x36')](_0x29aa23,null,_0x29aa23+_0xb375('0x12')+_0xcafaa7+'.'+_0x37ed61)[_0xb375('0x13')](_0xcafaa7+_0xb375('0x40'),_0x86cc37)['where'](_0xb375('0x37'),NOW)[_0xb375('0x13')](_0xb375('0x38'),squel[_0xb375('0xe')]()[_0xb375('0xf')](_0xb375('0x10'))['from'](_0xb375('0x47'))[_0xb375('0x13')](_0xb375('0x41'),_0x86cc37)['where'](_0x37ed61+_0xb375('0x14')+_0xcafaa7+'.'+_0x37ed61)))[_0xb375('0x3c')]();}function insertCmHopperAdditionalPhones(_0xefd9af){var _0x320072=[_0xb375('0x48'),'cm_contact_has_items.item',_0xb375('0x49'),_0xb375('0x4a'),_0xb375('0x4b')];return squel[_0xb375('0x3d')]()[_0xb375('0x3e')](_0xb375('0x4c'))['fromQuery']([_0xb375('0x4d'),_0xb375('0x10'),'OrderBy',_0xb375('0x30'),_0xb375('0x3f')],squel[_0xb375('0xe')]()[_0xb375('0x32')](_0x320072)['from'](_0xb375('0x39'))[_0xb375('0x36')](_0xb375('0x33'),null,'cm_contacts.id\x20=\x20cm_hopper.ContactId')[_0xb375('0x36')]('cm_contact_has_items',null,'cm_contacts.id\x20=\x20cm_contact_has_items.CmContactId')['where'](_0xb375('0x4e'),_0xefd9af)[_0xb375('0x13')]('cm_contacts.createdAt\x20=\x20?',NOW))[_0xb375('0x3c')]();}function insertCmContact(_0x2966ac,_0x4ec0ad,_0x459df8,_0x14c7e9){var _0x5b6713=_[_0xb375('0x4f')](_[_0xb375('0x50')](_0x14c7e9),[_0xb375('0x2f'),_0xb375('0x51'),_0xb375('0x30'),_0xb375('0x3f'),_0xb375('0x52')]);return squel[_0xb375('0x3d')]()[_0xb375('0x3e')](_0xb375('0x33'))[_0xb375('0x2c')](_0x5b6713,squel[_0xb375('0xe')]()[_0xb375('0x32')](_0x5b6713)[_0xb375('0x11')](_0x4ec0ad)[_0xb375('0x13')]('('+_0x459df8['join'](',')+_0xb375('0x53'),squel[_0xb375('0xe')]()[_0xb375('0x32')](_0x459df8)[_0xb375('0x11')](_0xb375('0x33'))['where'](_0xb375('0x41'),_0x2966ac)[_0xb375('0x13')](_0xb375('0x54')))[_0xb375('0x13')](_0xb375('0x55'),squel[_0xb375('0xe')]()[_0xb375('0xf')](_0xb375('0x56'),_0xb375('0x57'))[_0xb375('0x11')](_0x4ec0ad)[_0xb375('0x58')](_0x459df8[_0xb375('0x36')](','))))[_0xb375('0x3c')]();}function handleStop(){logger[_0xb375('0x59')](_0xb375('0x5a'));stopped=!![];}function handleUncaughtException(_0x40379c){logger[_0xb375('0x5b')](_0x40379c['message']);process['exit'](0x1);}function handleError(_0xfd2ef6,_0x5c916a){stats[_0xb375('0x5c')][_0xb375('0x1b')]({'name':_0x5c916a['code'],'message':_0x5c916a[_0xb375('0x5d')],'row':_0xfd2ef6});}function handleQuery(_0x223e21){logger[_0xb375('0x59')](_0x223e21);return db[_0xb375('0x5e')][_0xb375('0x5f')](_0x223e21)['spread'](function(_0x106b0c){results[_0xb375('0x1b')](_0x106b0c);})[_0xb375('0x60')](function(_0x103811){logger['error'](_0x103811[_0xb375('0x5d')]);});}function updateTzCampaigns(_0x524dd5){return new Promise(function(_0x2a6b3,_0x14fcd2){var _0x42c6a4=squel[_0xb375('0xe')]()[_0xb375('0x32')]([_0xb375('0x61'),_0xb375('0x62')])[_0xb375('0x11')](_0xb375('0x63'))[_0xb375('0x36')](_0xb375('0x64'),null,_0xb375('0x65'))[_0xb375('0x13')](_0xb375('0x66')+_0x524dd5);db[_0xb375('0x5e')][_0xb375('0x5f')](_0x42c6a4['toString']())[_0xb375('0x67')](function(_0x2e0186){var _0xd2edf5=[];for(var _0x5d50c0=0x0;_0x5d50c0<_0x2e0186[_0xb375('0x1a')];_0x5d50c0++){_0xd2edf5['push'](getTimezoneData(_0x2e0186[_0x5d50c0],tmp_campaigns));}BPromise[_0xb375('0x1c')](_0xd2edf5)[_0xb375('0x19')](function(){_0x2a6b3({'val':0x1});});})[_0xb375('0x60')](function(_0x220cf5){logger[_0xb375('0x5b')](_0x220cf5['message']);_0x2a6b3({'val':0x0});});});}function updateTzVoiceQueues(_0x3461e0){return new Promise(function(_0x5ba07a,_0x55ebdf){var _0x395934=squel['select']()[_0xb375('0x32')]([_0xb375('0x68'),_0xb375('0x69')])['from']('voice_queues')['join']('voice_queues_has_cm_lists',null,_0xb375('0x6a'))[_0xb375('0x13')]('voice_queues_has_cm_lists.CmListId='+_0x3461e0);db['sequelize'][_0xb375('0x5f')](_0x395934[_0xb375('0x3c')]())['spread'](function(_0x5f2cef){var _0x3e0770=[];for(var _0x2daefa=0x0;_0x2daefa<_0x5f2cef[_0xb375('0x1a')];_0x2daefa++){_0x3e0770['push'](getTimezoneData(_0x5f2cef[_0x2daefa],tmp_voice_queues));}BPromise[_0xb375('0x1c')](_0x3e0770)[_0xb375('0x19')](function(){_0x5ba07a({'val':0x1});});})[_0xb375('0x60')](function(_0x588258){logger[_0xb375('0x5b')](_0x588258['message']);_0x5ba07a({'val':0x0});});});}function getTimezoneData(_0x34759a,_0x421d40){return new Promise(function(_0x2e7d8b,_0x31f286){var _0x170bea=shared[_0xb375('0x6b')];var _0x405732=_0x170bea[_0x34759a[_0xb375('0x6c')]];if(_[_0xb375('0x1e')](_0x405732)){_0x2e7d8b({'ret':0x1});}else{var _0x1288f9=_0x405732[_0xb375('0x6d')];var _0x2a33ca=squel[_0xb375('0x3d')]()[_0xb375('0x3e')](_0x421d40)[_0xb375('0x6e')]('id',_0x34759a['id'])[_0xb375('0x6e')]('offset',_0x1288f9)[_0xb375('0x6e')]('dialTimezone',_0x34759a['dialTimezone'])['toString']();return db[_0xb375('0x5e')][_0xb375('0x5f')](_0x2a33ca)[_0xb375('0x67')](function(_0x42f384){_0x2e7d8b({'ret':0x1});})[_0xb375('0x60')](function(_0x103a34){logger['error'](_0x103a34[_0xb375('0x5d')]);_0x31f286({'ret':0x1});});}});}function handleTZQuery(_0x4369d6){logger[_0xb375('0x59')](_0x4369d6);return db[_0xb375('0x5e')]['query'](_0x4369d6)['spread'](function(_0x20e77d){})[_0xb375('0x60')](function(_0x17e1cd){logger[_0xb375('0x5b')](_0x17e1cd[_0xb375('0x5d')]);});}function main(_0x425d4b,_0x162738,_0x1596e3,_0x2c42a6){logger[_0xb375('0x59')](_0xb375('0x6f'),_0x425d4b,JSON[_0xb375('0x70')](_0x162738));process[_0xb375('0x71')](_0xb375('0x72'));var _0x12880c=_0x162738['binding'];var _0x2c9768=_[_0xb375('0x73')](_0x12880c);var _0xb58142=_0x162738[_0xb375('0x74')];var _0x303fcf=path['join'](config[_0xb375('0x75')],_0xb375('0x76'),_0xb58142+'.csv');hasTZ=_['keys'](_0x12880c)[_0xb375('0x77')](_0xb375('0x6c'));var _0x21369f=_[_0xb375('0x50')](_0x12880c)[_0xb375('0x36')]();logger[_0xb375('0x59')](_0xb375('0x78'),_0x21369f);db['ContactItemType']['findAll']({'raw':!![],'attributes':['id',_0xb375('0x79')]})[_0xb375('0x19')](function(_0x5d67d6){for(var _0x22f3a2=0x0;_0x22f3a2<_0x5d67d6['length'];_0x22f3a2++){if(_0x5d67d6[_0x22f3a2][_0xb375('0x79')]in _0x12880c){contactItemTypes[_0xb375('0x1b')](_0x5d67d6[_0x22f3a2]);delete _0x2c9768[_0x5d67d6[_0x22f3a2][_0xb375('0x79')]];hasAdditionalPhones=!![];}for(var _0x26daba in _0x12880c){if(_0x5d67d6[_0x22f3a2][_0xb375('0x79')]+'_description'===_0x26daba){phoneDescriptions['push']({'itemTypeId':_0x5d67d6[_0x22f3a2]['id'],'description':_0x26daba});delete _0x2c9768[_0x26daba];}}}if(hasAdditionalPhones)_0x2c9768[_0xb375('0x18')]='';var _0x410e92=_[_0xb375('0x50')](_0x2c9768)[_0xb375('0x36')]();logger['info'](_0xb375('0x78'),_0x410e92);fs[_0xb375('0x7a')](_0x303fcf,_0x410e92+'\x0a');Papa[_0xb375('0x7b')](fs[_0xb375('0x7c')](_0x425d4b),{'header':!![],'skipEmptyLines':!![],'step':function(_0x24b0fe,_0x49f9b5){try{for(var _0x22477f=0x0,_0x2e3669=[];_0x22477f<_0x24b0fe['data'][_0xb375('0x1a')];_0x22477f++){stats[_0xb375('0x7d')]+=0x1;if(_0x24b0fe[_0xb375('0x5c')][_0x22477f]){handleError(_0x24b0fe['data'][_0x22477f],_0x24b0fe[_0xb375('0x5c')][_0x22477f]);}else{var _0x4447b2=[];var _0x39ddc6=[];var _0x3a4a46={};for(var _0xd7d757 in _0x12880c){let _0x305cd8=contactItemTypes['find'](_0xc324c0=>_0xc324c0[_0xb375('0x79')]===_0xd7d757);let _0x504e73=contactItemTypes[_0xb375('0x7e')](_0x10e4f7=>_0x10e4f7[_0xb375('0x79')]+_0xb375('0x7f')===_0xd7d757);if(_[_0xb375('0x1e')](_0x305cd8)&&_['isNil'](_0x504e73)){if(_0x12880c[_0xb375('0x80')](_0xd7d757)){if(_0x24b0fe[_0xb375('0x81')][_0x22477f][_0x12880c[_0xd7d757]]){var _0x275f0d=_[_0xb375('0x82')](_0x24b0fe[_0xb375('0x81')][_0x22477f][_0x12880c[_0xd7d757]][_0xb375('0x83')](/"/g,'\x27'));switch(_0xd7d757){case'scheduledat':var _0x3d84e6=moment(_0x275f0d,_0xb375('0xc'),!![]);if(_0x3d84e6[_0xb375('0x84')]()){_0x2e3669[_0xb375('0x1b')]('\x22'+_0x275f0d+'\x22');}else{_0x4447b2[_0xb375('0x1b')]('scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)');}break;case _0xb375('0x45'):var _0x3f6b31=parseInt(_0x275f0d);_0x275f0d=_[_0xb375('0x85')](_0x3f6b31)||_0x3f6b31<0x0||_0x3f6b31>0x4?_0x2c42a6?0x3:0x2:_0x3f6b31;_0x2e3669[_0xb375('0x1b')]('\x22'+_0x275f0d+'\x22');break;case _0xb375('0x31'):var _0x43b3e7=parseInt(_0x275f0d);if(_[_0xb375('0x86')](_0x43b3e7)&&_[_0xb375('0x77')](_0x1596e3,_0x43b3e7)){_0x2e3669[_0xb375('0x1b')]('\x22'+_0x43b3e7+'\x22');}else{_0x4447b2['push'](_0xb375('0x87'));}break;case'email':if(isEmail(_0x275f0d)){_0x2e3669[_0xb375('0x1b')]('\x22'+_0x275f0d+'\x22');}else{_0x4447b2[_0xb375('0x1b')]('email\x20wrong\x20format');}break;case _0xb375('0x88'):var _0x34ce76=moment(_0x275f0d,_0xb375('0x89'),!![]);if(_0x34ce76['isValid']()){_0x2e3669[_0xb375('0x1b')]('\x22'+_0x275f0d+'\x22');}else{_0x4447b2[_0xb375('0x1b')](_0xb375('0x8a'));}break;case _0xb375('0x6c'):var _0x5eda8d=shared[_0xb375('0x6b')];var _0x24fdcb=_0x5eda8d[_0x275f0d];if(!_['isNil'](_0x24fdcb)){var _0x435ee9=_0x24fdcb[_0xb375('0x6d')];_0x2e3669[_0xb375('0x1b')]('\x22'+_0x275f0d+'\x22');_0x2e3669['push']('\x22'+_0x435ee9+'\x22');}break;default:_0x2e3669[_0xb375('0x1b')]('\x22'+_0x275f0d+'\x22');}}else{switch(_0xd7d757){case _0xb375('0x8b'):case'phone':_0x4447b2[_0xb375('0x1b')](_0xd7d757+_0xb375('0x8c'));break;default:_0x2e3669[_0xb375('0x1b')]('\x22\x22');}}}}else{var _0x578a80='';if(!_[_0xb375('0x1e')](_0x305cd8)){if(!_0x3a4a46[_0xb375('0x80')](_0x305cd8['id'])){if(!_[_0xb375('0x1e')](_0x24b0fe[_0xb375('0x81')][_0x22477f][_0x12880c[_0xd7d757]])){var _0x275f0d=_[_0xb375('0x82')](_0x24b0fe['data'][_0x22477f][_0x12880c[_0xd7d757]]['replace'](/"/g,'\x27'));var _0x12650a=phoneDescriptions[_0xb375('0x7e')](_0x531d80=>_0x531d80[_0xb375('0x8d')]===_0x305cd8['id']);if(!_[_0xb375('0x1e')](_0x12650a)){var _0x4847f5=_['trim'](_0x24b0fe['data'][_0x22477f][_0x12880c[_0x12650a[_0xb375('0x8e')]]][_0xb375('0x83')](/"/g,'\x27'));if(!_[_0xb375('0x1e')](_0x4847f5))_0x275f0d=_0x275f0d+'§'+_0x4847f5;}if(_0x578a80=='')_0x578a80=_0x275f0d;else _0x578a80+='|'+_0x275f0d;}_0x39ddc6[_0xb375('0x1b')](_0x305cd8['id']+':'+_0x578a80);_0x3a4a46[_0x305cd8['id']]=0x1;}}}}if(hasAdditionalPhones){_0x2e3669[_0xb375('0x1b')]('\x22'+_0x39ddc6[_0xb375('0x36')](';')+'\x22');}if(_0x4447b2[_0xb375('0x1a')]){handleError(_0x24b0fe[_0xb375('0x81')][_0x22477f],{'code':_0xb375('0x8f'),'message':_0x4447b2[_0xb375('0x36')]()});}else{fs[_0xb375('0x90')](_0x303fcf,_0x2e3669[_0xb375('0x36')]()+'\x0a');}_0x2e3669=[];}if(!(stats[_0xb375('0x7d')]%0xc8)){socket[_0xb375('0x91')](_0xb375('0x92')+_0xb58142,stats);stats[_0xb375('0x5c')]=[];}}if(stopped){logger[_0xb375('0x59')](_0xb375('0x93'));_0x49f9b5['abort']();}}catch(_0x310baa){handleError(_0x24b0fe[_0xb375('0x81')][_0x22477f],{'code':_0xb375('0x94'),'message':_0x310baa[_0xb375('0x5d')]});logger[_0xb375('0x5b')](_0xb375('0x95'),_0x310baa[_0xb375('0x5d')]);}},'complete':function(){try{var _0xd779fa=[];var _0x35c76e=[];var _0x2ea274=_0xb375('0x33');if(_0x162738[_0xb375('0x96')]&&_0x162738[_0xb375('0x96')][_0xb375('0x1a')]){_0x2ea274=_0xb375('0x97')+_0xb58142;_0xd779fa['push'](_0xb375('0x98')+_0x2ea274+'\x20LIKE\x20cm_contacts;');}tmp_campaigns=_0xb375('0x99')+_0xb58142;tmp_voice_queues=_0xb375('0x9a')+_0xb58142;_0x35c76e['push'](_0xb375('0x98')+tmp_campaigns+_0xb375('0x9b'));_0x35c76e['push'](_0xb375('0x98')+tmp_voice_queues+_0xb375('0x9b'));BPromise[_0xb375('0x9c')](_0x35c76e,handleTZQuery)[_0xb375('0x19')](function(_0x15bd42){updateTzCampaigns(_0x162738[_0xb375('0x2f')])['then'](function(_0x279e4c){updateTzVoiceQueues(_0x162738[_0xb375('0x2f')])[_0xb375('0x19')](function(_0x17e622){if(hasTZ)_0x410e92=_0x410e92[_0xb375('0x83')](_0xb375('0x6c'),_0xb375('0x9d'));var _0x50fc40=util[_0xb375('0x9e')](_0xb375('0x9f'),_0x303fcf,_0x2ea274,_0x410e92,_0x162738[_0xb375('0x2f')],_0x162738['CompanyId']||null,NOW,NOW);if(_[_0xb375('0x1e')](_0x12880c[_0xb375('0x2d')])){_0x50fc40+=',\x20scheduledAt\x20=\x20NOW()';}_0xd779fa[_0xb375('0x1b')](_0x50fc40);if(_0x162738[_0xb375('0x96')]&&_0x162738[_0xb375('0x96')][_0xb375('0x1a')]){_0xd779fa[_0xb375('0x1b')](insertCmContact(_0x162738[_0xb375('0x2f')],_0x2ea274,_0x162738['duplicates'],_0x12880c));_0xd779fa[_0xb375('0x1b')]('DROP\x20TABLE\x20'+_0x2ea274+';');}BPromise[_0xb375('0x9c')](_0xd779fa,handleQuery)[_0xb375('0x19')](function(_0x2f028e){BPromise['all']([handleAdditionalPhones()])[_0xb375('0x19')](function(){_0xd779fa=[];for(var _0x38f730=0x0;_0x38f730<promisesAdditionalPhones[_0xb375('0x1a')];_0x38f730++){if(promisesAdditionalPhones[_0x38f730]['phone']!='§'){_0xd779fa[_0xb375('0x1b')](createAdditionalPhone(promisesAdditionalPhones[_0x38f730][_0xb375('0xa0')],promisesAdditionalPhones[_0x38f730][_0xb375('0xa1')],promisesAdditionalPhones[_0x38f730][_0xb375('0x10')],promisesAdditionalPhones[_0x38f730]['orderBy']));}}BPromise[_0xb375('0x1c')](_0xd779fa)[_0xb375('0x19')](function(){_0xd779fa=[];if(hasTZ){_0xd779fa['push'](insertTzCmHopper(_0x162738[_0xb375('0x2f')],'voice_queues_has_cm_lists',_0xb375('0xa2'),_0xb375('0xa3'),_0x2c42a6,tmp_voice_queues));_0xd779fa['push'](insertTzCmHopperBlack(_0x162738[_0xb375('0x2f')],_0xb375('0xa4'),_0xb375('0xa2'),_0xb375('0xa3')));_0xd779fa['push'](insertTzCmHopper(_0x162738[_0xb375('0x2f')],_0xb375('0x64'),'campaigns',_0xb375('0xa5'),_0x2c42a6,tmp_campaigns));_0xd779fa[_0xb375('0x1b')](insertTzCmHopperBlack(_0x162738['ListId'],_0xb375('0xa6'),'campaigns',_0xb375('0xa5')));_0xd779fa[_0xb375('0x1b')](insertCmHopperAdditionalPhones(_0x162738[_0xb375('0x2f')]));}else{_0xd779fa[_0xb375('0x1b')](insertCmHopper(_0x162738[_0xb375('0x2f')],_0xb375('0xa7'),_0xb375('0xa2'),_0xb375('0xa3'),_0x2c42a6));_0xd779fa[_0xb375('0x1b')](insertCmHopperBlack(_0x162738['ListId'],'voice_queues_has_cm_blacklists',_0xb375('0xa2'),_0xb375('0xa3')));_0xd779fa[_0xb375('0x1b')](insertCmHopper(_0x162738['ListId'],_0xb375('0x64'),_0xb375('0x63'),_0xb375('0xa5'),_0x2c42a6));_0xd779fa[_0xb375('0x1b')](insertCmHopperBlack(_0x162738[_0xb375('0x2f')],_0xb375('0xa6'),_0xb375('0x63'),_0xb375('0xa5')));_0xd779fa['push'](insertCmHopperAdditionalPhones(_0x162738['ListId']));}_0xd779fa[_0xb375('0x1b')](_0xb375('0xa8')+tmp_campaigns+';');_0xd779fa[_0xb375('0x1b')](_0xb375('0xa8')+tmp_voice_queues+';');BPromise[_0xb375('0x9c')](_0xd779fa,handleQuery)['then'](function(_0x566af0){stats[_0xb375('0xa9')]=!![];stats[_0xb375('0xaa')]=_0x162738[_0xb375('0x96')]&&_0x162738[_0xb375('0x96')]['length']?results[0x2]['affectedRows']:results[0x0]['affectedRows'];socket[_0xb375('0x91')](_0xb375('0x92')+_0xb58142,stats);fs[_0xb375('0xab')](_0x425d4b);fs[_0xb375('0xab')](_0x303fcf);process[_0xb375('0xac')](0x0);})[_0xb375('0x60')](function(_0x5cca12){logger[_0xb375('0x5b')](_0x5cca12['message']);process[_0xb375('0xac')](0x1);});});});})[_0xb375('0x60')](function(_0x5e2c2a){logger[_0xb375('0x5b')](_0x5e2c2a[_0xb375('0x5d')]);process[_0xb375('0xac')](0x1);});});});});}catch(_0x18d1c3){logger[_0xb375('0x5b')](_0xb375('0xad'),_0x18d1c3[_0xb375('0x5d')]);process[_0xb375('0xac')](0x1);}},'error':function(_0xed7628,_0x438599,_0x353076,_0x440339){throw new Error(_0x440339);}});});}function validate(){if(process[_0xb375('0xae')]&&process[_0xb375('0xae')]['length']<0x4){throw new Error(_0xb375('0xaf'));}var _0x321d51=path[_0xb375('0x36')](config[_0xb375('0x75')],_0xb375('0x76'),process[_0xb375('0xae')][0x2]);if(!fs['existsSync'](_0x321d51)){throw new Error(_0xb375('0xb0'));}var _0x52a195={};try{_0x52a195=JSON[_0xb375('0x7b')](process['argv'][0x3]);if(!_0x52a195['binding']){throw new Error(_0xb375('0xb1'));}if(!_0x52a195[_0xb375('0xb2')][_0xb375('0x10')]){throw new Error('phone\x20is\x20mandatory');}if(!_0x52a195['binding'][_0xb375('0x8b')]){throw new Error('firstName\x20is\x20mandatory');}var _0x6e1d86=0x0;if(_0x52a195[_0xb375('0xb2')][_0xb375('0x31')]){_0x6e1d86=0x1;}if(!_0x52a195['ListId']){throw new Error(_0xb375('0xb3'));}}catch(_0x4d5a45){throw new Error(_0xb375('0xb4'));}var _0x1ecd81=[];try{_0x1ecd81=_[_0xb375('0xb5')](JSON[_0xb375('0x7b')](process[_0xb375('0xae')][0x4]),'id');}catch(_0x4f09cf){logger[_0xb375('0x59')]('No\x20agent\x20available');}main(_0x321d51,_0x52a195,_0x1ecd81,_0x6e1d86);}validate();process['on'](_0xb375('0xb6'),handleStop);process['on'](_0xb375('0xb7'),handleUncaughtException);
\ No newline at end of file