Built motion from commit 092f8824.|2.5.49
[motion2.git] / server / components / export / csv.js
index bcff0cc..f276e70 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x153f=['split','%s\x20limit\x20%d\x20OFFSET\x20%d','push','dirname','basename','.csv','existsSync','join','mkdirSync','each','csv','%s.%s','writeFileSync','zip','Extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format\x20completed','catch','Error\x20during\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','Failed','util','path','lodash','to-csv','bluebird','zip-dir','rimraf','../../mysqldb','../../config/logger','analytics','argv','savename','AnalyticExtractedReport','update','info','format','CSV','Setting','find','splitSizeCsv','then','sequelize','query','SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t','QueryTypes','SELECT','num','Empty','length'];(function(_0xb833b1,_0x1c3d3f){var _0x1ab87a=function(_0x1c9f6c){while(--_0x1c9f6c){_0xb833b1['push'](_0xb833b1['shift']());}};_0x1ab87a(++_0x1c3d3f);}(_0x153f,0x15b));var _0xf153=function(_0x3a6273,_0x52c710){_0x3a6273=_0x3a6273-0x0;var _0x405f5b=_0x153f[_0x3a6273];return _0x405f5b;};'use strict';var util=require(_0xf153('0x0'));var path=require(_0xf153('0x1'));var _=require(_0xf153('0x2'));var csv=require(_0xf153('0x3'));var fs=require('fs');var BPromise=require(_0xf153('0x4'));var zipdir=require(_0xf153('0x5'));var rimraf=require(_0xf153('0x6'));var db=require('../../mysqldb')['db'];var dbH=require(_0xf153('0x7'))['dbH'];var logger=require(_0xf153('0x8'))(_0xf153('0x9'));var EXTRACTED_REPORT_ID=Number(process[_0xf153('0xa')][0x2]);var QUERY=process[_0xf153('0xa')][0x3];var PATH=process[_0xf153('0xa')][0x4];function analyticExtractedReport(_0x4c8ae5,_0x17ba96){var _0x143497={'status':_0x4c8ae5};var _0x224f88={'where':{'id':EXTRACTED_REPORT_ID}};if(_0x17ba96){_0x143497[_0xf153('0xb')]=_0x17ba96;}return db[_0xf153('0xc')][_0xf153('0xd')](_0x143497,_0x224f88);}function main(){var _0x44845c=0x1388;var _0x15a18b;logger[_0xf153('0xe')](util[_0xf153('0xf')]('Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format',EXTRACTED_REPORT_ID,_0xf153('0x10')));return db[_0xf153('0x11')][_0xf153('0x12')]({'where':{'id':0x1},'raw':!![],'attributes':['id','split',_0xf153('0x13')]})[_0xf153('0x14')](function(_0x65756d){if(_0x65756d){_0x15a18b=_0x65756d;_0x44845c=_0x15a18b[_0xf153('0x13')]||0x1388;}})[_0xf153('0x14')](function(){return dbH[_0xf153('0x15')][_0xf153('0x16')](util[_0xf153('0xf')](_0xf153('0x17'),QUERY),{'type':dbH['sequelize'][_0xf153('0x18')][_0xf153('0x19')]});})[_0xf153('0x14')](function(_0x406e6f){if(!_0x406e6f[0x0][_0xf153('0x1a')]){return analyticExtractedReport(_0xf153('0x1b'));}var _0x273a90=[];var _0x287bc6=0x0;var _0x47fbfe=!![];if(_0x406e6f&&_0x406e6f[_0xf153('0x1c')]){var _0x564eeb=_0x406e6f[0x0][_0xf153('0x1a')]%(_0x287bc6+_0x44845c);if(_0x15a18b[_0xf153('0x1d')]){for(;_0x47fbfe;_0x287bc6+=_0x44845c,_0x564eeb=_0x406e6f[0x0][_0xf153('0x1a')]%(_0x287bc6+_0x44845c)){if(_0x564eeb==0x0||_0x564eeb==_0x406e6f[0x0][_0xf153('0x1a')]){_0x47fbfe=![];}_0x273a90['push'](dbH[_0xf153('0x15')][_0xf153('0x16')](util[_0xf153('0xf')](_0xf153('0x1e'),QUERY,_0x44845c,_0x287bc6),{'type':dbH[_0xf153('0x15')][_0xf153('0x18')][_0xf153('0x19')]}));}}else{_0x273a90[_0xf153('0x1f')](dbH[_0xf153('0x15')][_0xf153('0x16')](QUERY,{'type':dbH[_0xf153('0x15')][_0xf153('0x18')]['SELECT']}));}}var _0xcd5762=path[_0xf153('0x20')](PATH);var _0x3d3e41=path[_0xf153('0x21')](PATH,_0xf153('0x22'));var _0x3e94b5=_0x15a18b[_0xf153('0x1d')]&&_0x273a90[_0xf153('0x1c')]>0x1;var _0xf67cde=[];if(!fs[_0xf153('0x23')](path[_0xf153('0x24')](_0xcd5762,_0x3d3e41))&&_0x3e94b5){fs[_0xf153('0x25')](path[_0xf153('0x24')](_0xcd5762,_0x3d3e41));}return BPromise[_0xf153('0x26')](_0x273a90,function(_0xe490f8){_0xf67cde[_0xf153('0x1f')](_0xe490f8);})[_0xf153('0x14')](function(){for(var _0x703adb=0x0;_0x703adb<_0xf67cde[_0xf153('0x1c')];_0x703adb+=0x1){var _0x17f7a4;var _0x48ebdc=_0xf67cde[_0x703adb];if(_0x3e94b5){_0x17f7a4=path[_0xf153('0x24')](_0xcd5762,_0x3d3e41,util[_0xf153('0xf')]('%s%d.%s',_0x3d3e41,_0x703adb,_0xf153('0x27')));}else{_0x17f7a4=path[_0xf153('0x24')](_0xcd5762,util['format'](_0xf153('0x28'),_0x3d3e41,_0xf153('0x27')));}fs[_0xf153('0x29')](_0x17f7a4,csv(_0x48ebdc));}})[_0xf153('0x14')](function(){if(_0x3e94b5){zipdir(path[_0xf153('0x24')](_0xcd5762,_0x3d3e41),{'saveTo':path[_0xf153('0x24')](_0xcd5762,util[_0xf153('0xf')](_0xf153('0x28'),_0x3d3e41,_0xf153('0x2a')))},function(_0x8e31bf,_0x13b541){});rimraf(path[_0xf153('0x24')](_0xcd5762,_0x3d3e41),function(){});}})['then'](function(){logger[_0xf153('0xe')](util[_0xf153('0xf')](_0xf153('0x2b'),EXTRACTED_REPORT_ID,_0xf153('0x10')));return analyticExtractedReport('Completed',_0x3e94b5?util['format'](_0xf153('0x28'),_0x3d3e41,_0x3e94b5?'zip':'csv'):null);});})[_0xf153('0x2c')](function(_0x4ab958){logger[_0xf153('0xe')](util['format'](_0xf153('0x2d'),EXTRACTED_REPORT_ID,_0xf153('0x10')),util['inspect'](_0x4ab958,{'showHidden':![],'depth':null}));return analyticExtractedReport(_0xf153('0x2e'));});}main();
\ No newline at end of file
+var _0xf998=['.csv','join','mkdirSync','%s%d.%s','csv','%s.%s','writeFileSync','zip','zip\x20finished','Extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format\x20completed','CSV','Completed','Error\x20during\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','Failed','finally','util','path','to-csv','bluebird','rimraf','../../mysqldb','dbH','../../config/logger','analytics','argv','savename','update','info','format','Setting','find','split','splitSizeCsv','then','sequelize','query','SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t','QueryTypes','SELECT','num','Empty','length','forEach','push','%s\x20limit\x20%d\x20OFFSET\x20%d','dirname','basename'];(function(_0x27af45,_0x1b57aa){var _0x18df21=function(_0x4b7679){while(--_0x4b7679){_0x27af45['push'](_0x27af45['shift']());}};_0x18df21(++_0x1b57aa);}(_0xf998,0x187));var _0x8f99=function(_0x411add,_0x1aed38){_0x411add=_0x411add-0x0;var _0x238242=_0xf998[_0x411add];return _0x238242;};'use strict';var util=require(_0x8f99('0x0'));var path=require(_0x8f99('0x1'));var _=require('lodash');var csv=require(_0x8f99('0x2'));var fs=require('fs');var BPromise=require(_0x8f99('0x3'));var zipdir=require('zip-dir');var rimraf=require(_0x8f99('0x4'));var db=require(_0x8f99('0x5'))['db'];var dbH=require(_0x8f99('0x5'))[_0x8f99('0x6')];var logger=require(_0x8f99('0x7'))(_0x8f99('0x8'));var EXTRACTED_REPORT_ID=Number(process[_0x8f99('0x9')][0x2]);var QUERY=process[_0x8f99('0x9')][0x3];var PATH=process[_0x8f99('0x9')][0x4];var EXIT_CODE=0x0;function analyticExtractedReport(_0xc07d74,_0x4ac13b){var _0xa7afb1={'status':_0xc07d74};var _0x5cfb3e={'where':{'id':EXTRACTED_REPORT_ID}};if(_0x4ac13b){_0xa7afb1[_0x8f99('0xa')]=_0x4ac13b;}return db['AnalyticExtractedReport'][_0x8f99('0xb')](_0xa7afb1,_0x5cfb3e);}function main(){var _0x5aa378=0x1388;var _0x5265f8;logger[_0x8f99('0xc')](util[_0x8f99('0xd')]('Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format',EXTRACTED_REPORT_ID,'CSV'));return db[_0x8f99('0xe')][_0x8f99('0xf')]({'where':{'id':0x1},'raw':!![],'attributes':['id',_0x8f99('0x10'),_0x8f99('0x11')]})['then'](function(_0x2b2401){if(_0x2b2401){_0x5265f8=_0x2b2401;_0x5aa378=_0x5265f8[_0x8f99('0x11')]||0x1388;}})[_0x8f99('0x12')](function(){return dbH[_0x8f99('0x13')][_0x8f99('0x14')](util[_0x8f99('0xd')](_0x8f99('0x15'),QUERY),{'type':dbH[_0x8f99('0x13')][_0x8f99('0x16')][_0x8f99('0x17')]});})['then'](function(_0x68bcb){if(!_0x68bcb[0x0][_0x8f99('0x18')]){return analyticExtractedReport(_0x8f99('0x19'));}var _0x207701=[];var _0x293b14=0x0;if(_0x5265f8[_0x8f99('0x10')]){if(_0x68bcb&&_0x68bcb[_0x8f99('0x1a')]){var _0x4040db=_['range'](_0x68bcb[0x0][_0x8f99('0x18')]/_0x5aa378);var _0x5c3bd3=Number['isInteger'](_0x68bcb[0x0][_0x8f99('0x18')]/_0x5aa378)?_0x68bcb[0x0]['num']%_0x5aa378:0x0;_0x4040db[_0x8f99('0x1b')](function(_0x264712){if(_0x264712>0x0){_0x293b14+=_0x5aa378;}_0x207701[_0x8f99('0x1c')](dbH['sequelize'][_0x8f99('0x14')](util[_0x8f99('0xd')](_0x8f99('0x1d'),QUERY,_0x5aa378,_0x293b14),{'type':dbH['sequelize'][_0x8f99('0x16')]['SELECT']}));});if(_0x5c3bd3>0x0){_0x293b14+=_0x5aa378;_0x207701[_0x8f99('0x1c')](dbH[_0x8f99('0x13')][_0x8f99('0x14')](util[_0x8f99('0xd')](_0x8f99('0x1d'),QUERY,_0x5c3bd3,_0x293b14),{'type':dbH[_0x8f99('0x13')][_0x8f99('0x16')][_0x8f99('0x17')]}));}}}else{_0x207701['push'](dbH[_0x8f99('0x13')]['query'](QUERY,{'type':dbH[_0x8f99('0x13')]['QueryTypes'][_0x8f99('0x17')]}));}var _0x237f2f=path[_0x8f99('0x1e')](PATH);var _0x248eac=path[_0x8f99('0x1f')](PATH,_0x8f99('0x20'));var _0x4dfbfb=_0x5265f8[_0x8f99('0x10')]&&_0x207701['length']>0x1;var _0x41ac80=[];if(!fs['existsSync'](path[_0x8f99('0x21')](_0x237f2f,_0x248eac))&&_0x4dfbfb){fs[_0x8f99('0x22')](path['join'](_0x237f2f,_0x248eac));}return BPromise['each'](_0x207701,function(_0x187054){_0x41ac80[_0x8f99('0x1c')](_0x187054);})[_0x8f99('0x12')](function(){for(var _0x3d0e40=0x0;_0x3d0e40<_0x41ac80[_0x8f99('0x1a')];_0x3d0e40+=0x1){var _0x561615;var _0x30fa95=_0x41ac80[_0x3d0e40];if(_0x4dfbfb){_0x561615=path[_0x8f99('0x21')](_0x237f2f,_0x248eac,util[_0x8f99('0xd')](_0x8f99('0x23'),_0x248eac,_0x3d0e40,_0x8f99('0x24')));}else{_0x561615=path['join'](_0x237f2f,util[_0x8f99('0xd')](_0x8f99('0x25'),_0x248eac,_0x8f99('0x24')));}fs[_0x8f99('0x26')](_0x561615,csv(_0x30fa95));}})[_0x8f99('0x12')](function(){if(_0x4dfbfb){return new Promise(function(_0x9f5b17){zipdir(path[_0x8f99('0x21')](_0x237f2f,_0x248eac),{'saveTo':path[_0x8f99('0x21')](_0x237f2f,util[_0x8f99('0xd')](_0x8f99('0x25'),_0x248eac,_0x8f99('0x27')))},function(_0x151496,_0x26f4bf){rimraf(path[_0x8f99('0x21')](_0x237f2f,_0x248eac),function(){});_0x9f5b17(_0x8f99('0x28'));});});}})['then'](function(){logger[_0x8f99('0xc')](util[_0x8f99('0xd')](_0x8f99('0x29'),EXTRACTED_REPORT_ID,_0x8f99('0x2a')));return analyticExtractedReport(_0x8f99('0x2b'),_0x4dfbfb?util[_0x8f99('0xd')](_0x8f99('0x25'),_0x248eac,_0x4dfbfb?_0x8f99('0x27'):_0x8f99('0x24')):null);});})['catch'](function(_0x3dabcc){logger['info'](util[_0x8f99('0xd')](_0x8f99('0x2c'),EXTRACTED_REPORT_ID,_0x8f99('0x2a')),util['inspect'](_0x3dabcc,{'showHidden':![],'depth':null}));EXIT_CODE=0x1;return analyticExtractedReport(_0x8f99('0x2d'));})[_0x8f99('0x2e')](function(){process['exit'](EXIT_CODE);});}main();
\ No newline at end of file