Built motion from commit (unavailable).|2.5.23
[motion2.git] / server / components / export / csv.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 _0xf3cd=['SELECT','num','Empty','length','push','query','%s\x20limit\x20%d\x20OFFSET\x20%d','QueryTypes','dirname','basename','.csv','existsSync','join','mkdirSync','each','writeFileSync','%s.%s','zip','Extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format\x20completed','Completed','csv','Error\x20during\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','inspect','Failed','util','path','lodash','to-csv','bluebird','zip-dir','../../mysqldb','dbH','analytics','argv','update','info','format','Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','CSV','Setting','find','split','splitSizeCsv','then','sequelize','SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t'];(function(_0x39f96e,_0x55b9bc){var _0x55b927=function(_0x225f82){while(--_0x225f82){_0x39f96e['push'](_0x39f96e['shift']());}};_0x55b927(++_0x55b9bc);}(_0xf3cd,0xfe));var _0xdf3c=function(_0x55f8b4,_0x43f30d){_0x55f8b4=_0x55f8b4-0x0;var _0x2475f9=_0xf3cd[_0x55f8b4];return _0x2475f9;};'use strict';var util=require(_0xdf3c('0x0'));var path=require(_0xdf3c('0x1'));var _=require(_0xdf3c('0x2'));var csv=require(_0xdf3c('0x3'));var fs=require('fs');var BPromise=require(_0xdf3c('0x4'));var zipdir=require(_0xdf3c('0x5'));var rimraf=require('rimraf');var db=require(_0xdf3c('0x6'))['db'];var dbH=require(_0xdf3c('0x6'))[_0xdf3c('0x7')];var logger=require('../../config/logger')(_0xdf3c('0x8'));var EXTRACTED_REPORT_ID=Number(process[_0xdf3c('0x9')][0x2]);var QUERY=process[_0xdf3c('0x9')][0x3];var PATH=process[_0xdf3c('0x9')][0x4];function analyticExtractedReport(_0x106021,_0x28edae){var _0x52c073={'status':_0x106021};var _0x15705d={'where':{'id':EXTRACTED_REPORT_ID}};if(_0x28edae){_0x52c073['savename']=_0x28edae;}return db['AnalyticExtractedReport'][_0xdf3c('0xa')](_0x52c073,_0x15705d);}function main(){var _0x981616=0x1388;var _0x5ef936;logger[_0xdf3c('0xb')](util[_0xdf3c('0xc')](_0xdf3c('0xd'),EXTRACTED_REPORT_ID,_0xdf3c('0xe')));return db[_0xdf3c('0xf')][_0xdf3c('0x10')]({'where':{'id':0x1},'raw':!![],'attributes':['id',_0xdf3c('0x11'),_0xdf3c('0x12')]})['then'](function(_0x1d483c){if(_0x1d483c){_0x5ef936=_0x1d483c;_0x981616=_0x5ef936[_0xdf3c('0x12')]||0x1388;}})[_0xdf3c('0x13')](function(){return dbH[_0xdf3c('0x14')]['query'](util[_0xdf3c('0xc')](_0xdf3c('0x15'),QUERY),{'type':dbH[_0xdf3c('0x14')]['QueryTypes'][_0xdf3c('0x16')]});})[_0xdf3c('0x13')](function(_0x173041){if(!_0x173041[0x0][_0xdf3c('0x17')]){return analyticExtractedReport(_0xdf3c('0x18'));}var _0x1a7a5a=[];var _0x305ea5=0x0;var _0x92008b=!![];if(_0x173041&&_0x173041[_0xdf3c('0x19')]){var _0x5d3991=_0x173041[0x0]['num']%(_0x305ea5+_0x981616);if(_0x5ef936[_0xdf3c('0x11')]){for(;_0x92008b;_0x305ea5+=_0x981616,_0x5d3991=_0x173041[0x0][_0xdf3c('0x17')]%(_0x305ea5+_0x981616)){if(_0x5d3991==0x0||_0x5d3991==_0x173041[0x0][_0xdf3c('0x17')]){_0x92008b=![];}_0x1a7a5a[_0xdf3c('0x1a')](dbH[_0xdf3c('0x14')][_0xdf3c('0x1b')](util[_0xdf3c('0xc')](_0xdf3c('0x1c'),QUERY,_0x981616,_0x305ea5),{'type':dbH[_0xdf3c('0x14')][_0xdf3c('0x1d')][_0xdf3c('0x16')]}));}}else{_0x1a7a5a[_0xdf3c('0x1a')](dbH[_0xdf3c('0x14')]['query'](QUERY,{'type':dbH['sequelize'][_0xdf3c('0x1d')]['SELECT']}));}}var _0x15776c=path[_0xdf3c('0x1e')](PATH);var _0x36552e=path[_0xdf3c('0x1f')](PATH,_0xdf3c('0x20'));var _0x36ba1c=_0x5ef936['split']&&_0x1a7a5a[_0xdf3c('0x19')]>0x1;var _0x213d75=[];if(!fs[_0xdf3c('0x21')](path[_0xdf3c('0x22')](_0x15776c,_0x36552e))&&_0x36ba1c){fs[_0xdf3c('0x23')](path[_0xdf3c('0x22')](_0x15776c,_0x36552e));}return BPromise[_0xdf3c('0x24')](_0x1a7a5a,function(_0x155f54){_0x213d75[_0xdf3c('0x1a')](_0x155f54);})[_0xdf3c('0x13')](function(){for(var _0x4c076c=0x0;_0x4c076c<_0x213d75[_0xdf3c('0x19')];_0x4c076c+=0x1){var _0x153daa;var _0x4b57a4=_0x213d75[_0x4c076c];if(_0x36ba1c){_0x153daa=path[_0xdf3c('0x22')](_0x15776c,_0x36552e,util['format']('%s%d.%s',_0x36552e,_0x4c076c,'csv'));}else{_0x153daa=path[_0xdf3c('0x22')](_0x15776c,util[_0xdf3c('0xc')]('%s.%s',_0x36552e,'csv'));}fs[_0xdf3c('0x25')](_0x153daa,csv(_0x4b57a4));}})[_0xdf3c('0x13')](function(){if(_0x36ba1c){zipdir(path[_0xdf3c('0x22')](_0x15776c,_0x36552e),{'saveTo':path[_0xdf3c('0x22')](_0x15776c,util['format'](_0xdf3c('0x26'),_0x36552e,_0xdf3c('0x27')))},function(_0x5386bf,_0x51e0a4){});rimraf(path[_0xdf3c('0x22')](_0x15776c,_0x36552e),function(){});}})[_0xdf3c('0x13')](function(){logger[_0xdf3c('0xb')](util['format'](_0xdf3c('0x28'),EXTRACTED_REPORT_ID,_0xdf3c('0xe')));return analyticExtractedReport(_0xdf3c('0x29'),_0x36ba1c?util[_0xdf3c('0xc')]('%s.%s',_0x36552e,_0x36ba1c?_0xdf3c('0x27'):_0xdf3c('0x2a')):null);});})['catch'](function(_0x40ae3d){logger[_0xdf3c('0xb')](util[_0xdf3c('0xc')](_0xdf3c('0x2b'),EXTRACTED_REPORT_ID,'CSV'),util[_0xdf3c('0x2c')](_0x40ae3d,{'showHidden':![],'depth':null}));return analyticExtractedReport(_0xdf3c('0x2d'));});}main();