Built motion from commit e02f907f.|2.6.14
[motion2.git] / server / components / import / cm / csvUpdates.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x4959=['papaparse','util','bluebird','squel','ioredis','../../../mysqldb','../../../config/environment','import','redis','defaults','localhost','socket.io-emitter','format','YYYY-MM-DD\x20HH:mm:ss','cm_contacts_temp_','select','field','phone','from','join','.id\x20=\x20','where','\x20=\x20','.dialCheckDuplicateType\x20IN\x20(','sequelize','select\x20*\x20from\x20','spread','isNil','AdditionalPhones','push','all','message','split','length','then','filter','CmContactHasItem','findOne','update','updated','create','CmContact','CmHopper','cm_contacts.phone','cm_contacts.scheduledat','cm_contacts.id','cm_contacts.updatedAt','cm_contacts.priority','insert','into','fromQuery','ContactId','ListId','createdAt','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','\x22onlyIfOpen\x22','\x22always\x22','toString','cm_contacts.ListId','cm_contacts.createdAt','cm_hopper_black','updatedAt','ListId\x20=\x20?','cm_hopper.id','cm_contact_has_items.OrderBy','cm_contact_has_items.updatedAt','CmHopperId','OrderBy','cm_contacts.id\x20=\x20cm_hopper.ContactId','cm_contact_has_items','cm_hopper.ListId\x20=\x20?','concat','keys',')\x20NOT\x20IN\x20?','MIN(id)','group','info','Received\x20SIGINT','error','exit','errors','code','query','catch','main','stringify','clone','socket_timestamp','root','server/files/tmp','body','ContactItemType','findAll','name','_description','header','writeFileSync','parse','createReadStream','data','find','hasOwnProperty','replace','scheduledat','isValid','scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)','isNaN','isNumber','includes','email\x20wrong\x20format','dateOfBirth','YYYY-MM-DD','firstName','itemTypeId','trim','description','SystemRow','rows','contact:import:','Abort\x20parser','abort','SystemError','step','\x20LIKE\x20cm_contacts;','CompanyId',',\x20scheduledAt\x20=\x20NOW()','each','contact','contactId','contactTypeId','orderBy','affectedRows','emit','unlink','complete','argv','arguments\x20<filename>\x20<parameters>\x20<agents>','existsSync','binding','ListId\x20is\x20mandatory','body\x20id\x20mandatory','map','No\x20agent\x20available','SIGINT','uncaughtException'];(function(_0x49f7a0,_0x52f319){var _0x5d2518=function(_0x2d3d68){while(--_0x2d3d68){_0x49f7a0['push'](_0x49f7a0['shift']());}};_0x5d2518(++_0x52f319);}(_0x4959,0x9b));var _0x9495=function(_0x26d37b,_0x1df90d){_0x26d37b=_0x26d37b-0x0;var _0x5c114f=_0x4959[_0x26d37b];return _0x5c114f;};'use strict';var fs=require('fs');var path=require('path');var _=require('lodash');var Papa=require(_0x9495('0x0'));var util=require(_0x9495('0x1'));var BPromise=require(_0x9495('0x2'));var moment=require('moment');var squel=require(_0x9495('0x3'));var Redis=require(_0x9495('0x4'));var db=require(_0x9495('0x5'))['db'];var config=require(_0x9495('0x6'));var logger=require('../../../config/logger')(_0x9495('0x7'));config[_0x9495('0x8')]=_[_0x9495('0x9')](config[_0x9495('0x8')],{'host':_0x9495('0xa'),'port':0x18eb});var socket=require(_0x9495('0xb'))(new Redis(config[_0x9495('0x8')]));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var promisesAdditionalPhones=[];var promisesContact=[];var orderBy=0x0;var updatedRows=0x0;var stopped=![];var NOW=moment()[_0x9495('0xc')](_0x9495('0xd'));var tempTableName=_0x9495('0xe')+moment()[_0x9495('0xc')]('YYYYMMDDHHmmss');var contactItemTypes=[];var phoneDescriptions=[];var hasAdditionalPhones=![];function isEmail(_0x184fc3){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'](_0x184fc3);}function selectNotIn(_0x4b53aa,_0x4fb16d,_0x49bf36,_0x1fdde8,_0x5e15a3){return squel[_0x9495('0xf')]()[_0x9495('0x10')](_0x9495('0x11'))[_0x9495('0x12')](_0x1fdde8)[_0x9495('0x13')](_0x4fb16d,null,_0x4fb16d+_0x9495('0x14')+_0x1fdde8+'.'+_0x49bf36)[_0x9495('0x15')](_0x1fdde8+'.'+_0x49bf36+_0x9495('0x16')+_0x4b53aa+'.'+_0x49bf36)[_0x9495('0x15')](_0x4fb16d+_0x9495('0x17')+_0x5e15a3[_0x9495('0x13')]()+')');}function handleAdditionalPhones(){return new Promise(function(_0xf7e975,_0x41312c){promisesAdditionalPhones=[];promisesContact=[];return db[_0x9495('0x18')]['query'](_0x9495('0x19')+tempTableName)[_0x9495('0x1a')](function(_0x3cf201){if(_0x3cf201!==null){var _0xcfc1e8=[];for(var _0x1e2c6c=0x0;_0x1e2c6c<_0x3cf201['length'];_0x1e2c6c++){var _0x45d5fd=_0x3cf201[_0x1e2c6c];if(!_[_0x9495('0x1b')](_0x45d5fd[_0x9495('0x11')])){if(!_[_0x9495('0x1b')](_0x45d5fd[_0x9495('0x1c')]))_0xcfc1e8['push'](insertAdditionalPhones(_0x45d5fd));promisesContact[_0x9495('0x1d')]({'contact':_0x45d5fd});}}}Promise[_0x9495('0x1e')](_0xcfc1e8)['then'](function(){_0xf7e975({'val':0x1});});})['catch'](function(_0x56be18){logger['error'](_0x56be18[_0x9495('0x1f')]);});});}function insertAdditionalPhones(_0x185a86){return new Promise(function(_0x95e617,_0x1ca75b){var _0x38207a=_0x185a86[_0x9495('0x1c')];if(_[_0x9495('0x1b')](_0x38207a))_0x1ca75b({'val':0x0});else{var _0x8a990e=_0x38207a[_0x9495('0x20')](';');var _0x4053bb=[];orderBy=0x0;for(var _0x4acbaa=0x0;_0x4acbaa<_0x8a990e[_0x9495('0x21')];_0x4acbaa++){_0x4053bb[_0x9495('0x1d')](splitAdditionalPhone(_0x185a86['id'],_0x8a990e[_0x4acbaa]));}Promise[_0x9495('0x1e')](_0x4053bb)[_0x9495('0x22')](function(){_0x95e617({'val':_0x8a990e[_0x9495('0x21')]});});}});}function splitAdditionalPhone(_0x8fa430,_0xf3bf59){return new Promise(function(_0x5aee3f,_0x4087d9){var _0x5751c4=_0xf3bf59[_0x9495('0x20')](':');var _0x195dc6=_0x5751c4[0x0];var _0x3d1ea7=_0x5751c4[0x1];if(_0x3d1ea7!==''){var _0x1e200d=_0x3d1ea7[_0x9495('0x20')]('|');var _0x371eea=[];for(var _0xaa5ab4=0x0;_0xaa5ab4<_0x1e200d[_0x9495('0x21')];_0xaa5ab4++){if(_0x1e200d[_0xaa5ab4]!==''){var _0x535e24=_[_0x9495('0x23')](promisesAdditionalPhones,{'contactId':_0x8fa430,'phone':_0x1e200d[_0xaa5ab4]});if(_0x535e24[_0x9495('0x21')]==0x0){orderBy++;promisesAdditionalPhones[_0x9495('0x1d')]({'contactId':_0x8fa430,'contactTypeId':_0x195dc6,'phone':_0x1e200d[_0xaa5ab4],'orderBy':orderBy});}}}_0x5aee3f({'ok':0x1});}else _0x5aee3f({'res':0x0});});}function createAdditionalPhone(_0x23b5e7,_0x5ee329,_0xbaa782,_0x36aac0){var _0x8f20ad='';var _0x5f3d6e='';var _0x42761e=_0xbaa782[_0x9495('0x20')]('§');_0x8f20ad=_0x42761e[0x0];if(_0x42761e[_0x9495('0x21')]==0x2)_0x5f3d6e=_0x42761e[0x1];return new Promise(function(_0xbd2d2f,_0xcbfbee){return db[_0x9495('0x24')][_0x9495('0x25')]({'where':{'CmContactId':_0x23b5e7,'item':_0x8f20ad}})['then'](function(_0x3f6df9){if(_0x3f6df9){return db[_0x9495('0x24')][_0x9495('0x26')]({'ItemTypeId':_0x5ee329,'description':_0x5f3d6e,'OrderBy':_0x36aac0},{'where':{'CmContactId':_0x23b5e7,'item':_0x8f20ad}})[_0x9495('0x22')](function(_0x520f71){_0xbd2d2f({'res':_0x9495('0x27')});});}else{return db[_0x9495('0x24')][_0x9495('0x28')]({'CmContactId':_0x23b5e7,'item':_0x8f20ad,'ItemTypeId':_0x5ee329,'description':_0x5f3d6e,'OrderBy':_0x36aac0,'ItemClass':'PHONE'})[_0x9495('0x22')](function(_0x5830a5){_0xbd2d2f({'res':'inserted'});});}});});}function updateContact(_0x5370ac){return new Promise(function(_0x349db8,_0x231621){var _0x167a1d=_0x5370ac['id'];delete _0x5370ac['id'];return db[_0x9495('0x29')][_0x9495('0x26')](_0x5370ac,{'where':{'id':_0x167a1d}})[_0x9495('0x22')](function(_0x3f724e){updatedRows+=0x1;return db[_0x9495('0x2a')][_0x9495('0x26')]({'phone':_0x5370ac[_0x9495('0x11')]},{'where':{'ContactId':_0x167a1d}})[_0x9495('0x22')](function(_0x2a52fd){_0x349db8({'ret':'OK'});});});});}function insertCmHopper(_0x1e151a,_0x4cc7fe,_0x13824b,_0x347119,_0x9d9b31){var _0x37c6aa=[_0x9495('0x2b'),_0x9495('0x2c'),_0x9495('0x2d'),'cm_contacts.ListId',_0x4cc7fe+'.'+_0x347119,'cm_contacts.createdAt',_0x9495('0x2e'),_0x9495('0x2f'),'cm_contacts.UserId','\x22'+_0x9d9b31+'\x22'];return squel[_0x9495('0x30')]()[_0x9495('0x31')]('cm_hopper')[_0x9495('0x32')]([_0x9495('0x11'),'scheduledat',_0x9495('0x33'),_0x9495('0x34'),_0x347119,_0x9495('0x35'),'updatedAt',_0x9495('0x36'),_0x9495('0x37'),_0x9495('0x38')],squel[_0x9495('0xf')]()[_0x9495('0x39')](_0x37c6aa)[_0x9495('0x12')](_0x4cc7fe)['join'](_0x9495('0x3a'),null,_0x9495('0x3b')+_0x4cc7fe+_0x9495('0x3c'))['join'](_0x13824b,null,_0x13824b+_0x9495('0x14')+_0x4cc7fe+'.'+_0x347119)[_0x9495('0x15')](_0x4cc7fe+_0x9495('0x3d'),_0x1e151a)[_0x9495('0x15')](_0x9495('0x3e'),NOW)[_0x9495('0x15')](_0x9495('0x3f'),selectNotIn(_0x4cc7fe,_0x13824b,_0x347119,_0x9495('0x40'),['\x22always\x22',_0x9495('0x41')]))[_0x9495('0x15')](_0x9495('0x3f'),selectNotIn(_0x4cc7fe,_0x13824b,_0x347119,'cm_hopper',[_0x9495('0x42')])))[_0x9495('0x43')]();}function insertCmHopperBlack(_0x3f3af7,_0x3e2312,_0x49a9e9,_0x3fdf94){var _0x3ea2c2=[_0x9495('0x2b'),_0x9495('0x2d'),_0x9495('0x44'),_0x3e2312+'.'+_0x3fdf94,_0x9495('0x45'),_0x9495('0x2e')];return squel[_0x9495('0x30')]()[_0x9495('0x31')](_0x9495('0x46'))['fromQuery']([_0x9495('0x11'),_0x9495('0x33'),_0x9495('0x34'),_0x3fdf94,_0x9495('0x35'),_0x9495('0x47')],squel['select']()[_0x9495('0x39')](_0x3ea2c2)[_0x9495('0x12')](_0x3e2312)[_0x9495('0x13')](_0x9495('0x3a'),null,_0x9495('0x3b')+_0x3e2312+'.CmListId')[_0x9495('0x13')](_0x49a9e9,null,_0x49a9e9+_0x9495('0x14')+_0x3e2312+'.'+_0x3fdf94)['where'](_0x3e2312+_0x9495('0x3d'),_0x3f3af7)[_0x9495('0x15')]('cm_contacts.createdAt\x20=\x20?',NOW)['where']('cm_contacts.phone\x20NOT\x20IN\x20(?)',squel['select']()[_0x9495('0x10')](_0x9495('0x11'))[_0x9495('0x12')](_0x9495('0x46'))[_0x9495('0x15')](_0x9495('0x48'),_0x3f3af7)[_0x9495('0x15')](_0x3fdf94+'\x20=\x20?',_0x3e2312+'.'+_0x3fdf94)))[_0x9495('0x43')]();}function insertCmHopperAdditionalPhones(_0x7b3c2c){var _0xca58e2=[_0x9495('0x49'),'cm_contact_has_items.item',_0x9495('0x4a'),'cm_contact_has_items.createdAt',_0x9495('0x4b')];return squel[_0x9495('0x30')]()['into']('cm_hopper_additional_phones')[_0x9495('0x32')]([_0x9495('0x4c'),'phone',_0x9495('0x4d'),_0x9495('0x35'),_0x9495('0x47')],squel[_0x9495('0xf')]()['fields'](_0xca58e2)['from']('cm_hopper')[_0x9495('0x13')](_0x9495('0x3a'),null,_0x9495('0x4e'))[_0x9495('0x13')](_0x9495('0x4f'),null,'cm_contacts.id\x20=\x20cm_contact_has_items.CmContactId')['where'](_0x9495('0x50'),_0x7b3c2c)['where'](_0x9495('0x3e'),NOW))[_0x9495('0x43')]();}function insertCmContact(_0xaade15,_0x220446,_0x4a52b3,_0x2e519f){var _0x148b29=_[_0x9495('0x51')](_[_0x9495('0x52')](_0x2e519f),[_0x9495('0x34'),'CompanyId','createdAt','updatedAt']);return squel[_0x9495('0x30')]()[_0x9495('0x31')]('cm_contacts')['fromQuery'](_0x148b29,squel[_0x9495('0xf')]()[_0x9495('0x39')](_0x148b29)['from'](_0x220446)['where']('('+_0x4a52b3['join'](',')+_0x9495('0x53'),squel[_0x9495('0xf')]()[_0x9495('0x39')](_0x4a52b3)['from'](_0x9495('0x3a'))[_0x9495('0x15')](_0x9495('0x48'),_0xaade15))['where']('id\x20IN\x20?',squel['select']()[_0x9495('0x10')](_0x9495('0x54'),'min_id')[_0x9495('0x12')](_0x220446)[_0x9495('0x55')](_0x4a52b3[_0x9495('0x13')](','))))['toString']();}function handleStop(){logger[_0x9495('0x56')](_0x9495('0x57'));stopped=!![];}function handleUncaughtException(_0x2b8fd0){logger[_0x9495('0x58')](_0x2b8fd0[_0x9495('0x1f')]);process[_0x9495('0x59')](0x1);}function handleError(_0x315d1d,_0x78ec36){stats[_0x9495('0x5a')][_0x9495('0x1d')]({'name':_0x78ec36[_0x9495('0x5b')],'message':_0x78ec36[_0x9495('0x1f')],'row':_0x315d1d});}function handleQuery(_0x32adf6){logger[_0x9495('0x56')](_0x32adf6);return db[_0x9495('0x18')][_0x9495('0x5c')](_0x32adf6)[_0x9495('0x1a')](function(_0x5f4a7a){results['push'](_0x5f4a7a);})[_0x9495('0x5d')](function(_0x3ab1a1){logger[_0x9495('0x58')](_0x3ab1a1[_0x9495('0x1f')]);});}function main(_0x6986c1,_0x4a2a0f,_0x2f0456,_0xee8656){logger['info'](_0x9495('0x5e'),_0x6986c1,JSON[_0x9495('0x5f')](_0x4a2a0f));process['send']('start');var _0x4dfeb0=_0x4a2a0f['binding'];var _0x92b4ed=_[_0x9495('0x60')](_0x4dfeb0);var _0x3da4d3=_0x4a2a0f[_0x9495('0x61')];var _0x3688ba=path['join'](config[_0x9495('0x62')],_0x9495('0x63'),_0x3da4d3+'.csv');logger[_0x9495('0x56')](_0x9495('0x64'),_0x4a2a0f);db[_0x9495('0x65')][_0x9495('0x66')]({'raw':!![],'attributes':['id',_0x9495('0x67')]})[_0x9495('0x22')](function(_0x35b925){for(var _0x561592=0x0;_0x561592<_0x35b925[_0x9495('0x21')];_0x561592++){if(_0x35b925[_0x561592][_0x9495('0x67')]in _0x4dfeb0){contactItemTypes['push'](_0x35b925[_0x561592]);delete _0x92b4ed[_0x35b925[_0x561592][_0x9495('0x67')]];hasAdditionalPhones=!![];}for(var _0x2b7552 in _0x4dfeb0){if(_0x35b925[_0x561592][_0x9495('0x67')]+_0x9495('0x68')===_0x2b7552){phoneDescriptions[_0x9495('0x1d')]({'itemTypeId':_0x35b925[_0x561592]['id'],'description':_0x2b7552});delete _0x92b4ed[_0x2b7552];}}}if(hasAdditionalPhones)_0x92b4ed['AdditionalPhones']='';var _0x410038=_[_0x9495('0x52')](_0x92b4ed)[_0x9495('0x13')]();logger[_0x9495('0x56')](_0x9495('0x69'),_0x410038);fs[_0x9495('0x6a')](_0x3688ba,_0x410038+'\x0a');Papa[_0x9495('0x6b')](fs[_0x9495('0x6c')](_0x6986c1),{'header':!![],'skipEmptyLines':!![],'step':function(_0x505794,_0x35d547){try{for(var _0x38ede0=0x0,_0x222601=[];_0x38ede0<_0x505794['data'][_0x9495('0x21')];_0x38ede0++){stats['rows']+=0x1;if(_0x505794[_0x9495('0x5a')][_0x38ede0]){handleError(_0x505794[_0x9495('0x6d')][_0x38ede0],_0x505794['errors'][_0x38ede0]);}else{var _0x38a36d=[];var _0x2d0051=[];var _0x26692b={};for(var _0x3b0ecd in _0x4dfeb0){let _0x34a449=contactItemTypes[_0x9495('0x6e')](_0x3c87a4=>_0x3c87a4[_0x9495('0x67')]===_0x3b0ecd);let _0x2a9521=contactItemTypes[_0x9495('0x6e')](_0x1acc95=>_0x1acc95['name']+_0x9495('0x68')===_0x3b0ecd);if(_['isNil'](_0x34a449)&&_[_0x9495('0x1b')](_0x2a9521)){if(_0x4dfeb0[_0x9495('0x6f')](_0x3b0ecd)){if(_0x505794[_0x9495('0x6d')][_0x38ede0][_0x4dfeb0[_0x3b0ecd]]){var _0x1cd985=_['trim'](_0x505794[_0x9495('0x6d')][_0x38ede0][_0x4dfeb0[_0x3b0ecd]][_0x9495('0x70')](/"/g,'\x27'));switch(_0x3b0ecd){case _0x9495('0x71'):var _0x7264e6=moment(_0x1cd985,_0x9495('0xd'),!![]);if(_0x7264e6[_0x9495('0x72')]()){_0x222601[_0x9495('0x1d')]('\x22'+_0x1cd985+'\x22');}else{_0x38a36d['push'](_0x9495('0x73'));}break;case _0x9495('0x36'):var _0x1af7c4=parseInt(_0x1cd985);_0x1cd985=_[_0x9495('0x74')](_0x1af7c4)||_0x1af7c4<0x0||_0x1af7c4>0x4?_0xee8656?0x3:0x2:_0x1af7c4;_0x222601[_0x9495('0x1d')]('\x22'+_0x1cd985+'\x22');break;case _0x9495('0x37'):var _0x16897a=parseInt(_0x1cd985);if(_[_0x9495('0x75')](_0x16897a)&&_[_0x9495('0x76')](_0x2f0456,_0x16897a)){_0x222601[_0x9495('0x1d')]('\x22'+_0x16897a+'\x22');}else{_0x38a36d[_0x9495('0x1d')]('agent\x20not\x20exists');}break;case'email':if(isEmail(_0x1cd985)){_0x222601[_0x9495('0x1d')]('\x22'+_0x1cd985+'\x22');}else{_0x38a36d[_0x9495('0x1d')](_0x9495('0x77'));}break;case _0x9495('0x78'):var _0x166e8f=moment(_0x1cd985,_0x9495('0x79'),!![]);if(_0x166e8f[_0x9495('0x72')]()){_0x222601['push']('\x22'+_0x1cd985+'\x22');}else{_0x38a36d[_0x9495('0x1d')]('dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)');}break;default:_0x222601['push']('\x22'+_0x1cd985+'\x22');}}else{switch(_0x3b0ecd){case _0x9495('0x7a'):case'phone':_0x38a36d[_0x9495('0x1d')](_0x3b0ecd+'\x20not\x20specified');break;default:_0x222601[_0x9495('0x1d')]('\x22\x22');}}}}else{var _0x32e5f3='';if(!_[_0x9495('0x1b')](_0x34a449)){if(!_0x26692b[_0x9495('0x6f')](_0x34a449['id'])){for(var _0x1b6536=0x0;_0x1b6536<_0x4dfeb0[_0x3b0ecd][_0x9495('0x21')];_0x1b6536++){var _0x1cd985=_['trim'](_0x505794[_0x9495('0x6d')][_0x38ede0][_0x4dfeb0[_0x3b0ecd][_0x1b6536]][_0x9495('0x70')](/"/g,'\x27'));var _0x447f7a=phoneDescriptions[_0x9495('0x6e')](_0x49d0ad=>_0x49d0ad[_0x9495('0x7b')]===_0x34a449['id']);if(!_[_0x9495('0x1b')](_0x447f7a)){var _0xd1d6dd=_[_0x9495('0x7c')](_0x505794[_0x9495('0x6d')][_0x38ede0][_0x4dfeb0[_0x447f7a[_0x9495('0x7d')]][0x0]][_0x9495('0x70')](/"/g,'\x27'));if(!_['isNil'](_0xd1d6dd))_0x1cd985=_0x1cd985+'§'+_0xd1d6dd;}if(_0x32e5f3=='')_0x32e5f3=_0x1cd985;else _0x32e5f3+='|'+_0x1cd985;}_0x2d0051[_0x9495('0x1d')](_0x34a449['id']+':'+_0x32e5f3);_0x26692b[_0x34a449['id']]=0x1;}}}}if(hasAdditionalPhones){_0x222601[_0x9495('0x1d')]('\x22'+_0x2d0051[_0x9495('0x13')](';')+'\x22');}if(_0x38a36d[_0x9495('0x21')]){handleError(_0x505794['data'][_0x38ede0],{'code':_0x9495('0x7e'),'message':_0x38a36d[_0x9495('0x13')]()});}else{fs['appendFileSync'](_0x3688ba,_0x222601[_0x9495('0x13')]()+'\x0a');}_0x222601=[];}if(!(stats[_0x9495('0x7f')]%0xc8)){socket['emit'](_0x9495('0x80')+_0x3da4d3,stats);stats[_0x9495('0x5a')]=[];}}if(stopped){logger[_0x9495('0x56')](_0x9495('0x81'));_0x35d547[_0x9495('0x82')]();}}catch(_0x24049b){handleError(_0x505794[_0x9495('0x6d')][_0x38ede0],{'code':_0x9495('0x83'),'message':_0x24049b[_0x9495('0x1f')]});logger[_0x9495('0x58')](_0x9495('0x84'),_0x24049b[_0x9495('0x1f')]);}},'complete':function(){try{var _0x1fc709=[];var _0x2c6782=tempTableName;_0x1fc709[_0x9495('0x1d')]('CREATE\x20TABLE\x20'+_0x2c6782+_0x9495('0x85'));logger[_0x9495('0x56')]('CIS\x20len',contactItemTypes[_0x9495('0x21')]);var _0x4716d7=util[_0x9495('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\x20ListId\x20=\x20%s,\x20CompanyId\x20=\x20%s,\x20createdAt\x20=\x20\x27%s\x27,\x20updatedAt\x20=\x20\x27%s\x27',_0x3688ba,_0x2c6782,_0x410038,_0x4a2a0f[_0x9495('0x34')],_0x4a2a0f[_0x9495('0x86')]||null,NOW,NOW);if(_[_0x9495('0x1b')](_0x4dfeb0[_0x9495('0x71')])){_0x4716d7+=_0x9495('0x87');}_0x1fc709[_0x9495('0x1d')](_0x4716d7);BPromise[_0x9495('0x88')](_0x1fc709,handleQuery)[_0x9495('0x22')](function(_0x47dc90){BPromise[_0x9495('0x1e')]([handleAdditionalPhones()])[_0x9495('0x22')](function(){_0x1fc709=[];for(var _0x5ae053=0x0;_0x5ae053<promisesContact[_0x9495('0x21')];_0x5ae053++){_0x1fc709[_0x9495('0x1d')](updateContact(promisesContact[_0x5ae053][_0x9495('0x89')]));}BPromise['all'](_0x1fc709)[_0x9495('0x22')](function(){_0x1fc709=[];for(var _0xf284f1=0x0;_0xf284f1<promisesAdditionalPhones[_0x9495('0x21')];_0xf284f1++){_0x1fc709[_0x9495('0x1d')](createAdditionalPhone(promisesAdditionalPhones[_0xf284f1][_0x9495('0x8a')],promisesAdditionalPhones[_0xf284f1][_0x9495('0x8b')],promisesAdditionalPhones[_0xf284f1][_0x9495('0x11')],promisesAdditionalPhones[_0xf284f1][_0x9495('0x8c')]));}BPromise[_0x9495('0x1e')](_0x1fc709)[_0x9495('0x22')](function(){_0x1fc709=[];_0x1fc709[_0x9495('0x1d')](insertCmHopperAdditionalPhones(_0x4a2a0f['ListId']));_0x1fc709[_0x9495('0x1d')]('DROP\x20TABLE\x20'+_0x2c6782+';');BPromise['each'](_0x1fc709,handleQuery)[_0x9495('0x22')](function(_0x4cc1b0){stats['finish']=!![];stats[_0x9495('0x8d')]=updatedRows;socket[_0x9495('0x8e')](_0x9495('0x80')+_0x3da4d3,stats);fs[_0x9495('0x8f')](_0x6986c1);fs['unlink'](_0x3688ba);process[_0x9495('0x59')](0x0);})['catch'](function(_0xcf9e21){logger['error'](_0xcf9e21[_0x9495('0x1f')]);process[_0x9495('0x59')](0x1);});});});});})[_0x9495('0x5d')](function(_0x2310e1){logger[_0x9495('0x58')](_0x2310e1[_0x9495('0x1f')]);process[_0x9495('0x59')](0x1);});}catch(_0xbb3e25){logger[_0x9495('0x58')](_0x9495('0x90'),_0xbb3e25[_0x9495('0x1f')]);process[_0x9495('0x59')](0x1);}},'error':function(_0x96b8b4,_0x11b8c3,_0x25c2a5,_0x3030ac){throw new Error(_0x3030ac);}});});}function validate(){if(process[_0x9495('0x91')]&&process[_0x9495('0x91')][_0x9495('0x21')]<0x4){throw new Error(_0x9495('0x92'));}var _0x35758e=path[_0x9495('0x13')](config[_0x9495('0x62')],'server/files/tmp',process[_0x9495('0x91')][0x2]);if(!fs[_0x9495('0x93')](_0x35758e)){throw new Error('file\x20doesn\x27t\x20exists');}var _0x3f629b={};try{_0x3f629b=JSON[_0x9495('0x6b')](process['argv'][0x3]);if(!_0x3f629b[_0x9495('0x94')]){throw new Error('binding\x20doesn\x27t\x20exists');}var _0x1ab41f=0x0;if(_0x3f629b[_0x9495('0x94')][_0x9495('0x37')]){_0x1ab41f=0x1;}if(!_0x3f629b[_0x9495('0x34')]){throw new Error(_0x9495('0x95'));}}catch(_0x55fe26){throw new Error(_0x9495('0x96'));}var _0x30ed03=[];try{_0x30ed03=_[_0x9495('0x97')](JSON[_0x9495('0x6b')](process[_0x9495('0x91')][0x4]),'id');}catch(_0x5bd185){logger[_0x9495('0x56')](_0x9495('0x98'));}main(_0x35758e,_0x3f629b,_0x30ed03,_0x1ab41f);}validate();process['on'](_0x9495('0x99'),handleStop);process['on'](_0x9495('0x9a'),handleUncaughtException);