Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / components / import / cm / csv2.js
index 7d9ef3c..11e6722 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x10cf=['cm_contacts.createdAt','cm_contacts.UserId','insert','into','cm_hopper','fromQuery','scheduledat','ContactId','ListId','createdAt','priority','recallme','select','fields','cm_contacts.ListId\x20=\x20','.CmListId','.CmListId\x20=\x20?','cm_contacts.phone\x20NOT\x20IN\x20(?)','\x22onlyIfOpen\x22','\x22always\x22','toString','updatedAt','cm_contacts','cm_contacts.createdAt\x20=\x20?','cm_hopper_black','ListId\x20=\x20?','\x20=\x20?','keys',')\x20NOT\x20IN\x20?','id\x20IN\x20?','field','MIN(id)','min_id','info','error','message','exit','errors','code','sequelize','spread','push','catch','binding','socket_timestamp','header','writeFileSync','length','rows','data','trim','replace','isValid','scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)','agent\x20not\x20exists','email\x20wrong\x20format','dateOfBirth','YYYY-MM-DD','dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)','firstName','\x20not\x20specified','SystemRow','appendFileSync','contact:import:','Abort\x20parser','abort','SystemError','step','duplicates','cm_contacts_','\x20LIKE\x20cm_contacts;','CompanyId',',\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','then','finish','affectedRows','unlink','complete','argv','root','server/files/tmp','existsSync','file\x20doesn\x27t\x20exists','parse','binding\x20doesn\x27t\x20exists','phone\x20is\x20mandatory','firstName\x20is\x20mandatory','UserId','body\x20id\x20mandatory','map','No\x20agent\x20available','SIGINT','path','lodash','papaparse','util','bluebird','moment','squel','ioredis','../../../mysqldb','import','redis','defaults','localhost','format','YYYY-MM-DD\x20HH:mm:ss','test','phone','from','join','.id\x20=\x20','where','cm_contacts.phone','cm_contacts.scheduledat','cm_contacts.id','cm_contacts.ListId'];(function(_0x263d34,_0x3dd748){var _0x645805=function(_0x1496a6){while(--_0x1496a6){_0x263d34['push'](_0x263d34['shift']());}};_0x645805(++_0x3dd748);}(_0x10cf,0xe3));var _0xf10c=function(_0x40f5be,_0x579a81){_0x40f5be=_0x40f5be-0x0;var _0x30d587=_0x10cf[_0x40f5be];return _0x30d587;};'use strict';var fs=require('fs');var path=require(_0xf10c('0x0'));var _=require(_0xf10c('0x1'));var Papa=require(_0xf10c('0x2'));var util=require(_0xf10c('0x3'));var BPromise=require(_0xf10c('0x4'));var moment=require(_0xf10c('0x5'));var squel=require(_0xf10c('0x6'));var Redis=require(_0xf10c('0x7'));var db=require(_0xf10c('0x8'))['db'];var config=require('../../../config/environment');var logger=require('../../../config/logger')(_0xf10c('0x9'));config[_0xf10c('0xa')]=_[_0xf10c('0xb')](config['redis'],{'host':_0xf10c('0xc'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xf10c('0xa')]));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var stopped=![];var NOW=moment()[_0xf10c('0xd')](_0xf10c('0xe'));function isEmail(_0x5a1d8c){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))*$/[_0xf10c('0xf')](_0x5a1d8c);}function selectNotIn(_0x16530b,_0xf14791,_0x148d07,_0x1baa07,_0x50aeac){return squel['select']()['field'](_0xf10c('0x10'))[_0xf10c('0x11')](_0x1baa07)[_0xf10c('0x12')](_0xf14791,null,_0xf14791+_0xf10c('0x13')+_0x1baa07+'.'+_0x148d07)[_0xf10c('0x14')](_0x1baa07+'.'+_0x148d07+'\x20=\x20'+_0x16530b+'.'+_0x148d07)[_0xf10c('0x14')](_0xf14791+'.dialCheckDuplicateType\x20IN\x20('+_0x50aeac[_0xf10c('0x12')]()+')');}function insertCmHopper(_0x681987,_0x3abcfc,_0x49d01e,_0x46cdce,_0x1940ea){var _0x5378ca=[_0xf10c('0x15'),_0xf10c('0x16'),_0xf10c('0x17'),_0xf10c('0x18'),_0x3abcfc+'.'+_0x46cdce,_0xf10c('0x19'),'cm_contacts.updatedAt','cm_contacts.priority',_0xf10c('0x1a'),'\x22'+_0x1940ea+'\x22'];return squel[_0xf10c('0x1b')]()[_0xf10c('0x1c')](_0xf10c('0x1d'))[_0xf10c('0x1e')]([_0xf10c('0x10'),_0xf10c('0x1f'),_0xf10c('0x20'),_0xf10c('0x21'),_0x46cdce,_0xf10c('0x22'),'updatedAt',_0xf10c('0x23'),'UserId',_0xf10c('0x24')],squel[_0xf10c('0x25')]()[_0xf10c('0x26')](_0x5378ca)[_0xf10c('0x11')](_0x3abcfc)[_0xf10c('0x12')]('cm_contacts',null,_0xf10c('0x27')+_0x3abcfc+_0xf10c('0x28'))[_0xf10c('0x12')](_0x49d01e,null,_0x49d01e+_0xf10c('0x13')+_0x3abcfc+'.'+_0x46cdce)['where'](_0x3abcfc+_0xf10c('0x29'),_0x681987)[_0xf10c('0x14')]('cm_contacts.createdAt\x20=\x20?',NOW)['where'](_0xf10c('0x2a'),selectNotIn(_0x3abcfc,_0x49d01e,_0x46cdce,_0xf10c('0x1d'),['\x22always\x22',_0xf10c('0x2b')]))['where'](_0xf10c('0x2a'),selectNotIn(_0x3abcfc,_0x49d01e,_0x46cdce,_0xf10c('0x1d'),[_0xf10c('0x2c')])))[_0xf10c('0x2d')]();}function insertCmHopperBlack(_0x131009,_0x2114eb,_0x154d8a,_0x32fdda){var _0x32427a=[_0xf10c('0x15'),_0xf10c('0x17'),_0xf10c('0x18'),_0x2114eb+'.'+_0x32fdda,_0xf10c('0x19'),'cm_contacts.updatedAt'];return squel[_0xf10c('0x1b')]()['into']('cm_hopper_black')[_0xf10c('0x1e')]([_0xf10c('0x10'),_0xf10c('0x20'),_0xf10c('0x21'),_0x32fdda,_0xf10c('0x22'),_0xf10c('0x2e')],squel[_0xf10c('0x25')]()[_0xf10c('0x26')](_0x32427a)['from'](_0x2114eb)[_0xf10c('0x12')](_0xf10c('0x2f'),null,'cm_contacts.ListId\x20=\x20'+_0x2114eb+_0xf10c('0x28'))['join'](_0x154d8a,null,_0x154d8a+_0xf10c('0x13')+_0x2114eb+'.'+_0x32fdda)[_0xf10c('0x14')](_0x2114eb+_0xf10c('0x29'),_0x131009)[_0xf10c('0x14')](_0xf10c('0x30'),NOW)[_0xf10c('0x14')](_0xf10c('0x2a'),squel['select']()['field'](_0xf10c('0x10'))[_0xf10c('0x11')](_0xf10c('0x31'))['where'](_0xf10c('0x32'),_0x131009)[_0xf10c('0x14')](_0x32fdda+_0xf10c('0x33'),_0x2114eb+'.'+_0x32fdda)))[_0xf10c('0x2d')]();}function insertCmContact(_0x1d5364,_0x590f4a,_0x44cf23,_0xe5b1b8){var _0x2e6dd7=_['concat'](_[_0xf10c('0x34')](_0xe5b1b8),[_0xf10c('0x21'),'CompanyId','createdAt',_0xf10c('0x2e')]);return squel[_0xf10c('0x1b')]()[_0xf10c('0x1c')](_0xf10c('0x2f'))[_0xf10c('0x1e')](_0x2e6dd7,squel[_0xf10c('0x25')]()[_0xf10c('0x26')](_0x2e6dd7)[_0xf10c('0x11')](_0x590f4a)[_0xf10c('0x14')]('('+_0x44cf23['join'](',')+_0xf10c('0x35'),squel[_0xf10c('0x25')]()[_0xf10c('0x26')](_0x44cf23)[_0xf10c('0x11')](_0xf10c('0x2f'))[_0xf10c('0x14')](_0xf10c('0x32'),_0x1d5364)['where']('deletedAt\x20IS\x20NULL'))[_0xf10c('0x14')](_0xf10c('0x36'),squel['select']()[_0xf10c('0x37')](_0xf10c('0x38'),_0xf10c('0x39'))[_0xf10c('0x11')](_0x590f4a)['group'](_0x44cf23[_0xf10c('0x12')](','))))[_0xf10c('0x2d')]();}function handleStop(){logger[_0xf10c('0x3a')]('Received\x20SIGINT');stopped=!![];}function handleUncaughtException(_0x4aa7cf){logger[_0xf10c('0x3b')](_0x4aa7cf[_0xf10c('0x3c')]);process[_0xf10c('0x3d')](0x1);}function handleError(_0x5e04a6,_0x3ec3e8){stats[_0xf10c('0x3e')]['push']({'name':_0x3ec3e8[_0xf10c('0x3f')],'message':_0x3ec3e8[_0xf10c('0x3c')],'row':_0x5e04a6});}function handleQuery(_0x3bb8b9){logger[_0xf10c('0x3a')](_0x3bb8b9);return db[_0xf10c('0x40')]['query'](_0x3bb8b9)[_0xf10c('0x41')](function(_0x51c07d){results[_0xf10c('0x42')](_0x51c07d);})[_0xf10c('0x43')](function(_0x31dcd3){logger[_0xf10c('0x3b')](_0x31dcd3[_0xf10c('0x3c')]);});}function main(_0x3426dd,_0x5dcff5,_0xb43428,_0x7e3ced){logger[_0xf10c('0x3a')]('main',_0x3426dd,JSON['stringify'](_0x5dcff5));process['send']('start');var _0x56d292=_0x5dcff5[_0xf10c('0x44')];var _0x23b85d=_0x5dcff5[_0xf10c('0x45')];var _0x2aa9b8=path[_0xf10c('0x12')](config['root'],'server/files/tmp',_0x23b85d+'.csv');var _0x575ef9=_[_0xf10c('0x34')](_0x56d292)[_0xf10c('0x12')]();logger[_0xf10c('0x3a')](_0xf10c('0x46'),_0x575ef9);fs[_0xf10c('0x47')](_0x2aa9b8,_0x575ef9+'\x0a');Papa['parse'](fs['createReadStream'](_0x3426dd),{'header':!![],'skipEmptyLines':!![],'step':function(_0x103369,_0x2cf84f){try{for(var _0xf28684=0x0,_0x1462eb=[];_0xf28684<_0x103369['data'][_0xf10c('0x48')];_0xf28684++){stats[_0xf10c('0x49')]+=0x1;if(_0x103369[_0xf10c('0x3e')][_0xf28684]){handleError(_0x103369[_0xf10c('0x4a')][_0xf28684],_0x103369[_0xf10c('0x3e')][_0xf28684]);}else{var _0x5c73f1=[];for(var _0x598115 in _0x56d292){if(_0x56d292['hasOwnProperty'](_0x598115)){if(_0x103369[_0xf10c('0x4a')][_0xf28684][_0x56d292[_0x598115]]){var _0x4515c6=_[_0xf10c('0x4b')](_0x103369[_0xf10c('0x4a')][_0xf28684][_0x56d292[_0x598115]][_0xf10c('0x4c')](/"/g,'\x27'));switch(_0x598115){case _0xf10c('0x1f'):var _0x28b6a4=moment(_0x4515c6,_0xf10c('0xe'),!![]);if(_0x28b6a4[_0xf10c('0x4d')]()){_0x1462eb['push']('\x22'+_0x4515c6+'\x22');}else{_0x5c73f1[_0xf10c('0x42')](_0xf10c('0x4e'));}break;case _0xf10c('0x23'):var _0x333adb=parseInt(_0x4515c6);_0x4515c6=_['isNaN'](_0x333adb)||_0x333adb<0x0||_0x333adb>0x4?_0x7e3ced?0x3:0x2:_0x333adb;_0x1462eb[_0xf10c('0x42')]('\x22'+_0x4515c6+'\x22');break;case'UserId':var _0x504f85=parseInt(_0x4515c6);if(_['isNumber'](_0x504f85)&&_['includes'](_0xb43428,_0x504f85)){_0x1462eb[_0xf10c('0x42')]('\x22'+_0x504f85+'\x22');}else{_0x5c73f1[_0xf10c('0x42')](_0xf10c('0x4f'));}break;case'email':if(isEmail(_0x4515c6)){_0x1462eb['push']('\x22'+_0x4515c6+'\x22');}else{_0x5c73f1['push'](_0xf10c('0x50'));}break;case _0xf10c('0x51'):var _0x37b47a=moment(_0x4515c6,_0xf10c('0x52'),!![]);if(_0x37b47a[_0xf10c('0x4d')]()){_0x1462eb[_0xf10c('0x42')]('\x22'+_0x4515c6+'\x22');}else{_0x5c73f1['push'](_0xf10c('0x53'));}break;default:_0x1462eb[_0xf10c('0x42')]('\x22'+_0x4515c6+'\x22');}}else{switch(_0x598115){case _0xf10c('0x54'):case _0xf10c('0x10'):_0x5c73f1[_0xf10c('0x42')](_0x598115+_0xf10c('0x55'));break;default:_0x1462eb[_0xf10c('0x42')]('\x22\x22');}}}}if(_0x5c73f1[_0xf10c('0x48')]){handleError(_0x103369[_0xf10c('0x4a')][_0xf28684],{'code':_0xf10c('0x56'),'message':_0x5c73f1['join']()});}else{fs[_0xf10c('0x57')](_0x2aa9b8,_0x1462eb[_0xf10c('0x12')]()+'\x0a');}_0x1462eb=[];}if(!(stats[_0xf10c('0x49')]%0xc8)){socket['emit'](_0xf10c('0x58')+_0x23b85d,stats);stats[_0xf10c('0x3e')]=[];}}if(stopped){logger[_0xf10c('0x3a')](_0xf10c('0x59'));_0x2cf84f[_0xf10c('0x5a')]();}}catch(_0x26e896){handleError(_0x103369[_0xf10c('0x4a')][_0xf28684],{'code':_0xf10c('0x5b'),'message':_0x26e896[_0xf10c('0x3c')]});logger['error'](_0xf10c('0x5c'),_0x26e896[_0xf10c('0x3c')]);}},'complete':function(){try{var _0x46c1ef=[];var _0x4943f9=_0xf10c('0x2f');if(_0x5dcff5[_0xf10c('0x5d')]&&_0x5dcff5[_0xf10c('0x5d')][_0xf10c('0x48')]){_0x4943f9=_0xf10c('0x5e')+_0x23b85d;_0x46c1ef[_0xf10c('0x42')]('CREATE\x20TABLE\x20'+_0x4943f9+_0xf10c('0x5f'));}var _0x18903e=util[_0xf10c('0xd')]('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',_0x2aa9b8,_0x4943f9,_0x575ef9,_0x5dcff5['ListId'],_0x5dcff5[_0xf10c('0x60')]||null,NOW,NOW);if(_['isNil'](_0x56d292[_0xf10c('0x1f')])){_0x18903e+=_0xf10c('0x61');}_0x46c1ef['push'](_0x18903e);if(_0x5dcff5[_0xf10c('0x5d')]&&_0x5dcff5[_0xf10c('0x5d')][_0xf10c('0x48')]){_0x46c1ef[_0xf10c('0x42')](insertCmContact(_0x5dcff5[_0xf10c('0x21')],_0x4943f9,_0x5dcff5['duplicates'],_0x56d292));_0x46c1ef['push'](_0xf10c('0x62')+_0x4943f9+';');}_0x46c1ef[_0xf10c('0x42')](insertCmHopper(_0x5dcff5[_0xf10c('0x21')],_0xf10c('0x63'),_0xf10c('0x64'),_0xf10c('0x65'),_0x7e3ced));_0x46c1ef[_0xf10c('0x42')](insertCmHopperBlack(_0x5dcff5['ListId'],_0xf10c('0x66'),'voice_queues',_0xf10c('0x65')));_0x46c1ef[_0xf10c('0x42')](insertCmHopper(_0x5dcff5[_0xf10c('0x21')],_0xf10c('0x67'),_0xf10c('0x68'),_0xf10c('0x69'),_0x7e3ced));_0x46c1ef[_0xf10c('0x42')](insertCmHopperBlack(_0x5dcff5[_0xf10c('0x21')],_0xf10c('0x6a'),'campaigns',_0xf10c('0x69')));BPromise['each'](_0x46c1ef,handleQuery)[_0xf10c('0x6b')](function(_0x26e072){stats[_0xf10c('0x6c')]=!![];stats[_0xf10c('0x6d')]=_0x5dcff5[_0xf10c('0x5d')]&&_0x5dcff5[_0xf10c('0x5d')][_0xf10c('0x48')]?results[0x2][_0xf10c('0x6d')]:results[0x0][_0xf10c('0x6d')];socket['emit'](_0xf10c('0x58')+_0x23b85d,stats);fs[_0xf10c('0x6e')](_0x3426dd);fs[_0xf10c('0x6e')](_0x2aa9b8);process[_0xf10c('0x3d')](0x0);})['catch'](function(_0x276d02){logger[_0xf10c('0x3b')](_0x276d02[_0xf10c('0x3c')]);process[_0xf10c('0x3d')](0x1);});}catch(_0x202a74){logger[_0xf10c('0x3b')](_0xf10c('0x6f'),_0x202a74[_0xf10c('0x3c')]);process[_0xf10c('0x3d')](0x1);}},'error':function(_0x17605f,_0x4667d5,_0x26ecdc,_0x4e254b){throw new Error(_0x4e254b);}});}function validate(){if(process[_0xf10c('0x70')]&&process['argv'][_0xf10c('0x48')]<0x4){throw new Error('arguments\x20<filename>\x20<parameters>\x20<agents>');}var _0x7bef1f=path[_0xf10c('0x12')](config[_0xf10c('0x71')],_0xf10c('0x72'),process[_0xf10c('0x70')][0x2]);if(!fs[_0xf10c('0x73')](_0x7bef1f)){throw new Error(_0xf10c('0x74'));}var _0x5ec824={};try{_0x5ec824=JSON[_0xf10c('0x75')](process[_0xf10c('0x70')][0x3]);if(!_0x5ec824[_0xf10c('0x44')]){throw new Error(_0xf10c('0x76'));}if(!_0x5ec824[_0xf10c('0x44')][_0xf10c('0x10')]){throw new Error(_0xf10c('0x77'));}if(!_0x5ec824['binding'][_0xf10c('0x54')]){throw new Error(_0xf10c('0x78'));}var _0x2e963b=0x0;if(_0x5ec824['binding'][_0xf10c('0x79')]){_0x2e963b=0x1;}if(!_0x5ec824[_0xf10c('0x21')]){throw new Error('ListId\x20is\x20mandatory');}}catch(_0x17acfc){throw new Error(_0xf10c('0x7a'));}var _0x1efeaf=[];try{_0x1efeaf=_[_0xf10c('0x7b')](JSON['parse'](process[_0xf10c('0x70')][0x4]),'id');}catch(_0x4a1a7d){logger['info'](_0xf10c('0x7c'));}main(_0x7bef1f,_0x5ec824,_0x1efeaf,_0x2e963b);}validate();process['on'](_0xf10c('0x7d'),handleStop);process['on']('uncaughtException',handleUncaughtException);
\ No newline at end of file
+var _0x99f7=['firstName','itemTypeId','description','SystemRow','appendFileSync','Abort\x20parser','SystemError','step','duplicates','cm_contacts_','CREATE\x20TABLE\x20','campaigns_','voice_queues_','(id\x20int,dialTimezone\x20varchar(255),offset\x20int);','each','dialTimezone,utcOffset','CompanyId',',\x20scheduledAt\x20=\x20NOW()','orderBy','voice_queues_has_cm_lists','voice_queues','VoiceQueueId','voice_queues_has_cm_blacklists','CampaignId','campaigns_has_cm_blacklists','DROP\x20TABLE\x20','finish','affectedRows','emit','contact:import:','unlink','complete','argv','arguments\x20<filename>\x20<parameters>\x20<agents>','server/files/tmp','existsSync','file\x20doesn\x27t\x20exists','parse','binding\x20doesn\x27t\x20exists','phone\x20is\x20mandatory','firstName\x20is\x20mandatory','ListId\x20is\x20mandatory','map','No\x20agent\x20available','SIGINT','lodash','moment','squel','ioredis','../../../config/environment','../../../config/environment/shared','../../../config/logger','import','redis','defaults','localhost','socket.io-emitter','format','YYYY-MM-DD\x20HH:mm:ss','select','field','phone','from','where','.dialCheckDuplicateType\x20IN\x20(','CmContact','findAll','AdditionalPhones','then','length','push','all','split','CmContactHasItem','findOne','update','updated','create','PHONE','inserted','cm_contacts.phone','cm_contacts.scheduledat','cm_contacts.id','cm_contacts.ListId','cm_contacts.createdAt','cm_contacts.priority','insert','into','cm_hopper','ContactId','ListId','createdAt','updatedAt','priority','UserId','recallme','cm_contacts','.CmListId','join','.id\x20=\x20','.CmListId\x20=\x20?','cm_contacts.createdAt\x20=\x20?','cm_contacts.phone\x20NOT\x20IN\x20(?)','\x22always\x22','\x22onlyIfOpen\x22','toString','cm_contacts.updatedAt','cm_hopper_black','fields','cm_contacts.ListId\x20=\x20','\x20=\x20','.offset-cm_contacts.utcOffset\x20minute)','cm_contacts.UserId','fromQuery','scheduledat','cm_hopper.id','cm_contact_has_items.item','cm_contact_has_items.createdAt','cm_hopper_additional_phones','CmHopperId','OrderBy','cm_contacts.id\x20=\x20cm_contact_has_items.CmContactId','cm_hopper.ListId\x20=\x20?','concat','keys','scheduledAt','ListId\x20=\x20?','id\x20IN\x20?','min_id','info','Received\x20SIGINT','exit','errors','sequelize','spread','catch','message','campaigns.id','campaigns.dialTimezone','campaigns','campaigns_has_cm_lists','campaigns.id\x20=\x20campaigns_has_cm_lists.CampaignId','error','voice_queues.id','voice_queues.id\x20=\x20voice_queues_has_cm_lists.VoiceQueueId','query','timezones','dialTimezone','utcOffset','set','offset','main','send','start','binding','clone','socket_timestamp','root','.csv','header','ContactItemType','name','_description','writeFileSync','createReadStream','rows','data','find','isNil','hasOwnProperty','trim','replace','isValid','scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)','isNumber','includes','agent\x20not\x20exists','email','email\x20wrong\x20format','YYYY-MM-DD'];(function(_0x2e08fe,_0x4f4b67){var _0xe83039=function(_0x3be780){while(--_0x3be780){_0x2e08fe['push'](_0x2e08fe['shift']());}};_0xe83039(++_0x4f4b67);}(_0x99f7,0xe1));var _0x799f=function(_0x186e1a,_0x59d2b8){_0x186e1a=_0x186e1a-0x0;var _0x1c2d5b=_0x99f7[_0x186e1a];return _0x1c2d5b;};'use strict';var fs=require('fs');var path=require('path');var _=require(_0x799f('0x0'));var Papa=require('papaparse');var util=require('util');var BPromise=require('bluebird');var moment=require(_0x799f('0x1'));var squel=require(_0x799f('0x2'));var Redis=require(_0x799f('0x3'));var db=require('../../../mysqldb')['db'];var config=require(_0x799f('0x4'));var shared=require(_0x799f('0x5'));var logger=require(_0x799f('0x6'))(_0x799f('0x7'));config[_0x799f('0x8')]=_[_0x799f('0x9')](config[_0x799f('0x8')],{'host':_0x799f('0xa'),'port':0x18eb});var socket=require(_0x799f('0xb'))(new Redis(config[_0x799f('0x8')]));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var promisesAdditionalPhones=[];var orderBy=0x0;var stopped=![];var NOW=moment()[_0x799f('0xc')](_0x799f('0xd'));var contactItemTypes=[];var phoneDescriptions=[];var hasAdditionalPhones=![];var tmp_voice_queues;var tmp_campaigns;var tzOffset=0x0;var hasTZ;var NOW=moment()[_0x799f('0xc')](_0x799f('0xd'));function isEmail(_0x1068e9){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))*$/['test'](_0x1068e9);}function selectNotIn(_0x527787,_0x1ba2ce,_0x322b30,_0x2159ef,_0x52e2d4){return squel[_0x799f('0xe')]()[_0x799f('0xf')](_0x799f('0x10'))[_0x799f('0x11')](_0x2159ef)['join'](_0x1ba2ce,null,_0x1ba2ce+'.id\x20=\x20'+_0x2159ef+'.'+_0x322b30)[_0x799f('0x12')](_0x2159ef+'.'+_0x322b30+'\x20=\x20'+_0x527787+'.'+_0x322b30)['where'](_0x1ba2ce+_0x799f('0x13')+_0x52e2d4['join']()+')');}function handleAdditionalPhones(){return new Promise(function(_0x2096ac,_0x39e0fc){promisesAdditionalPhones=[];return db[_0x799f('0x14')][_0x799f('0x15')]({'raw':!![],'attributes':['id',_0x799f('0x16')],'where':{'createdAt':NOW,'AdditionalPhones':{'$ne':null}}})[_0x799f('0x17')](function(_0x44efb7){if(_0x44efb7!==null){var _0x2df48c=[];for(var _0x146387=0x0;_0x146387<_0x44efb7[_0x799f('0x18')];_0x146387++){var _0x4ea6a7=_0x44efb7[_0x146387];_0x2df48c[_0x799f('0x19')](insertAdditionalPhones(_0x4ea6a7));}}Promise[_0x799f('0x1a')](_0x2df48c)[_0x799f('0x17')](function(){_0x2096ac({'val':0x1});});});});}function insertAdditionalPhones(_0x122697){return new Promise(function(_0x527659,_0x49c4de){var _0x5f2f01=_0x122697[_0x799f('0x16')];var _0x12308b=_0x5f2f01[_0x799f('0x1b')](';');var _0x2f3478=[];orderBy=0x0;for(var _0x3a8eda=0x0;_0x3a8eda<_0x12308b[_0x799f('0x18')];_0x3a8eda++){_0x2f3478[_0x799f('0x19')](splitAdditionalPhone(_0x122697['id'],_0x12308b[_0x3a8eda]));}Promise[_0x799f('0x1a')](_0x2f3478)[_0x799f('0x17')](function(){_0x527659({'val':_0x12308b[_0x799f('0x18')]});});});}function splitAdditionalPhone(_0x418968,_0x79115c){return new Promise(function(_0x4073aa,_0xb86804){var _0x5066ce=_0x79115c[_0x799f('0x1b')](':');var _0x4cf246=_0x5066ce[0x0];var _0x96fb1d=_0x5066ce[0x1];if(!_['isNil'](_0x96fb1d)){var _0x41a3ea=_0x96fb1d[_0x799f('0x1b')]('|');var _0x3e2e7a=[];for(var _0x4e9b1b=0x0;_0x4e9b1b<_0x41a3ea[_0x799f('0x18')];_0x4e9b1b++){if(_0x41a3ea[_0x4e9b1b]!==''){var _0x522772=_['filter'](promisesAdditionalPhones,{'contactId':_0x418968,'phone':_0x41a3ea[_0x4e9b1b]});if(_0x522772['length']==0x0){orderBy++;promisesAdditionalPhones[_0x799f('0x19')]({'contactId':_0x418968,'contactTypeId':_0x4cf246,'phone':_0x41a3ea[_0x4e9b1b],'orderBy':orderBy});}}}_0x4073aa({'ok':0x1});}else _0x4073aa({'res':0x0});});}function createAdditionalPhone(_0x36983a,_0x4d5629,_0x296e85,_0x3361dc){var _0x5ccbcf='';var _0x3b04ed='';var _0x1638e9=_0x296e85[_0x799f('0x1b')]('§');_0x5ccbcf=_0x1638e9[0x0];if(_0x1638e9[_0x799f('0x18')]==0x2)_0x3b04ed=_0x1638e9[0x1];return new Promise(function(_0x1df4e5,_0x5c956f){return db[_0x799f('0x1c')][_0x799f('0x1d')]({'where':{'CmContactId':_0x36983a,'item':_0x5ccbcf}})['then'](function(_0x467a52){if(_0x467a52){return db[_0x799f('0x1c')][_0x799f('0x1e')]({'ItemTypeId':_0x4d5629,'description':_0x3b04ed,'OrderBy':_0x3361dc},{'where':{'CmContactId':_0x36983a,'item':_0x5ccbcf}})[_0x799f('0x17')](function(_0x431d91){_0x1df4e5({'res':_0x799f('0x1f')});});}else{return db[_0x799f('0x1c')][_0x799f('0x20')]({'CmContactId':_0x36983a,'item':_0x5ccbcf,'description':_0x3b04ed,'ItemTypeId':_0x4d5629,'OrderBy':_0x3361dc,'ItemClass':_0x799f('0x21')})[_0x799f('0x17')](function(_0x205e1c){_0x1df4e5({'res':_0x799f('0x22')});});}});});}function insertCmHopper(_0x40ea8b,_0x57b18b,_0x3f7ebd,_0x597de8,_0x297b04){var _0x39480e=[_0x799f('0x23'),_0x799f('0x24'),_0x799f('0x25'),_0x799f('0x26'),_0x57b18b+'.'+_0x597de8,_0x799f('0x27'),'cm_contacts.updatedAt',_0x799f('0x28'),'cm_contacts.UserId','\x22'+_0x297b04+'\x22'];return squel[_0x799f('0x29')]()[_0x799f('0x2a')](_0x799f('0x2b'))['fromQuery']([_0x799f('0x10'),'scheduledat',_0x799f('0x2c'),_0x799f('0x2d'),_0x597de8,_0x799f('0x2e'),_0x799f('0x2f'),_0x799f('0x30'),_0x799f('0x31'),_0x799f('0x32')],squel[_0x799f('0xe')]()['fields'](_0x39480e)[_0x799f('0x11')](_0x57b18b)['join'](_0x799f('0x33'),null,'cm_contacts.ListId\x20=\x20'+_0x57b18b+_0x799f('0x34'))[_0x799f('0x35')](_0x3f7ebd,null,_0x3f7ebd+_0x799f('0x36')+_0x57b18b+'.'+_0x597de8)['where'](_0x57b18b+_0x799f('0x37'),_0x40ea8b)[_0x799f('0x12')](_0x799f('0x38'),NOW)[_0x799f('0x12')](_0x799f('0x39'),selectNotIn(_0x57b18b,_0x3f7ebd,_0x597de8,_0x799f('0x2b'),[_0x799f('0x3a'),_0x799f('0x3b')]))[_0x799f('0x12')](_0x799f('0x39'),selectNotIn(_0x57b18b,_0x3f7ebd,_0x597de8,'cm_hopper',['\x22always\x22'])))[_0x799f('0x3c')]();}function insertCmHopperBlack(_0x552980,_0x52eaeb,_0x464230,_0x57c4b4){var _0x42ce7a=[_0x799f('0x23'),_0x799f('0x25'),_0x799f('0x26'),_0x52eaeb+'.'+_0x57c4b4,_0x799f('0x27'),_0x799f('0x3d')];return squel['insert']()[_0x799f('0x2a')](_0x799f('0x3e'))['fromQuery']([_0x799f('0x10'),_0x799f('0x2c'),_0x799f('0x2d'),_0x57c4b4,_0x799f('0x2e'),_0x799f('0x2f')],squel[_0x799f('0xe')]()[_0x799f('0x3f')](_0x42ce7a)[_0x799f('0x11')](_0x52eaeb)[_0x799f('0x35')]('cm_contacts',null,_0x799f('0x40')+_0x52eaeb+_0x799f('0x34'))[_0x799f('0x35')](_0x464230,null,_0x464230+'.id\x20=\x20'+_0x52eaeb+'.'+_0x57c4b4)[_0x799f('0x12')](_0x52eaeb+_0x799f('0x37'),_0x552980)[_0x799f('0x12')](_0x799f('0x38'),NOW)[_0x799f('0x12')](_0x799f('0x39'),squel[_0x799f('0xe')]()['field'](_0x799f('0x10'))[_0x799f('0x11')]('cm_hopper_black')[_0x799f('0x12')]('ListId\x20=\x20?',_0x552980)[_0x799f('0x12')](_0x57c4b4+_0x799f('0x41')+_0x52eaeb+'.'+_0x57c4b4)))[_0x799f('0x3c')]();}function insertTzCmHopper(_0x20320c,_0x1aa409,_0x3abf60,_0x19b34c,_0x253d50,_0x2acb18){var _0x437341=[_0x799f('0x23'),'date_add(cm_contacts.scheduledat,interval\x20'+_0x2acb18+_0x799f('0x42'),'cm_contacts.id','cm_contacts.ListId',_0x1aa409+'.'+_0x19b34c,_0x799f('0x27'),_0x799f('0x3d'),_0x799f('0x28'),_0x799f('0x43'),'\x22'+_0x253d50+'\x22'];var _0x11ddf0=squel['insert']()[_0x799f('0x2a')](_0x799f('0x2b'))[_0x799f('0x44')]([_0x799f('0x10'),_0x799f('0x45'),'ContactId',_0x799f('0x2d'),_0x19b34c,_0x799f('0x2e'),_0x799f('0x2f'),_0x799f('0x30'),_0x799f('0x31'),_0x799f('0x32')],squel[_0x799f('0xe')]()['fields'](_0x437341)[_0x799f('0x11')](_0x1aa409)[_0x799f('0x35')]('cm_contacts',null,_0x799f('0x40')+_0x1aa409+_0x799f('0x34'))[_0x799f('0x35')](_0x3abf60,null,_0x3abf60+_0x799f('0x36')+_0x1aa409+'.'+_0x19b34c)[_0x799f('0x35')](_0x2acb18,null,_0x2acb18+_0x799f('0x36')+_0x1aa409+'.'+_0x19b34c)[_0x799f('0x12')](_0x1aa409+_0x799f('0x37'),_0x20320c)[_0x799f('0x12')](_0x799f('0x38'),NOW)['where'](_0x799f('0x39'),selectNotIn(_0x1aa409,_0x3abf60,_0x19b34c,_0x799f('0x2b'),[_0x799f('0x3a'),_0x799f('0x3b')]))[_0x799f('0x12')](_0x799f('0x39'),selectNotIn(_0x1aa409,_0x3abf60,_0x19b34c,_0x799f('0x2b'),[_0x799f('0x3a')])))[_0x799f('0x3c')]();return _0x11ddf0;}function insertTzCmHopperBlack(_0x65b997,_0x2dbf66,_0x460fa6,_0x31e127){var _0x1938c5=[_0x799f('0x23'),_0x799f('0x25'),_0x799f('0x26'),_0x2dbf66+'.'+_0x31e127,_0x799f('0x27'),'cm_contacts.updatedAt'];return squel['insert']()['into'](_0x799f('0x3e'))[_0x799f('0x44')]([_0x799f('0x10'),_0x799f('0x2c'),'ListId',_0x31e127,_0x799f('0x2e'),_0x799f('0x2f')],squel['select']()[_0x799f('0x3f')](_0x1938c5)['from'](_0x2dbf66)['join']('cm_contacts',null,_0x799f('0x40')+_0x2dbf66+_0x799f('0x34'))[_0x799f('0x35')](_0x460fa6,null,_0x460fa6+_0x799f('0x36')+_0x2dbf66+'.'+_0x31e127)[_0x799f('0x12')](_0x2dbf66+_0x799f('0x37'),_0x65b997)[_0x799f('0x12')](_0x799f('0x38'),NOW)[_0x799f('0x12')]('cm_contacts.phone\x20NOT\x20IN\x20(?)',squel[_0x799f('0xe')]()[_0x799f('0xf')]('phone')[_0x799f('0x11')](_0x799f('0x3e'))['where']('ListId\x20=\x20?',_0x65b997)['where'](_0x31e127+_0x799f('0x41')+_0x2dbf66+'.'+_0x31e127)))['toString']();}function insertCmHopperAdditionalPhones(_0x36fb4e){var _0x474356=[_0x799f('0x46'),_0x799f('0x47'),'cm_contact_has_items.OrderBy',_0x799f('0x48'),'cm_contact_has_items.updatedAt'];return squel[_0x799f('0x29')]()['into'](_0x799f('0x49'))[_0x799f('0x44')]([_0x799f('0x4a'),'phone',_0x799f('0x4b'),'createdAt','updatedAt'],squel[_0x799f('0xe')]()[_0x799f('0x3f')](_0x474356)['from'](_0x799f('0x2b'))['join'](_0x799f('0x33'),null,'cm_contacts.id\x20=\x20cm_hopper.ContactId')[_0x799f('0x35')]('cm_contact_has_items',null,_0x799f('0x4c'))[_0x799f('0x12')](_0x799f('0x4d'),_0x36fb4e)[_0x799f('0x12')](_0x799f('0x38'),NOW))[_0x799f('0x3c')]();}function insertCmContact(_0x3ca082,_0x3a11cf,_0x56f33b,_0x13b1fd){var _0x3e7576=_[_0x799f('0x4e')](_[_0x799f('0x4f')](_0x13b1fd),[_0x799f('0x2d'),'CompanyId','createdAt',_0x799f('0x2f'),_0x799f('0x50')]);return squel['insert']()['into']('cm_contacts')[_0x799f('0x44')](_0x3e7576,squel[_0x799f('0xe')]()[_0x799f('0x3f')](_0x3e7576)['from'](_0x3a11cf)[_0x799f('0x12')]('('+_0x56f33b['join'](',')+')\x20NOT\x20IN\x20?',squel['select']()[_0x799f('0x3f')](_0x56f33b)['from'](_0x799f('0x33'))[_0x799f('0x12')](_0x799f('0x51'),_0x3ca082)[_0x799f('0x12')]('deletedAt\x20IS\x20NULL'))['where'](_0x799f('0x52'),squel['select']()['field']('MIN(id)',_0x799f('0x53'))[_0x799f('0x11')](_0x3a11cf)['group'](_0x56f33b[_0x799f('0x35')](','))))[_0x799f('0x3c')]();}function handleStop(){logger[_0x799f('0x54')](_0x799f('0x55'));stopped=!![];}function handleUncaughtException(_0x23943d){logger['error'](_0x23943d['message']);process[_0x799f('0x56')](0x1);}function handleError(_0x59d330,_0x58e8ad){stats[_0x799f('0x57')][_0x799f('0x19')]({'name':_0x58e8ad['code'],'message':_0x58e8ad['message'],'row':_0x59d330});}function handleQuery(_0x4a1a9c){logger['info'](_0x4a1a9c);return db[_0x799f('0x58')]['query'](_0x4a1a9c)[_0x799f('0x59')](function(_0x32291c){results[_0x799f('0x19')](_0x32291c);})[_0x799f('0x5a')](function(_0x1ba40b){logger['error'](_0x1ba40b[_0x799f('0x5b')]);});}function updateTzCampaigns(_0x151332){return new Promise(function(_0x319bfe,_0x2e40c6){var _0x44c63c=squel[_0x799f('0xe')]()[_0x799f('0x3f')]([_0x799f('0x5c'),_0x799f('0x5d')])[_0x799f('0x11')](_0x799f('0x5e'))[_0x799f('0x35')](_0x799f('0x5f'),null,_0x799f('0x60'))[_0x799f('0x12')]('campaigns_has_cm_lists.CmListId='+_0x151332);db[_0x799f('0x58')]['query'](_0x44c63c[_0x799f('0x3c')]())[_0x799f('0x59')](function(_0x4600b9){var _0x2ad685=[];for(var _0xd577a0=0x0;_0xd577a0<_0x4600b9['length'];_0xd577a0++){_0x2ad685['push'](getTimezoneData(_0x4600b9[_0xd577a0],tmp_campaigns));}BPromise[_0x799f('0x1a')](_0x2ad685)[_0x799f('0x17')](function(){_0x319bfe({'val':0x1});});})[_0x799f('0x5a')](function(_0x4adae8){logger[_0x799f('0x61')](_0x4adae8['message']);_0x319bfe({'val':0x0});});});}function updateTzVoiceQueues(_0x10bf22){return new Promise(function(_0x4b0563,_0x3f41d9){var _0x55579a=squel[_0x799f('0xe')]()[_0x799f('0x3f')]([_0x799f('0x62'),'voice_queues.dialTimezone'])[_0x799f('0x11')]('voice_queues')[_0x799f('0x35')]('voice_queues_has_cm_lists',null,_0x799f('0x63'))[_0x799f('0x12')]('voice_queues_has_cm_lists.CmListId='+_0x10bf22);db[_0x799f('0x58')][_0x799f('0x64')](_0x55579a[_0x799f('0x3c')]())['spread'](function(_0x2a7fbb){var _0xf2a5a4=[];for(var _0x517a70=0x0;_0x517a70<_0x2a7fbb[_0x799f('0x18')];_0x517a70++){_0xf2a5a4[_0x799f('0x19')](getTimezoneData(_0x2a7fbb[_0x517a70],tmp_voice_queues));}BPromise[_0x799f('0x1a')](_0xf2a5a4)['then'](function(){_0x4b0563({'val':0x1});});})['catch'](function(_0x5dbaae){logger['error'](_0x5dbaae[_0x799f('0x5b')]);_0x4b0563({'val':0x0});});});}function getTimezoneData(_0x418b31,_0x5bd62c){return new Promise(function(_0x4d54aa,_0x2a88dc){var _0x391544=shared[_0x799f('0x65')];var _0xb93c7d=_0x391544[_0x418b31[_0x799f('0x66')]];if(_['isNil'](_0xb93c7d)){_0x4d54aa({'ret':0x1});}else{var _0x487162=_0xb93c7d[_0x799f('0x67')];var _0x539ce8=squel[_0x799f('0x29')]()[_0x799f('0x2a')](_0x5bd62c)[_0x799f('0x68')]('id',_0x418b31['id'])[_0x799f('0x68')](_0x799f('0x69'),_0x487162)['set'](_0x799f('0x66'),_0x418b31[_0x799f('0x66')])[_0x799f('0x3c')]();return db[_0x799f('0x58')]['query'](_0x539ce8)[_0x799f('0x59')](function(_0x4a7981){_0x4d54aa({'ret':0x1});})[_0x799f('0x5a')](function(_0x2acef4){logger[_0x799f('0x61')](_0x2acef4[_0x799f('0x5b')]);_0x2a88dc({'ret':0x1});});}});}function handleTZQuery(_0x486e01){logger[_0x799f('0x54')](_0x486e01);return db[_0x799f('0x58')]['query'](_0x486e01)['spread'](function(_0x43752e){})[_0x799f('0x5a')](function(_0x246c7e){logger[_0x799f('0x61')](_0x246c7e[_0x799f('0x5b')]);});}function main(_0x59d87c,_0x1505dc,_0x465057,_0x21f8ce){logger['info'](_0x799f('0x6a'),_0x59d87c,JSON['stringify'](_0x1505dc));process[_0x799f('0x6b')](_0x799f('0x6c'));var _0x40e1bd=_0x1505dc[_0x799f('0x6d')];var _0x2ac3ab=_[_0x799f('0x6e')](_0x40e1bd);var _0x1ff895=_0x1505dc[_0x799f('0x6f')];var _0x540a49=path['join'](config[_0x799f('0x70')],'server/files/tmp',_0x1ff895+_0x799f('0x71'));hasTZ=_[_0x799f('0x4f')](_0x40e1bd)['includes'](_0x799f('0x66'));var _0xb5a1b1=_[_0x799f('0x4f')](_0x40e1bd)[_0x799f('0x35')]();logger[_0x799f('0x54')](_0x799f('0x72'),_0xb5a1b1);db[_0x799f('0x73')]['findAll']({'raw':!![],'attributes':['id',_0x799f('0x74')]})[_0x799f('0x17')](function(_0x23ab5c){for(var _0x398ad4=0x0;_0x398ad4<_0x23ab5c['length'];_0x398ad4++){if(_0x23ab5c[_0x398ad4][_0x799f('0x74')]in _0x40e1bd){contactItemTypes[_0x799f('0x19')](_0x23ab5c[_0x398ad4]);delete _0x2ac3ab[_0x23ab5c[_0x398ad4][_0x799f('0x74')]];hasAdditionalPhones=!![];}for(var _0x5b50c6 in _0x40e1bd){if(_0x23ab5c[_0x398ad4][_0x799f('0x74')]+_0x799f('0x75')===_0x5b50c6){phoneDescriptions[_0x799f('0x19')]({'itemTypeId':_0x23ab5c[_0x398ad4]['id'],'description':_0x5b50c6});delete _0x2ac3ab[_0x5b50c6];}}}if(hasAdditionalPhones)_0x2ac3ab[_0x799f('0x16')]='';var _0x37ffd3=_[_0x799f('0x4f')](_0x2ac3ab)[_0x799f('0x35')]();logger[_0x799f('0x54')](_0x799f('0x72'),_0x37ffd3);fs[_0x799f('0x76')](_0x540a49,_0x37ffd3+'\x0a');Papa['parse'](fs[_0x799f('0x77')](_0x59d87c),{'header':!![],'skipEmptyLines':!![],'step':function(_0x160519,_0x3f121a){try{for(var _0x4688d3=0x0,_0x381113=[];_0x4688d3<_0x160519['data'][_0x799f('0x18')];_0x4688d3++){stats[_0x799f('0x78')]+=0x1;if(_0x160519[_0x799f('0x57')][_0x4688d3]){handleError(_0x160519[_0x799f('0x79')][_0x4688d3],_0x160519[_0x799f('0x57')][_0x4688d3]);}else{var _0xe8036b=[];var _0x85f3e8=[];var _0x8cc6cd={};for(var _0x19df7a in _0x40e1bd){let _0x3cbca6=contactItemTypes[_0x799f('0x7a')](_0x390cf2=>_0x390cf2[_0x799f('0x74')]===_0x19df7a);let _0x17a231=contactItemTypes[_0x799f('0x7a')](_0x2d3c3a=>_0x2d3c3a[_0x799f('0x74')]+_0x799f('0x75')===_0x19df7a);if(_[_0x799f('0x7b')](_0x3cbca6)&&_['isNil'](_0x17a231)){if(_0x40e1bd[_0x799f('0x7c')](_0x19df7a)){if(_0x160519[_0x799f('0x79')][_0x4688d3][_0x40e1bd[_0x19df7a]]){var _0x585996=_[_0x799f('0x7d')](_0x160519[_0x799f('0x79')][_0x4688d3][_0x40e1bd[_0x19df7a]][_0x799f('0x7e')](/"/g,'\x27'));switch(_0x19df7a){case _0x799f('0x45'):var _0x48a2b4=moment(_0x585996,_0x799f('0xd'),!![]);if(_0x48a2b4[_0x799f('0x7f')]()){_0x381113['push']('\x22'+_0x585996+'\x22');}else{_0xe8036b[_0x799f('0x19')](_0x799f('0x80'));}break;case _0x799f('0x30'):var _0x242137=parseInt(_0x585996);_0x585996=_['isNaN'](_0x242137)||_0x242137<0x0||_0x242137>0x4?_0x21f8ce?0x3:0x2:_0x242137;_0x381113[_0x799f('0x19')]('\x22'+_0x585996+'\x22');break;case _0x799f('0x31'):var _0x45c994=parseInt(_0x585996);if(_[_0x799f('0x81')](_0x45c994)&&_[_0x799f('0x82')](_0x465057,_0x45c994)){_0x381113['push']('\x22'+_0x45c994+'\x22');}else{_0xe8036b[_0x799f('0x19')](_0x799f('0x83'));}break;case _0x799f('0x84'):if(isEmail(_0x585996)){_0x381113[_0x799f('0x19')]('\x22'+_0x585996+'\x22');}else{_0xe8036b[_0x799f('0x19')](_0x799f('0x85'));}break;case'dateOfBirth':var _0x25b42d=moment(_0x585996,_0x799f('0x86'),!![]);if(_0x25b42d[_0x799f('0x7f')]()){_0x381113['push']('\x22'+_0x585996+'\x22');}else{_0xe8036b['push']('dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)');}break;case'dialTimezone':var _0x4bd71c=shared['timezones'];var _0x5dafbb=_0x4bd71c[_0x585996];if(!_[_0x799f('0x7b')](_0x5dafbb)){var _0x5b0545=_0x5dafbb[_0x799f('0x67')];_0x381113['push']('\x22'+_0x585996+'\x22');_0x381113['push']('\x22'+_0x5b0545+'\x22');}break;default:_0x381113[_0x799f('0x19')]('\x22'+_0x585996+'\x22');}}else{switch(_0x19df7a){case _0x799f('0x87'):case'phone':_0xe8036b['push'](_0x19df7a+'\x20not\x20specified');break;default:_0x381113[_0x799f('0x19')]('\x22\x22');}}}}else{var _0x51257e='';if(!_[_0x799f('0x7b')](_0x3cbca6)){if(!_0x8cc6cd['hasOwnProperty'](_0x3cbca6['id'])){if(!_[_0x799f('0x7b')](_0x160519[_0x799f('0x79')][_0x4688d3][_0x40e1bd[_0x19df7a]])){var _0x585996=_[_0x799f('0x7d')](_0x160519['data'][_0x4688d3][_0x40e1bd[_0x19df7a]][_0x799f('0x7e')](/"/g,'\x27'));var _0x4a5be1=phoneDescriptions['find'](_0x275da4=>_0x275da4[_0x799f('0x88')]===_0x3cbca6['id']);if(!_[_0x799f('0x7b')](_0x4a5be1)){var _0x116889=_[_0x799f('0x7d')](_0x160519[_0x799f('0x79')][_0x4688d3][_0x40e1bd[_0x4a5be1[_0x799f('0x89')]]][_0x799f('0x7e')](/"/g,'\x27'));if(!_['isNil'](_0x116889))_0x585996=_0x585996+'§'+_0x116889;}if(_0x51257e=='')_0x51257e=_0x585996;else _0x51257e+='|'+_0x585996;}_0x85f3e8[_0x799f('0x19')](_0x3cbca6['id']+':'+_0x51257e);_0x8cc6cd[_0x3cbca6['id']]=0x1;}}}}if(hasAdditionalPhones){_0x381113[_0x799f('0x19')]('\x22'+_0x85f3e8[_0x799f('0x35')](';')+'\x22');}if(_0xe8036b[_0x799f('0x18')]){handleError(_0x160519[_0x799f('0x79')][_0x4688d3],{'code':_0x799f('0x8a'),'message':_0xe8036b['join']()});}else{fs[_0x799f('0x8b')](_0x540a49,_0x381113[_0x799f('0x35')]()+'\x0a');}_0x381113=[];}if(!(stats['rows']%0xc8)){socket['emit']('contact:import:'+_0x1ff895,stats);stats[_0x799f('0x57')]=[];}}if(stopped){logger[_0x799f('0x54')](_0x799f('0x8c'));_0x3f121a['abort']();}}catch(_0x407ff9){handleError(_0x160519[_0x799f('0x79')][_0x4688d3],{'code':_0x799f('0x8d'),'message':_0x407ff9[_0x799f('0x5b')]});logger['error'](_0x799f('0x8e'),_0x407ff9[_0x799f('0x5b')]);}},'complete':function(){try{var _0x487367=[];var _0x4290c7=[];var _0x5e889d=_0x799f('0x33');if(_0x1505dc[_0x799f('0x8f')]&&_0x1505dc[_0x799f('0x8f')][_0x799f('0x18')]){_0x5e889d=_0x799f('0x90')+_0x1ff895;_0x487367[_0x799f('0x19')](_0x799f('0x91')+_0x5e889d+'\x20LIKE\x20cm_contacts;');}tmp_campaigns=_0x799f('0x92')+_0x1ff895;tmp_voice_queues=_0x799f('0x93')+_0x1ff895;_0x4290c7['push']('CREATE\x20TABLE\x20'+tmp_campaigns+'(id\x20int,dialTimezone\x20varchar(255),offset\x20int);');_0x4290c7['push'](_0x799f('0x91')+tmp_voice_queues+_0x799f('0x94'));BPromise[_0x799f('0x95')](_0x4290c7,handleTZQuery)['then'](function(_0x4355c4){updateTzCampaigns(_0x1505dc[_0x799f('0x2d')])[_0x799f('0x17')](function(_0x426f0d){updateTzVoiceQueues(_0x1505dc[_0x799f('0x2d')])[_0x799f('0x17')](function(_0x3cbd90){if(hasTZ)_0x37ffd3=_0x37ffd3[_0x799f('0x7e')](_0x799f('0x66'),_0x799f('0x96'));var _0x5f0d4e=util[_0x799f('0xc')]('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',_0x540a49,_0x5e889d,_0x37ffd3,_0x1505dc[_0x799f('0x2d')],_0x1505dc[_0x799f('0x97')]||null,NOW,NOW);if(_[_0x799f('0x7b')](_0x40e1bd['scheduledat'])){_0x5f0d4e+=_0x799f('0x98');}_0x487367['push'](_0x5f0d4e);if(_0x1505dc[_0x799f('0x8f')]&&_0x1505dc['duplicates'][_0x799f('0x18')]){_0x487367[_0x799f('0x19')](insertCmContact(_0x1505dc['ListId'],_0x5e889d,_0x1505dc['duplicates'],_0x40e1bd));_0x487367[_0x799f('0x19')]('DROP\x20TABLE\x20'+_0x5e889d+';');}BPromise['each'](_0x487367,handleQuery)[_0x799f('0x17')](function(_0x120ccf){BPromise[_0x799f('0x1a')]([handleAdditionalPhones()])[_0x799f('0x17')](function(){_0x487367=[];for(var _0x437b17=0x0;_0x437b17<promisesAdditionalPhones[_0x799f('0x18')];_0x437b17++){if(promisesAdditionalPhones[_0x437b17][_0x799f('0x10')]!='§'){_0x487367['push'](createAdditionalPhone(promisesAdditionalPhones[_0x437b17]['contactId'],promisesAdditionalPhones[_0x437b17]['contactTypeId'],promisesAdditionalPhones[_0x437b17][_0x799f('0x10')],promisesAdditionalPhones[_0x437b17][_0x799f('0x99')]));}}BPromise[_0x799f('0x1a')](_0x487367)[_0x799f('0x17')](function(){_0x487367=[];if(hasTZ){_0x487367['push'](insertTzCmHopper(_0x1505dc[_0x799f('0x2d')],_0x799f('0x9a'),_0x799f('0x9b'),_0x799f('0x9c'),_0x21f8ce,tmp_voice_queues));_0x487367[_0x799f('0x19')](insertTzCmHopperBlack(_0x1505dc[_0x799f('0x2d')],_0x799f('0x9d'),'voice_queues',_0x799f('0x9c')));_0x487367[_0x799f('0x19')](insertTzCmHopper(_0x1505dc[_0x799f('0x2d')],_0x799f('0x5f'),_0x799f('0x5e'),_0x799f('0x9e'),_0x21f8ce,tmp_campaigns));_0x487367['push'](insertTzCmHopperBlack(_0x1505dc[_0x799f('0x2d')],_0x799f('0x9f'),_0x799f('0x5e'),'CampaignId'));_0x487367[_0x799f('0x19')](insertCmHopperAdditionalPhones(_0x1505dc[_0x799f('0x2d')]));}else{_0x487367[_0x799f('0x19')](insertCmHopper(_0x1505dc[_0x799f('0x2d')],_0x799f('0x9a'),_0x799f('0x9b'),_0x799f('0x9c'),_0x21f8ce));_0x487367[_0x799f('0x19')](insertCmHopperBlack(_0x1505dc[_0x799f('0x2d')],'voice_queues_has_cm_blacklists',_0x799f('0x9b'),'VoiceQueueId'));_0x487367[_0x799f('0x19')](insertCmHopper(_0x1505dc[_0x799f('0x2d')],_0x799f('0x5f'),_0x799f('0x5e'),'CampaignId',_0x21f8ce));_0x487367['push'](insertCmHopperBlack(_0x1505dc['ListId'],_0x799f('0x9f'),_0x799f('0x5e'),'CampaignId'));_0x487367[_0x799f('0x19')](insertCmHopperAdditionalPhones(_0x1505dc[_0x799f('0x2d')]));}_0x487367[_0x799f('0x19')](_0x799f('0xa0')+tmp_campaigns+';');_0x487367[_0x799f('0x19')]('DROP\x20TABLE\x20'+tmp_voice_queues+';');BPromise[_0x799f('0x95')](_0x487367,handleQuery)[_0x799f('0x17')](function(_0x5bb18a){stats[_0x799f('0xa1')]=!![];stats['affectedRows']=_0x1505dc[_0x799f('0x8f')]&&_0x1505dc['duplicates'][_0x799f('0x18')]?results[0x2][_0x799f('0xa2')]:results[0x0][_0x799f('0xa2')];socket[_0x799f('0xa3')](_0x799f('0xa4')+_0x1ff895,stats);fs[_0x799f('0xa5')](_0x59d87c);fs[_0x799f('0xa5')](_0x540a49);process['exit'](0x0);})[_0x799f('0x5a')](function(_0xbd2b5){logger['error'](_0xbd2b5[_0x799f('0x5b')]);process[_0x799f('0x56')](0x1);});});});})['catch'](function(_0x498be6){logger[_0x799f('0x61')](_0x498be6['message']);process[_0x799f('0x56')](0x1);});});});});}catch(_0xc2145e){logger[_0x799f('0x61')](_0x799f('0xa6'),_0xc2145e[_0x799f('0x5b')]);process[_0x799f('0x56')](0x1);}},'error':function(_0x2e3695,_0x297f62,_0x391537,_0x54aee2){throw new Error(_0x54aee2);}});});}function validate(){if(process[_0x799f('0xa7')]&&process[_0x799f('0xa7')][_0x799f('0x18')]<0x4){throw new Error(_0x799f('0xa8'));}var _0x120c41=path[_0x799f('0x35')](config[_0x799f('0x70')],_0x799f('0xa9'),process[_0x799f('0xa7')][0x2]);if(!fs[_0x799f('0xaa')](_0x120c41)){throw new Error(_0x799f('0xab'));}var _0x1709f2={};try{_0x1709f2=JSON[_0x799f('0xac')](process[_0x799f('0xa7')][0x3]);if(!_0x1709f2[_0x799f('0x6d')]){throw new Error(_0x799f('0xad'));}if(!_0x1709f2[_0x799f('0x6d')][_0x799f('0x10')]){throw new Error(_0x799f('0xae'));}if(!_0x1709f2['binding'][_0x799f('0x87')]){throw new Error(_0x799f('0xaf'));}var _0x3f2b00=0x0;if(_0x1709f2[_0x799f('0x6d')]['UserId']){_0x3f2b00=0x1;}if(!_0x1709f2[_0x799f('0x2d')]){throw new Error(_0x799f('0xb0'));}}catch(_0x211b66){throw new Error('body\x20id\x20mandatory');}var _0x51e10a=[];try{_0x51e10a=_[_0x799f('0xb1')](JSON[_0x799f('0xac')](process['argv'][0x4]),'id');}catch(_0x259b9f){logger[_0x799f('0x54')](_0x799f('0xb2'));}main(_0x120c41,_0x1709f2,_0x51e10a,_0x3f2b00);}validate();process['on'](_0x799f('0xb3'),handleStop);process['on']('uncaughtException',handleUncaughtException);
\ No newline at end of file