Built motion from commit 639a1a7f.|2.6.19
[motion2.git] / server / components / export / csv.js
index 455f10d..4afecb4 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x507f=['num','forEach','push','SELECT','query','%s\x20limit\x20%d\x20OFFSET\x20%d','QueryTypes','basename','.csv','join','mkdirSync','each','%s%d.%s','csv','%s.%s','writeFileSync','zip','zip\x20finished','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','finally','exit','util','path','lodash','to-csv','bluebird','zip-dir','rimraf','../../mysqldb','dbH','../../config/logger','analytics','argv','savename','AnalyticExtractedReport','update','info','format','CSV','Setting','find','split','then','splitSizeCsv','SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t','sequelize','Empty','length','range'];(function(_0x26a74d,_0x37ecfc){var _0xcbb1a3=function(_0x24b978){while(--_0x24b978){_0x26a74d['push'](_0x26a74d['shift']());}};_0xcbb1a3(++_0x37ecfc);}(_0x507f,0xf2));var _0xf507=function(_0x5b150f,_0x185e99){_0x5b150f=_0x5b150f-0x0;var _0x3a246e=_0x507f[_0x5b150f];return _0x3a246e;};'use strict';var util=require(_0xf507('0x0'));var path=require(_0xf507('0x1'));var _=require(_0xf507('0x2'));var csv=require(_0xf507('0x3'));var fs=require('fs');var BPromise=require(_0xf507('0x4'));var zipdir=require(_0xf507('0x5'));var rimraf=require(_0xf507('0x6'));var db=require('../../mysqldb')['db'];var dbH=require(_0xf507('0x7'))[_0xf507('0x8')];var logger=require(_0xf507('0x9'))(_0xf507('0xa'));var EXTRACTED_REPORT_ID=Number(process['argv'][0x2]);var QUERY=process['argv'][0x3];var PATH=process[_0xf507('0xb')][0x4];var EXIT_CODE=0x0;function analyticExtractedReport(_0x564657,_0x32ff37){var _0x470e10={'status':_0x564657};var _0x513d1f={'where':{'id':EXTRACTED_REPORT_ID}};if(_0x32ff37){_0x470e10[_0xf507('0xc')]=_0x32ff37;}return db[_0xf507('0xd')][_0xf507('0xe')](_0x470e10,_0x513d1f);}function main(){var _0x37b208=0x1388;var _0x40ab89;logger[_0xf507('0xf')](util[_0xf507('0x10')]('Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format',EXTRACTED_REPORT_ID,_0xf507('0x11')));return db[_0xf507('0x12')][_0xf507('0x13')]({'where':{'id':0x1},'raw':!![],'attributes':['id',_0xf507('0x14'),'splitSizeCsv']})[_0xf507('0x15')](function(_0x3f69af){if(_0x3f69af){_0x40ab89=_0x3f69af;_0x37b208=_0x40ab89[_0xf507('0x16')]||0x1388;}})[_0xf507('0x15')](function(){return dbH['sequelize']['query'](util[_0xf507('0x10')](_0xf507('0x17'),QUERY),{'type':dbH[_0xf507('0x18')]['QueryTypes']['SELECT']});})[_0xf507('0x15')](function(_0x511b1e){if(!_0x511b1e[0x0]['num']){return analyticExtractedReport(_0xf507('0x19'));}var _0x90f7a1=[];var _0x82d08b=0x0;if(_0x40ab89[_0xf507('0x14')]){if(_0x511b1e&&_0x511b1e[_0xf507('0x1a')]){var _0xce4bbe=_[_0xf507('0x1b')](_0x511b1e[0x0][_0xf507('0x1c')]/_0x37b208);var _0x1bcccf=Number['isInteger'](_0x511b1e[0x0][_0xf507('0x1c')]/_0x37b208)?_0x511b1e[0x0][_0xf507('0x1c')]%_0x37b208:0x0;_0xce4bbe[_0xf507('0x1d')](function(_0x4ea20a){if(_0x4ea20a>0x0){_0x82d08b+=_0x37b208;}_0x90f7a1[_0xf507('0x1e')](dbH[_0xf507('0x18')]['query'](util[_0xf507('0x10')]('%s\x20limit\x20%d\x20OFFSET\x20%d',QUERY,_0x37b208,_0x82d08b),{'type':dbH[_0xf507('0x18')]['QueryTypes'][_0xf507('0x1f')]}));});if(_0x1bcccf>0x0){_0x82d08b+=_0x37b208;_0x90f7a1[_0xf507('0x1e')](dbH[_0xf507('0x18')][_0xf507('0x20')](util[_0xf507('0x10')](_0xf507('0x21'),QUERY,_0x1bcccf,_0x82d08b),{'type':dbH[_0xf507('0x18')][_0xf507('0x22')][_0xf507('0x1f')]}));}}}else{_0x90f7a1[_0xf507('0x1e')](dbH[_0xf507('0x18')][_0xf507('0x20')](QUERY,{'type':dbH[_0xf507('0x18')]['QueryTypes'][_0xf507('0x1f')]}));}var _0x4e10c9=path['dirname'](PATH);var _0x2dfe5a=path[_0xf507('0x23')](PATH,_0xf507('0x24'));var _0xe15ceb=_0x40ab89['split']&&_0x90f7a1[_0xf507('0x1a')]>0x1;var _0x408c5f=[];if(!fs['existsSync'](path[_0xf507('0x25')](_0x4e10c9,_0x2dfe5a))&&_0xe15ceb){fs[_0xf507('0x26')](path[_0xf507('0x25')](_0x4e10c9,_0x2dfe5a));}return BPromise[_0xf507('0x27')](_0x90f7a1,function(_0x409404){_0x408c5f[_0xf507('0x1e')](_0x409404);})[_0xf507('0x15')](function(){for(var _0x5165e5=0x0;_0x5165e5<_0x408c5f[_0xf507('0x1a')];_0x5165e5+=0x1){var _0x1e02ba;var _0xb30353=_0x408c5f[_0x5165e5];if(_0xe15ceb){_0x1e02ba=path[_0xf507('0x25')](_0x4e10c9,_0x2dfe5a,util[_0xf507('0x10')](_0xf507('0x28'),_0x2dfe5a,_0x5165e5,_0xf507('0x29')));}else{_0x1e02ba=path[_0xf507('0x25')](_0x4e10c9,util['format'](_0xf507('0x2a'),_0x2dfe5a,_0xf507('0x29')));}fs[_0xf507('0x2b')](_0x1e02ba,csv(_0xb30353));}})['then'](function(){if(_0xe15ceb){return new Promise(function(_0x468e2f){zipdir(path[_0xf507('0x25')](_0x4e10c9,_0x2dfe5a),{'saveTo':path[_0xf507('0x25')](_0x4e10c9,util[_0xf507('0x10')](_0xf507('0x2a'),_0x2dfe5a,_0xf507('0x2c')))},function(_0x1063bc,_0x2da4e4){rimraf(path[_0xf507('0x25')](_0x4e10c9,_0x2dfe5a),function(){});_0x468e2f(_0xf507('0x2d'));});});}})[_0xf507('0x15')](function(){logger[_0xf507('0xf')](util['format'](_0xf507('0x2e'),EXTRACTED_REPORT_ID,_0xf507('0x11')));return analyticExtractedReport(_0xf507('0x2f'),_0xe15ceb?util[_0xf507('0x10')](_0xf507('0x2a'),_0x2dfe5a,_0xe15ceb?'zip':'csv'):null);});})[_0xf507('0x30')](function(_0xe78929){logger[_0xf507('0xf')](util[_0xf507('0x10')](_0xf507('0x31'),EXTRACTED_REPORT_ID,_0xf507('0x11')),util[_0xf507('0x32')](_0xe78929,{'showHidden':![],'depth':null}));EXIT_CODE=0x1;return analyticExtractedReport(_0xf507('0x33'));})[_0xf507('0x34')](function(){process[_0xf507('0x35')](EXIT_CODE);});}main();
\ No newline at end of file
+var _0xd61e=['CSV','Setting','find','splitSizeCsv','then','sequelize','query','SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t','num','split','length','range','isInteger','push','%s\x20limit\x20%d\x20OFFSET\x20%d','QueryTypes','SELECT','dirname','basename','.csv','existsSync','join','mkdirSync','each','%s%d.%s','csv','%s.%s','writeFileSync','zip','zip\x20finished','Extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format\x20completed','Error\x20during\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','finally','util','path','lodash','to-csv','bluebird','zip-dir','rimraf','../../mysqldb','dbH','../../config/logger','analytics','argv','savename','update','info','format'];(function(_0x3506e5,_0x3bc1bc){var _0x21c033=function(_0xf88597){while(--_0xf88597){_0x3506e5['push'](_0x3506e5['shift']());}};_0x21c033(++_0x3bc1bc);}(_0xd61e,0x1da));var _0xed61=function(_0x1bcd0a,_0xd65baf){_0x1bcd0a=_0x1bcd0a-0x0;var _0x47f9bb=_0xd61e[_0x1bcd0a];return _0x47f9bb;};'use strict';var util=require(_0xed61('0x0'));var path=require(_0xed61('0x1'));var _=require(_0xed61('0x2'));var csv=require(_0xed61('0x3'));var fs=require('fs');var BPromise=require(_0xed61('0x4'));var zipdir=require(_0xed61('0x5'));var rimraf=require(_0xed61('0x6'));var db=require(_0xed61('0x7'))['db'];var dbH=require('../../mysqldb')[_0xed61('0x8')];var logger=require(_0xed61('0x9'))(_0xed61('0xa'));var EXTRACTED_REPORT_ID=Number(process[_0xed61('0xb')][0x2]);var QUERY=process['argv'][0x3];var PATH=process[_0xed61('0xb')][0x4];var EXIT_CODE=0x0;function analyticExtractedReport(_0x4642bb,_0x1b973a){var _0x3947ee={'status':_0x4642bb};var _0x491699={'where':{'id':EXTRACTED_REPORT_ID}};if(_0x1b973a){_0x3947ee[_0xed61('0xc')]=_0x1b973a;}return db['AnalyticExtractedReport'][_0xed61('0xd')](_0x3947ee,_0x491699);}function main(){var _0x247c3b=0x1388;var _0xa7ec3a;logger[_0xed61('0xe')](util[_0xed61('0xf')]('Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format',EXTRACTED_REPORT_ID,_0xed61('0x10')));return db[_0xed61('0x11')][_0xed61('0x12')]({'where':{'id':0x1},'raw':!![],'attributes':['id','split',_0xed61('0x13')]})['then'](function(_0x1f4120){if(_0x1f4120){_0xa7ec3a=_0x1f4120;_0x247c3b=_0xa7ec3a[_0xed61('0x13')]||0x1388;}})[_0xed61('0x14')](function(){return dbH[_0xed61('0x15')][_0xed61('0x16')](util['format'](_0xed61('0x17'),QUERY),{'type':dbH[_0xed61('0x15')]['QueryTypes']['SELECT']});})[_0xed61('0x14')](function(_0x339f50){if(!_0x339f50[0x0][_0xed61('0x18')]){return analyticExtractedReport('Empty');}var _0x1f70ff=[];var _0x32e38a=0x0;if(_0xa7ec3a[_0xed61('0x19')]){if(_0x339f50&&_0x339f50[_0xed61('0x1a')]){var _0x20652c=_[_0xed61('0x1b')](_0x339f50[0x0][_0xed61('0x18')]/_0x247c3b);var _0x4d83a2=Number[_0xed61('0x1c')](_0x339f50[0x0]['num']/_0x247c3b)?_0x339f50[0x0][_0xed61('0x18')]%_0x247c3b:0x0;_0x20652c['forEach'](function(_0x26f6b0){if(_0x26f6b0>0x0){_0x32e38a+=_0x247c3b;}_0x1f70ff[_0xed61('0x1d')](dbH['sequelize'][_0xed61('0x16')](util[_0xed61('0xf')](_0xed61('0x1e'),QUERY,_0x247c3b,_0x32e38a),{'type':dbH[_0xed61('0x15')][_0xed61('0x1f')][_0xed61('0x20')]}));});if(_0x4d83a2>0x0){_0x32e38a+=_0x247c3b;_0x1f70ff[_0xed61('0x1d')](dbH[_0xed61('0x15')][_0xed61('0x16')](util[_0xed61('0xf')]('%s\x20limit\x20%d\x20OFFSET\x20%d',QUERY,_0x4d83a2,_0x32e38a),{'type':dbH[_0xed61('0x15')]['QueryTypes'][_0xed61('0x20')]}));}}}else{_0x1f70ff['push'](dbH[_0xed61('0x15')][_0xed61('0x16')](QUERY,{'type':dbH[_0xed61('0x15')][_0xed61('0x1f')][_0xed61('0x20')]}));}var _0x2f688c=path[_0xed61('0x21')](PATH);var _0x2b28a2=path[_0xed61('0x22')](PATH,_0xed61('0x23'));var _0x4a7302=_0xa7ec3a[_0xed61('0x19')]&&_0x1f70ff[_0xed61('0x1a')]>0x1;var _0x2049a5=[];if(!fs[_0xed61('0x24')](path[_0xed61('0x25')](_0x2f688c,_0x2b28a2))&&_0x4a7302){fs[_0xed61('0x26')](path['join'](_0x2f688c,_0x2b28a2));}return BPromise[_0xed61('0x27')](_0x1f70ff,function(_0x56a51e){_0x2049a5[_0xed61('0x1d')](_0x56a51e);})[_0xed61('0x14')](function(){for(var _0x45fcee=0x0;_0x45fcee<_0x2049a5['length'];_0x45fcee+=0x1){var _0x438600;var _0x536185=_0x2049a5[_0x45fcee];if(_0x4a7302){_0x438600=path[_0xed61('0x25')](_0x2f688c,_0x2b28a2,util[_0xed61('0xf')](_0xed61('0x28'),_0x2b28a2,_0x45fcee,_0xed61('0x29')));}else{_0x438600=path[_0xed61('0x25')](_0x2f688c,util[_0xed61('0xf')](_0xed61('0x2a'),_0x2b28a2,'csv'));}fs[_0xed61('0x2b')](_0x438600,csv(_0x536185));}})[_0xed61('0x14')](function(){if(_0x4a7302){return new Promise(function(_0x559b77){zipdir(path[_0xed61('0x25')](_0x2f688c,_0x2b28a2),{'saveTo':path['join'](_0x2f688c,util['format'](_0xed61('0x2a'),_0x2b28a2,_0xed61('0x2c')))},function(_0x1e20fe,_0x295587){rimraf(path['join'](_0x2f688c,_0x2b28a2),function(){});_0x559b77(_0xed61('0x2d'));});});}})[_0xed61('0x14')](function(){logger[_0xed61('0xe')](util['format'](_0xed61('0x2e'),EXTRACTED_REPORT_ID,_0xed61('0x10')));return analyticExtractedReport('Completed',_0x4a7302?util['format'](_0xed61('0x2a'),_0x2b28a2,_0x4a7302?_0xed61('0x2c'):_0xed61('0x29')):null);});})['catch'](function(_0xb5d004){logger['info'](util[_0xed61('0xf')](_0xed61('0x2f'),EXTRACTED_REPORT_ID,_0xed61('0x10')),util['inspect'](_0xb5d004,{'showHidden':![],'depth':null}));EXIT_CODE=0x1;return analyticExtractedReport('Failed');})[_0xed61('0x30')](function(){process['exit'](EXIT_CODE);});}main();
\ No newline at end of file