Built motion from commit ab870f9e.|2.5.44
[motion2.git] / server / components / export / csv.js
index 1b2b2df..a664140 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x99e9=['rimraf','../../mysqldb','../../config/logger','argv','savename','AnalyticExtractedReport','update','info','format','Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','CSV','Setting','find','split','splitSizeCsv','then','query','SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t','QueryTypes','Empty','length','num','push','sequelize','%s\x20limit\x20%d\x20OFFSET\x20%d','SELECT','dirname','basename','existsSync','join','mkdirSync','each','csv','%s.%s','writeFileSync','zip','Extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format\x20completed','Completed','catch','Error\x20during\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','inspect','Failed','path','lodash','to-csv','bluebird'];(function(_0x5d0746,_0x511b2d){var _0x19a392=function(_0x111382){while(--_0x111382){_0x5d0746['push'](_0x5d0746['shift']());}};_0x19a392(++_0x511b2d);}(_0x99e9,0xb4));var _0x999e=function(_0x54fbff,_0x53470e){_0x54fbff=_0x54fbff-0x0;var _0x5cf619=_0x99e9[_0x54fbff];return _0x5cf619;};'use strict';var util=require('util');var path=require(_0x999e('0x0'));var _=require(_0x999e('0x1'));var csv=require(_0x999e('0x2'));var fs=require('fs');var BPromise=require(_0x999e('0x3'));var zipdir=require('zip-dir');var rimraf=require(_0x999e('0x4'));var db=require(_0x999e('0x5'))['db'];var dbH=require(_0x999e('0x5'))['dbH'];var logger=require(_0x999e('0x6'))('analytics');var EXTRACTED_REPORT_ID=Number(process[_0x999e('0x7')][0x2]);var QUERY=process[_0x999e('0x7')][0x3];var PATH=process[_0x999e('0x7')][0x4];function analyticExtractedReport(_0x18f337,_0x5c1c17){var _0x46aeae={'status':_0x18f337};var _0x38a692={'where':{'id':EXTRACTED_REPORT_ID}};if(_0x5c1c17){_0x46aeae[_0x999e('0x8')]=_0x5c1c17;}return db[_0x999e('0x9')][_0x999e('0xa')](_0x46aeae,_0x38a692);}function main(){var _0x175042=0x1388;var _0x3f2c24;logger[_0x999e('0xb')](util[_0x999e('0xc')](_0x999e('0xd'),EXTRACTED_REPORT_ID,_0x999e('0xe')));return db[_0x999e('0xf')][_0x999e('0x10')]({'where':{'id':0x1},'raw':!![],'attributes':['id',_0x999e('0x11'),_0x999e('0x12')]})[_0x999e('0x13')](function(_0x26b55a){if(_0x26b55a){_0x3f2c24=_0x26b55a;_0x175042=_0x3f2c24['splitSizeCsv']||0x1388;}})[_0x999e('0x13')](function(){return dbH['sequelize'][_0x999e('0x14')](util[_0x999e('0xc')](_0x999e('0x15'),QUERY),{'type':dbH['sequelize'][_0x999e('0x16')]['SELECT']});})[_0x999e('0x13')](function(_0x539598){if(!_0x539598[0x0]['num']){return analyticExtractedReport(_0x999e('0x17'));}var _0x22feac=[];var _0x2dd5f4=0x0;var _0x289e0e=!![];if(_0x539598&&_0x539598[_0x999e('0x18')]){var _0x39ce36=_0x539598[0x0]['num']%(_0x2dd5f4+_0x175042);if(_0x3f2c24['split']){for(;_0x289e0e;_0x2dd5f4+=_0x175042,_0x39ce36=_0x539598[0x0]['num']%(_0x2dd5f4+_0x175042)){if(_0x39ce36==0x0||_0x39ce36==_0x539598[0x0][_0x999e('0x19')]){_0x289e0e=![];}_0x22feac[_0x999e('0x1a')](dbH[_0x999e('0x1b')][_0x999e('0x14')](util[_0x999e('0xc')](_0x999e('0x1c'),QUERY,_0x175042,_0x2dd5f4),{'type':dbH['sequelize']['QueryTypes'][_0x999e('0x1d')]}));}}else{_0x22feac[_0x999e('0x1a')](dbH[_0x999e('0x1b')]['query'](QUERY,{'type':dbH[_0x999e('0x1b')][_0x999e('0x16')][_0x999e('0x1d')]}));}}var _0x36fce4=path[_0x999e('0x1e')](PATH);var _0x3750a0=path[_0x999e('0x1f')](PATH,'.csv');var _0x54ad83=_0x3f2c24[_0x999e('0x11')]&&_0x22feac[_0x999e('0x18')]>0x1;var _0x4c5491=[];if(!fs[_0x999e('0x20')](path[_0x999e('0x21')](_0x36fce4,_0x3750a0))&&_0x54ad83){fs[_0x999e('0x22')](path[_0x999e('0x21')](_0x36fce4,_0x3750a0));}return BPromise[_0x999e('0x23')](_0x22feac,function(_0x320634){_0x4c5491['push'](_0x320634);})[_0x999e('0x13')](function(){for(var _0x4199ff=0x0;_0x4199ff<_0x4c5491[_0x999e('0x18')];_0x4199ff+=0x1){var _0x12b9ad;var _0x1b7adb=_0x4c5491[_0x4199ff];if(_0x54ad83){_0x12b9ad=path[_0x999e('0x21')](_0x36fce4,_0x3750a0,util[_0x999e('0xc')]('%s%d.%s',_0x3750a0,_0x4199ff,_0x999e('0x24')));}else{_0x12b9ad=path['join'](_0x36fce4,util['format'](_0x999e('0x25'),_0x3750a0,_0x999e('0x24')));}fs[_0x999e('0x26')](_0x12b9ad,csv(_0x1b7adb));}})['then'](function(){if(_0x54ad83){zipdir(path[_0x999e('0x21')](_0x36fce4,_0x3750a0),{'saveTo':path[_0x999e('0x21')](_0x36fce4,util[_0x999e('0xc')](_0x999e('0x25'),_0x3750a0,_0x999e('0x27')))},function(_0x327079,_0x82e067){});rimraf(path[_0x999e('0x21')](_0x36fce4,_0x3750a0),function(){});}})[_0x999e('0x13')](function(){logger[_0x999e('0xb')](util['format'](_0x999e('0x28'),EXTRACTED_REPORT_ID,_0x999e('0xe')));return analyticExtractedReport(_0x999e('0x29'),_0x54ad83?util['format'](_0x999e('0x25'),_0x3750a0,_0x54ad83?'zip':'csv'):null);});})[_0x999e('0x2a')](function(_0x332195){logger['info'](util['format'](_0x999e('0x2b'),EXTRACTED_REPORT_ID,_0x999e('0xe')),util[_0x999e('0x2c')](_0x332195,{'showHidden':![],'depth':null}));return analyticExtractedReport(_0x999e('0x2d'));});}main();
\ No newline at end of file
+var _0x4f3e=['then','query','SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t','QueryTypes','SELECT','num','Empty','length','range','forEach','push','%s\x20limit\x20%d\x20OFFSET\x20%d','sequelize','dirname','.csv','existsSync','join','mkdirSync','each','%s%d.%s','writeFileSync','zip','CSV','Completed','csv','Error\x20during\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','inspect','Failed','finally','util','path','lodash','to-csv','zip-dir','../../mysqldb','../../config/logger','analytics','argv','savename','update','info','format','Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','Setting','find','split','splitSizeCsv'];(function(_0x1b2947,_0x2cadb3){var _0x4dc3a9=function(_0x26eff1){while(--_0x26eff1){_0x1b2947['push'](_0x1b2947['shift']());}};_0x4dc3a9(++_0x2cadb3);}(_0x4f3e,0xaa));var _0xe4f3=function(_0x5ec4be,_0xf2bd81){_0x5ec4be=_0x5ec4be-0x0;var _0x31be90=_0x4f3e[_0x5ec4be];return _0x31be90;};'use strict';var util=require(_0xe4f3('0x0'));var path=require(_0xe4f3('0x1'));var _=require(_0xe4f3('0x2'));var csv=require(_0xe4f3('0x3'));var fs=require('fs');var BPromise=require('bluebird');var zipdir=require(_0xe4f3('0x4'));var rimraf=require('rimraf');var db=require(_0xe4f3('0x5'))['db'];var dbH=require(_0xe4f3('0x5'))['dbH'];var logger=require(_0xe4f3('0x6'))(_0xe4f3('0x7'));var EXTRACTED_REPORT_ID=Number(process['argv'][0x2]);var QUERY=process['argv'][0x3];var PATH=process[_0xe4f3('0x8')][0x4];var EXIT_CODE=0x0;function analyticExtractedReport(_0x3871ac,_0xb1a75){var _0x7060cc={'status':_0x3871ac};var _0x16e293={'where':{'id':EXTRACTED_REPORT_ID}};if(_0xb1a75){_0x7060cc[_0xe4f3('0x9')]=_0xb1a75;}return db['AnalyticExtractedReport'][_0xe4f3('0xa')](_0x7060cc,_0x16e293);}function main(){var _0x143b8d=0x1388;var _0x526406;logger[_0xe4f3('0xb')](util[_0xe4f3('0xc')](_0xe4f3('0xd'),EXTRACTED_REPORT_ID,'CSV'));return db[_0xe4f3('0xe')][_0xe4f3('0xf')]({'where':{'id':0x1},'raw':!![],'attributes':['id',_0xe4f3('0x10'),_0xe4f3('0x11')]})[_0xe4f3('0x12')](function(_0x2363ce){if(_0x2363ce){_0x526406=_0x2363ce;_0x143b8d=_0x526406['splitSizeCsv']||0x1388;}})[_0xe4f3('0x12')](function(){return dbH['sequelize'][_0xe4f3('0x13')](util['format'](_0xe4f3('0x14'),QUERY),{'type':dbH['sequelize'][_0xe4f3('0x15')][_0xe4f3('0x16')]});})[_0xe4f3('0x12')](function(_0x4a78c6){if(!_0x4a78c6[0x0][_0xe4f3('0x17')]){return analyticExtractedReport(_0xe4f3('0x18'));}var _0x2c0127=[];var _0x2369fe=0x0;if(_0x526406['split']){if(_0x4a78c6&&_0x4a78c6[_0xe4f3('0x19')]){var _0x539722=_[_0xe4f3('0x1a')](_0x4a78c6[0x0][_0xe4f3('0x17')]/_0x143b8d);var _0x2e6192=Number['isInteger'](_0x4a78c6[0x0][_0xe4f3('0x17')]/_0x143b8d)?_0x4a78c6[0x0][_0xe4f3('0x17')]%_0x143b8d:0x0;_0x539722[_0xe4f3('0x1b')](function(_0x4d217a){if(_0x4d217a>0x0){_0x2369fe+=_0x143b8d;}_0x2c0127[_0xe4f3('0x1c')](dbH['sequelize']['query'](util['format'](_0xe4f3('0x1d'),QUERY,_0x143b8d,_0x2369fe),{'type':dbH[_0xe4f3('0x1e')][_0xe4f3('0x15')][_0xe4f3('0x16')]}));});if(_0x2e6192>0x0){_0x2369fe+=_0x143b8d;_0x2c0127[_0xe4f3('0x1c')](dbH[_0xe4f3('0x1e')]['query'](util['format']('%s\x20limit\x20%d\x20OFFSET\x20%d',QUERY,_0x2e6192,_0x2369fe),{'type':dbH[_0xe4f3('0x1e')][_0xe4f3('0x15')][_0xe4f3('0x16')]}));}}}else{_0x2c0127[_0xe4f3('0x1c')](dbH['sequelize'][_0xe4f3('0x13')](QUERY,{'type':dbH[_0xe4f3('0x1e')][_0xe4f3('0x15')]['SELECT']}));}var _0x1bce9c=path[_0xe4f3('0x1f')](PATH);var _0x3b2217=path['basename'](PATH,_0xe4f3('0x20'));var _0x49bb13=_0x526406[_0xe4f3('0x10')]&&_0x2c0127['length']>0x1;var _0x327c96=[];if(!fs[_0xe4f3('0x21')](path[_0xe4f3('0x22')](_0x1bce9c,_0x3b2217))&&_0x49bb13){fs[_0xe4f3('0x23')](path[_0xe4f3('0x22')](_0x1bce9c,_0x3b2217));}return BPromise[_0xe4f3('0x24')](_0x2c0127,function(_0x4b3cc8){_0x327c96[_0xe4f3('0x1c')](_0x4b3cc8);})['then'](function(){for(var _0x13901b=0x0;_0x13901b<_0x327c96['length'];_0x13901b+=0x1){var _0x302d3b;var _0x3f32e7=_0x327c96[_0x13901b];if(_0x49bb13){_0x302d3b=path[_0xe4f3('0x22')](_0x1bce9c,_0x3b2217,util[_0xe4f3('0xc')](_0xe4f3('0x25'),_0x3b2217,_0x13901b,'csv'));}else{_0x302d3b=path[_0xe4f3('0x22')](_0x1bce9c,util[_0xe4f3('0xc')]('%s.%s',_0x3b2217,'csv'));}fs[_0xe4f3('0x26')](_0x302d3b,csv(_0x3f32e7));}})['then'](function(){if(_0x49bb13){return new Promise(function(_0x5f03da){zipdir(path['join'](_0x1bce9c,_0x3b2217),{'saveTo':path['join'](_0x1bce9c,util[_0xe4f3('0xc')]('%s.%s',_0x3b2217,_0xe4f3('0x27')))},function(_0x532ab8,_0x207dad){rimraf(path[_0xe4f3('0x22')](_0x1bce9c,_0x3b2217),function(){});_0x5f03da('zip\x20finished');});});}})[_0xe4f3('0x12')](function(){logger[_0xe4f3('0xb')](util['format']('Extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format\x20completed',EXTRACTED_REPORT_ID,_0xe4f3('0x28')));return analyticExtractedReport(_0xe4f3('0x29'),_0x49bb13?util['format']('%s.%s',_0x3b2217,_0x49bb13?_0xe4f3('0x27'):_0xe4f3('0x2a')):null);});})['catch'](function(_0x30e1b4){logger['info'](util[_0xe4f3('0xc')](_0xe4f3('0x2b'),EXTRACTED_REPORT_ID,_0xe4f3('0x28')),util[_0xe4f3('0x2c')](_0x30e1b4,{'showHidden':![],'depth':null}));EXIT_CODE=0x1;return analyticExtractedReport(_0xe4f3('0x2d'));})[_0xe4f3('0x2e')](function(){process['exit'](EXIT_CODE);});}main();
\ No newline at end of file