Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / components / import / cm / csv2.js
index b2627f5..11e6722 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x0788=['cm_contacts.priority','keys','CompanyId',')\x20NOT\x20IN\x20?','id\x20IN\x20?','min_id','group','info','Received\x20SIGINT','message','exit','push','code','sequelize','query','spread','error','campaigns.dialTimezone','campaigns.id\x20=\x20campaigns_has_cm_lists.CampaignId','campaigns_has_cm_lists.CmListId=','length','all','then','catch','voice_queues.dialTimezone','voice_queues','voice_queues.id\x20=\x20voice_queues_has_cm_lists.VoiceQueueId','timezones','dialTimezone','isNil','utcOffset','set','offset','main','stringify','send','server/files/tmp','.csv','includes','writeFileSync','createReadStream','data','rows','errors','hasOwnProperty','trim','replace','isValid','scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)','isNaN','isNumber','agent\x20not\x20exists','email','email\x20wrong\x20format','YYYY-MM-DD','dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)','\x20not\x20specified','SystemRow','appendFileSync','emit','contact:import:','abort','SystemError','step','duplicates','cm_contacts_','CREATE\x20TABLE\x20','voice_queues_','(id\x20int,dialTimezone\x20varchar(255),offset\x20int);','each','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',',\x20scheduledAt\x20=\x20NOW()','DROP\x20TABLE\x20','voice_queues_has_cm_lists','VoiceQueueId','voice_queues_has_cm_blacklists','campaigns_has_cm_lists','CampaignId','campaigns_has_cm_blacklists','campaigns','finish','affectedRows','unlink','complete','argv','arguments\x20<filename>\x20<parameters>\x20<agents>','file\x20doesn\x27t\x20exists','binding','phone\x20is\x20mandatory','firstName','firstName\x20is\x20mandatory','ListId\x20is\x20mandatory','map','parse','No\x20agent\x20available','uncaughtException','lodash','papaparse','util','bluebird','moment','squel','../../../config/environment','../../../config/environment/shared','redis','defaults','localhost','YYYY-MM-DD\x20HH:mm:ss','test','select','field','phone','from','join','.id\x20=\x20','\x20=\x20','where','.dialCheckDuplicateType\x20IN\x20(','cm_contacts.phone','cm_contacts.scheduledat','cm_contacts.id','cm_contacts.ListId','cm_contacts.updatedAt','cm_contacts.UserId','insert','into','fromQuery','scheduledat','ContactId','ListId','createdAt','updatedAt','priority','UserId','recallme','fields','cm_contacts','cm_contacts.ListId\x20=\x20','.CmListId','.CmListId\x20=\x20?','cm_contacts.createdAt\x20=\x20?','cm_contacts.phone\x20NOT\x20IN\x20(?)','cm_hopper','\x22always\x22','\x22onlyIfOpen\x22','toString','cm_hopper_black','\x20=\x20?','.offset-cm_contacts.utcOffset\x20minute)','cm_contacts.createdAt'];(function(_0x4bdb52,_0xfe60ee){var _0x185ee3=function(_0x316855){while(--_0x316855){_0x4bdb52['push'](_0x4bdb52['shift']());}};_0x185ee3(++_0xfe60ee);}(_0x0788,0x18f));var _0x8078=function(_0x28fbb7,_0x3e6904){_0x28fbb7=_0x28fbb7-0x0;var _0x4894e1=_0x0788[_0x28fbb7];return _0x4894e1;};'use strict';var fs=require('fs');var path=require('path');var _=require(_0x8078('0x0'));var Papa=require(_0x8078('0x1'));var util=require(_0x8078('0x2'));var BPromise=require(_0x8078('0x3'));var moment=require(_0x8078('0x4'));var squel=require(_0x8078('0x5'));var Redis=require('ioredis');var db=require('../../../mysqldb')['db'];var config=require(_0x8078('0x6'));var shared=require(_0x8078('0x7'));var logger=require('../../../config/logger')('import');config[_0x8078('0x8')]=_[_0x8078('0x9')](config['redis'],{'host':_0x8078('0xa'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x8078('0x8')]));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var stopped=![];var tmp_voice_queues;var tmp_campaigns;var tzOffset=0x0;var hasTZ;var NOW=moment()['format'](_0x8078('0xb'));function isEmail(_0x6bd609){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))*$/[_0x8078('0xc')](_0x6bd609);}function selectNotIn(_0x5b7bc9,_0x288087,_0x2cbc8b,_0x43d898,_0xa141e6){return squel[_0x8078('0xd')]()[_0x8078('0xe')](_0x8078('0xf'))[_0x8078('0x10')](_0x43d898)[_0x8078('0x11')](_0x288087,null,_0x288087+_0x8078('0x12')+_0x43d898+'.'+_0x2cbc8b)['where'](_0x43d898+'.'+_0x2cbc8b+_0x8078('0x13')+_0x5b7bc9+'.'+_0x2cbc8b)[_0x8078('0x14')](_0x288087+_0x8078('0x15')+_0xa141e6[_0x8078('0x11')]()+')');}function insertCmHopper(_0x5538bb,_0x2a1aa5,_0x4653c7,_0xc1354a,_0x2321f0){var _0x4e8dcb=[_0x8078('0x16'),_0x8078('0x17'),_0x8078('0x18'),_0x8078('0x19'),_0x2a1aa5+'.'+_0xc1354a,'cm_contacts.createdAt',_0x8078('0x1a'),'cm_contacts.priority',_0x8078('0x1b'),'\x22'+_0x2321f0+'\x22'];return squel[_0x8078('0x1c')]()[_0x8078('0x1d')]('cm_hopper')[_0x8078('0x1e')]([_0x8078('0xf'),_0x8078('0x1f'),_0x8078('0x20'),_0x8078('0x21'),_0xc1354a,_0x8078('0x22'),_0x8078('0x23'),_0x8078('0x24'),_0x8078('0x25'),_0x8078('0x26')],squel['select']()[_0x8078('0x27')](_0x4e8dcb)[_0x8078('0x10')](_0x2a1aa5)[_0x8078('0x11')](_0x8078('0x28'),null,_0x8078('0x29')+_0x2a1aa5+_0x8078('0x2a'))[_0x8078('0x11')](_0x4653c7,null,_0x4653c7+_0x8078('0x12')+_0x2a1aa5+'.'+_0xc1354a)[_0x8078('0x14')](_0x2a1aa5+_0x8078('0x2b'),_0x5538bb)['where'](_0x8078('0x2c'),NOW)[_0x8078('0x14')](_0x8078('0x2d'),selectNotIn(_0x2a1aa5,_0x4653c7,_0xc1354a,_0x8078('0x2e'),[_0x8078('0x2f'),_0x8078('0x30')]))[_0x8078('0x14')](_0x8078('0x2d'),selectNotIn(_0x2a1aa5,_0x4653c7,_0xc1354a,_0x8078('0x2e'),[_0x8078('0x2f')])))[_0x8078('0x31')]();}function insertCmHopperBlack(_0x2d8d26,_0x3025ed,_0x17595e,_0xcd52cc){var _0x51ef94=[_0x8078('0x16'),_0x8078('0x18'),_0x8078('0x19'),_0x3025ed+'.'+_0xcd52cc,'cm_contacts.createdAt',_0x8078('0x1a')];return squel[_0x8078('0x1c')]()[_0x8078('0x1d')](_0x8078('0x32'))[_0x8078('0x1e')]([_0x8078('0xf'),_0x8078('0x20'),_0x8078('0x21'),_0xcd52cc,_0x8078('0x22'),_0x8078('0x23')],squel[_0x8078('0xd')]()[_0x8078('0x27')](_0x51ef94)[_0x8078('0x10')](_0x3025ed)[_0x8078('0x11')](_0x8078('0x28'),null,_0x8078('0x29')+_0x3025ed+_0x8078('0x2a'))['join'](_0x17595e,null,_0x17595e+'.id\x20=\x20'+_0x3025ed+'.'+_0xcd52cc)[_0x8078('0x14')](_0x3025ed+_0x8078('0x2b'),_0x2d8d26)['where'](_0x8078('0x2c'),NOW)[_0x8078('0x14')](_0x8078('0x2d'),squel[_0x8078('0xd')]()[_0x8078('0xe')](_0x8078('0xf'))['from']('cm_hopper_black')[_0x8078('0x14')]('ListId\x20=\x20?',_0x2d8d26)[_0x8078('0x14')](_0xcd52cc+_0x8078('0x33'),_0x3025ed+'.'+_0xcd52cc)))[_0x8078('0x31')]();}function insertTzCmHopper(_0x57bf59,_0x4685d6,_0x4b330c,_0x335aa8,_0x165603,_0x3f1303){var _0x29e712=[_0x8078('0x16'),'date_add(cm_contacts.scheduledat,interval\x20'+_0x3f1303+_0x8078('0x34'),'cm_contacts.id',_0x8078('0x19'),_0x4685d6+'.'+_0x335aa8,_0x8078('0x35'),_0x8078('0x1a'),_0x8078('0x36'),'cm_contacts.UserId','\x22'+_0x165603+'\x22'];var _0x11a4f3=squel[_0x8078('0x1c')]()[_0x8078('0x1d')](_0x8078('0x2e'))[_0x8078('0x1e')]([_0x8078('0xf'),'scheduledat',_0x8078('0x20'),_0x8078('0x21'),_0x335aa8,_0x8078('0x22'),'updatedAt','priority','UserId',_0x8078('0x26')],squel[_0x8078('0xd')]()[_0x8078('0x27')](_0x29e712)[_0x8078('0x10')](_0x4685d6)[_0x8078('0x11')]('cm_contacts',null,'cm_contacts.ListId\x20=\x20'+_0x4685d6+'.CmListId')[_0x8078('0x11')](_0x4b330c,null,_0x4b330c+_0x8078('0x12')+_0x4685d6+'.'+_0x335aa8)['join'](_0x3f1303,null,_0x3f1303+_0x8078('0x12')+_0x4685d6+'.'+_0x335aa8)[_0x8078('0x14')](_0x4685d6+'.CmListId\x20=\x20?',_0x57bf59)['where'](_0x8078('0x2c'),NOW)['where'](_0x8078('0x2d'),selectNotIn(_0x4685d6,_0x4b330c,_0x335aa8,_0x8078('0x2e'),['\x22always\x22',_0x8078('0x30')]))[_0x8078('0x14')](_0x8078('0x2d'),selectNotIn(_0x4685d6,_0x4b330c,_0x335aa8,'cm_hopper',[_0x8078('0x2f')])))['toString']();return _0x11a4f3;}function insertTzCmHopperBlack(_0x1f273,_0x4d2f8f,_0xf6325c,_0x1c4df5){var _0x2a574f=[_0x8078('0x16'),_0x8078('0x18'),_0x8078('0x19'),_0x4d2f8f+'.'+_0x1c4df5,_0x8078('0x35'),_0x8078('0x1a')];return squel[_0x8078('0x1c')]()[_0x8078('0x1d')](_0x8078('0x32'))[_0x8078('0x1e')]([_0x8078('0xf'),_0x8078('0x20'),_0x8078('0x21'),_0x1c4df5,'createdAt',_0x8078('0x23')],squel[_0x8078('0xd')]()[_0x8078('0x27')](_0x2a574f)['from'](_0x4d2f8f)[_0x8078('0x11')]('cm_contacts',null,_0x8078('0x29')+_0x4d2f8f+_0x8078('0x2a'))[_0x8078('0x11')](_0xf6325c,null,_0xf6325c+'.id\x20=\x20'+_0x4d2f8f+'.'+_0x1c4df5)[_0x8078('0x14')](_0x4d2f8f+_0x8078('0x2b'),_0x1f273)[_0x8078('0x14')](_0x8078('0x2c'),NOW)['where'](_0x8078('0x2d'),squel[_0x8078('0xd')]()[_0x8078('0xe')]('phone')[_0x8078('0x10')](_0x8078('0x32'))[_0x8078('0x14')]('ListId\x20=\x20?',_0x1f273)[_0x8078('0x14')](_0x1c4df5+_0x8078('0x33'),_0x4d2f8f+'.'+_0x1c4df5)))['toString']();}function insertCmContact(_0xa7496a,_0x4f7f61,_0x5544e6,_0x1aba18){var _0x3b32b3=_['concat'](_[_0x8078('0x37')](_0x1aba18),[_0x8078('0x21'),_0x8078('0x38'),_0x8078('0x22'),_0x8078('0x23')]);return squel[_0x8078('0x1c')]()[_0x8078('0x1d')](_0x8078('0x28'))['fromQuery'](_0x3b32b3,squel[_0x8078('0xd')]()[_0x8078('0x27')](_0x3b32b3)[_0x8078('0x10')](_0x4f7f61)[_0x8078('0x14')]('('+_0x5544e6[_0x8078('0x11')](',')+_0x8078('0x39'),squel[_0x8078('0xd')]()[_0x8078('0x27')](_0x5544e6)[_0x8078('0x10')](_0x8078('0x28'))[_0x8078('0x14')]('ListId\x20=\x20?',_0xa7496a)[_0x8078('0x14')]('deletedAt\x20IS\x20NULL'))[_0x8078('0x14')](_0x8078('0x3a'),squel['select']()[_0x8078('0xe')]('MIN(id)',_0x8078('0x3b'))[_0x8078('0x10')](_0x4f7f61)[_0x8078('0x3c')](_0x5544e6[_0x8078('0x11')](','))))[_0x8078('0x31')]();}function handleStop(){logger[_0x8078('0x3d')](_0x8078('0x3e'));stopped=!![];}function handleUncaughtException(_0x43f4e0){logger['error'](_0x43f4e0[_0x8078('0x3f')]);process[_0x8078('0x40')](0x1);}function handleError(_0x37dbd9,_0x5a803b){stats['errors'][_0x8078('0x41')]({'name':_0x5a803b[_0x8078('0x42')],'message':_0x5a803b[_0x8078('0x3f')],'row':_0x37dbd9});}function handleQuery(_0x45003b){logger[_0x8078('0x3d')](_0x45003b);return db[_0x8078('0x43')][_0x8078('0x44')](_0x45003b)[_0x8078('0x45')](function(_0x5ad74c){results['push'](_0x5ad74c);})['catch'](function(_0x56d192){logger[_0x8078('0x46')](_0x56d192[_0x8078('0x3f')]);});}function updateTzCampaigns(_0xdc5048){return new Promise(function(_0x431529,_0x21e17f){var _0x2d258c=squel[_0x8078('0xd')]()[_0x8078('0x27')](['campaigns.id',_0x8078('0x47')])['from']('campaigns')[_0x8078('0x11')]('campaigns_has_cm_lists',null,_0x8078('0x48'))['where'](_0x8078('0x49')+_0xdc5048);db[_0x8078('0x43')][_0x8078('0x44')](_0x2d258c[_0x8078('0x31')]())[_0x8078('0x45')](function(_0xd551c1){var _0x306f10=[];for(var _0x5384a5=0x0;_0x5384a5<_0xd551c1[_0x8078('0x4a')];_0x5384a5++){_0x306f10[_0x8078('0x41')](getTimezoneData(_0xd551c1[_0x5384a5],tmp_campaigns));}BPromise[_0x8078('0x4b')](_0x306f10)[_0x8078('0x4c')](function(){_0x431529({'val':0x1});});})[_0x8078('0x4d')](function(_0x189117){logger[_0x8078('0x46')](_0x189117[_0x8078('0x3f')]);_0x431529({'val':0x0});});});}function updateTzVoiceQueues(_0xb87814){return new Promise(function(_0x327834,_0x271476){var _0x6942d3=squel[_0x8078('0xd')]()[_0x8078('0x27')](['voice_queues.id',_0x8078('0x4e')])[_0x8078('0x10')](_0x8078('0x4f'))[_0x8078('0x11')]('voice_queues_has_cm_lists',null,_0x8078('0x50'))[_0x8078('0x14')]('voice_queues_has_cm_lists.CmListId='+_0xb87814);db['sequelize'][_0x8078('0x44')](_0x6942d3[_0x8078('0x31')]())[_0x8078('0x45')](function(_0x3f0f50){var _0x5b8d39=[];for(var _0x8c72a9=0x0;_0x8c72a9<_0x3f0f50[_0x8078('0x4a')];_0x8c72a9++){_0x5b8d39[_0x8078('0x41')](getTimezoneData(_0x3f0f50[_0x8c72a9],tmp_voice_queues));}BPromise['all'](_0x5b8d39)[_0x8078('0x4c')](function(){_0x327834({'val':0x1});});})[_0x8078('0x4d')](function(_0x2e4368){logger[_0x8078('0x46')](_0x2e4368[_0x8078('0x3f')]);_0x327834({'val':0x0});});});}function getTimezoneData(_0x5bac8e,_0x5e0b0f){return new Promise(function(_0x55bce8,_0x570b27){var _0x2be820=shared[_0x8078('0x51')];var _0x252277=_0x2be820[_0x5bac8e[_0x8078('0x52')]];if(_[_0x8078('0x53')](_0x252277)){_0x55bce8({'ret':0x1});}else{var _0x3df35=_0x252277[_0x8078('0x54')];var _0x5c1a09=squel['insert']()[_0x8078('0x1d')](_0x5e0b0f)[_0x8078('0x55')]('id',_0x5bac8e['id'])[_0x8078('0x55')](_0x8078('0x56'),_0x3df35)['set']('dialTimezone',_0x5bac8e[_0x8078('0x52')])[_0x8078('0x31')]();return db['sequelize']['query'](_0x5c1a09)['spread'](function(_0x1d9fe1){_0x55bce8({'ret':0x1});})[_0x8078('0x4d')](function(_0x14f972){logger[_0x8078('0x46')](_0x14f972[_0x8078('0x3f')]);_0x570b27({'ret':0x1});});}});}function handleTZQuery(_0x2b4289){logger['info'](_0x2b4289);return db['sequelize'][_0x8078('0x44')](_0x2b4289)['spread'](function(_0x35dd4e){})[_0x8078('0x4d')](function(_0x2aba6b){logger['error'](_0x2aba6b[_0x8078('0x3f')]);});}function main(_0x41fa76,_0x49fd04,_0x26862d,_0x1aedea){logger[_0x8078('0x3d')](_0x8078('0x57'),_0x41fa76,JSON[_0x8078('0x58')](_0x49fd04));process[_0x8078('0x59')]('start');var _0x187f77=_0x49fd04['binding'];var _0x4097f0=_0x49fd04['socket_timestamp'];var _0x4cc33b=path[_0x8078('0x11')](config['root'],_0x8078('0x5a'),_0x4097f0+_0x8078('0x5b'));hasTZ=_['keys'](_0x187f77)[_0x8078('0x5c')](_0x8078('0x52'));var _0x34c198=_[_0x8078('0x37')](_0x187f77)[_0x8078('0x11')]();logger['info']('header',_0x34c198);if(hasTZ)_0x34c198+=',utcOffset';fs[_0x8078('0x5d')](_0x4cc33b,_0x34c198+'\x0a');Papa['parse'](fs[_0x8078('0x5e')](_0x41fa76),{'header':!![],'skipEmptyLines':!![],'step':function(_0x9fddf,_0x3517d5){try{for(var _0x56ef6e=0x0,_0x5387c4=[];_0x56ef6e<_0x9fddf[_0x8078('0x5f')][_0x8078('0x4a')];_0x56ef6e++){stats[_0x8078('0x60')]+=0x1;if(_0x9fddf[_0x8078('0x61')][_0x56ef6e]){handleError(_0x9fddf[_0x8078('0x5f')][_0x56ef6e],_0x9fddf[_0x8078('0x61')][_0x56ef6e]);}else{var _0x123c5c=[];for(var _0x38b876 in _0x187f77){if(_0x187f77[_0x8078('0x62')](_0x38b876)){if(_0x9fddf[_0x8078('0x5f')][_0x56ef6e][_0x187f77[_0x38b876]]){var _0xe57a79=_[_0x8078('0x63')](_0x9fddf['data'][_0x56ef6e][_0x187f77[_0x38b876]][_0x8078('0x64')](/"/g,'\x27'));switch(_0x38b876){case _0x8078('0x1f'):var _0x163d65=moment(_0xe57a79,_0x8078('0xb'),!![]);if(_0x163d65[_0x8078('0x65')]()){_0x5387c4[_0x8078('0x41')]('\x22'+_0xe57a79+'\x22');}else{_0x123c5c[_0x8078('0x41')](_0x8078('0x66'));}break;case _0x8078('0x24'):var _0x45c4c8=parseInt(_0xe57a79);_0xe57a79=_[_0x8078('0x67')](_0x45c4c8)||_0x45c4c8<0x0||_0x45c4c8>0x4?_0x1aedea?0x3:0x2:_0x45c4c8;_0x5387c4['push']('\x22'+_0xe57a79+'\x22');break;case _0x8078('0x25'):var _0x58f290=parseInt(_0xe57a79);if(_[_0x8078('0x68')](_0x58f290)&&_[_0x8078('0x5c')](_0x26862d,_0x58f290)){_0x5387c4[_0x8078('0x41')]('\x22'+_0x58f290+'\x22');}else{_0x123c5c['push'](_0x8078('0x69'));}break;case _0x8078('0x6a'):if(isEmail(_0xe57a79)){_0x5387c4['push']('\x22'+_0xe57a79+'\x22');}else{_0x123c5c[_0x8078('0x41')](_0x8078('0x6b'));}break;case'dateOfBirth':var _0x21e1d4=moment(_0xe57a79,_0x8078('0x6c'),!![]);if(_0x21e1d4['isValid']()){_0x5387c4['push']('\x22'+_0xe57a79+'\x22');}else{_0x123c5c[_0x8078('0x41')](_0x8078('0x6d'));}break;case _0x8078('0x52'):var _0x394821=shared[_0x8078('0x51')];var _0x3ce216=_0x394821[_0xe57a79];if(!_[_0x8078('0x53')](_0x3ce216)){var _0x4e7f4d=_0x3ce216[_0x8078('0x54')];_0x5387c4[_0x8078('0x41')]('\x22'+_0xe57a79+'\x22');_0x5387c4[_0x8078('0x41')]('\x22'+_0x4e7f4d+'\x22');}break;default:_0x5387c4['push']('\x22'+_0xe57a79+'\x22');}}else{switch(_0x38b876){case'firstName':case _0x8078('0xf'):_0x123c5c[_0x8078('0x41')](_0x38b876+_0x8078('0x6e'));break;default:_0x5387c4['push']('\x22\x22');}}}}if(_0x123c5c[_0x8078('0x4a')]){handleError(_0x9fddf['data'][_0x56ef6e],{'code':_0x8078('0x6f'),'message':_0x123c5c['join']()});}else{fs[_0x8078('0x70')](_0x4cc33b,_0x5387c4[_0x8078('0x11')]()+'\x0a');}_0x5387c4=[];}if(!(stats[_0x8078('0x60')]%0xc8)){socket[_0x8078('0x71')](_0x8078('0x72')+_0x4097f0,stats);stats['errors']=[];}}if(stopped){logger[_0x8078('0x3d')]('Abort\x20parser');_0x3517d5[_0x8078('0x73')]();}}catch(_0x16a037){handleError(_0x9fddf['data'][_0x56ef6e],{'code':_0x8078('0x74'),'message':_0x16a037[_0x8078('0x3f')]});logger[_0x8078('0x46')](_0x8078('0x75'),_0x16a037[_0x8078('0x3f')]);}},'complete':function(){try{var _0x555764=[];var _0x37bc9c=[];var _0x341a65=_0x8078('0x28');if(_0x49fd04[_0x8078('0x76')]&&_0x49fd04[_0x8078('0x76')]['length']){_0x341a65=_0x8078('0x77')+_0x4097f0;_0x555764[_0x8078('0x41')](_0x8078('0x78')+_0x341a65+'\x20LIKE\x20cm_contacts;');}tmp_campaigns='campaigns_'+_0x4097f0;tmp_voice_queues=_0x8078('0x79')+_0x4097f0;_0x37bc9c['push'](_0x8078('0x78')+tmp_campaigns+_0x8078('0x7a'));_0x37bc9c['push'](_0x8078('0x78')+tmp_voice_queues+_0x8078('0x7a'));BPromise[_0x8078('0x7b')](_0x37bc9c,handleTZQuery)[_0x8078('0x4c')](function(_0x540db8){updateTzCampaigns(_0x49fd04[_0x8078('0x21')])[_0x8078('0x4c')](function(_0x4ae946){updateTzVoiceQueues(_0x49fd04[_0x8078('0x21')])[_0x8078('0x4c')](function(_0x570448){var _0x39e616=util[_0x8078('0x7c')](_0x8078('0x7d'),_0x4cc33b,_0x341a65,_0x34c198,_0x49fd04[_0x8078('0x21')],_0x49fd04[_0x8078('0x38')]||null,NOW,NOW);if(_['isNil'](_0x187f77['scheduledat'])){_0x39e616+=_0x8078('0x7e');}_0x555764[_0x8078('0x41')](_0x39e616);if(_0x49fd04[_0x8078('0x76')]&&_0x49fd04[_0x8078('0x76')][_0x8078('0x4a')]){_0x555764[_0x8078('0x41')](insertCmContact(_0x49fd04[_0x8078('0x21')],_0x341a65,_0x49fd04[_0x8078('0x76')],_0x187f77));_0x555764[_0x8078('0x41')](_0x8078('0x7f')+_0x341a65+';');}if(hasTZ){_0x555764[_0x8078('0x41')](insertTzCmHopper(_0x49fd04[_0x8078('0x21')],_0x8078('0x80'),_0x8078('0x4f'),_0x8078('0x81'),_0x1aedea,tmp_voice_queues));_0x555764[_0x8078('0x41')](insertTzCmHopperBlack(_0x49fd04['ListId'],_0x8078('0x82'),_0x8078('0x4f'),_0x8078('0x81')));_0x555764[_0x8078('0x41')](insertTzCmHopper(_0x49fd04[_0x8078('0x21')],_0x8078('0x83'),'campaigns',_0x8078('0x84'),_0x1aedea,tmp_campaigns));_0x555764['push'](insertTzCmHopperBlack(_0x49fd04['ListId'],_0x8078('0x85'),_0x8078('0x86'),_0x8078('0x84')));}else{_0x555764[_0x8078('0x41')](insertCmHopper(_0x49fd04[_0x8078('0x21')],'voice_queues_has_cm_lists',_0x8078('0x4f'),'VoiceQueueId',_0x1aedea));_0x555764[_0x8078('0x41')](insertCmHopperBlack(_0x49fd04[_0x8078('0x21')],_0x8078('0x82'),_0x8078('0x4f'),_0x8078('0x81')));_0x555764['push'](insertCmHopper(_0x49fd04[_0x8078('0x21')],_0x8078('0x83'),_0x8078('0x86'),_0x8078('0x84'),_0x1aedea));_0x555764[_0x8078('0x41')](insertCmHopperBlack(_0x49fd04['ListId'],_0x8078('0x85'),_0x8078('0x86'),_0x8078('0x84')));}_0x555764[_0x8078('0x41')](_0x8078('0x7f')+tmp_campaigns+';');_0x555764[_0x8078('0x41')]('DROP\x20TABLE\x20'+tmp_voice_queues+';');BPromise[_0x8078('0x7b')](_0x555764,handleQuery)[_0x8078('0x4c')](function(_0x19caf6){stats[_0x8078('0x87')]=!![];stats[_0x8078('0x88')]=_0x49fd04[_0x8078('0x76')]&&_0x49fd04['duplicates'][_0x8078('0x4a')]?results[0x2]['affectedRows']:results[0x0]['affectedRows'];socket[_0x8078('0x71')](_0x8078('0x72')+_0x4097f0,stats);fs[_0x8078('0x89')](_0x41fa76);fs['unlink'](_0x4cc33b);process[_0x8078('0x40')](0x0);})[_0x8078('0x4d')](function(_0x38ca3b){logger[_0x8078('0x46')](_0x38ca3b[_0x8078('0x3f')]);process['exit'](0x1);});});});});}catch(_0x37e246){logger[_0x8078('0x46')](_0x8078('0x8a'),_0x37e246[_0x8078('0x3f')]);process[_0x8078('0x40')](0x1);}},'error':function(_0x5aeae9,_0xc42e08,_0x4a61bc,_0x3e3664){throw new Error(_0x3e3664);}});}function validate(){if(process['argv']&&process[_0x8078('0x8b')][_0x8078('0x4a')]<0x4){throw new Error(_0x8078('0x8c'));}var _0x4b0a64=path['join'](config['root'],_0x8078('0x5a'),process['argv'][0x2]);if(!fs['existsSync'](_0x4b0a64)){throw new Error(_0x8078('0x8d'));}var _0x287213={};try{_0x287213=JSON['parse'](process[_0x8078('0x8b')][0x3]);if(!_0x287213[_0x8078('0x8e')]){throw new Error('binding\x20doesn\x27t\x20exists');}if(!_0x287213[_0x8078('0x8e')][_0x8078('0xf')]){throw new Error(_0x8078('0x8f'));}if(!_0x287213['binding'][_0x8078('0x90')]){throw new Error(_0x8078('0x91'));}var _0x40711c=0x0;if(_0x287213[_0x8078('0x8e')][_0x8078('0x25')]){_0x40711c=0x1;}if(!_0x287213[_0x8078('0x21')]){throw new Error(_0x8078('0x92'));}}catch(_0x2ce05c){throw new Error('body\x20id\x20mandatory');}var _0x5adf61=[];try{_0x5adf61=_[_0x8078('0x93')](JSON[_0x8078('0x94')](process['argv'][0x4]),'id');}catch(_0x353dd4){logger['info'](_0x8078('0x95'));}main(_0x4b0a64,_0x287213,_0x5adf61,_0x40711c);}validate();process['on']('SIGINT',handleStop);process['on'](_0x8078('0x96'),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