Built motion from commit 092f8824.|2.5.49
[motion2.git] / server / components / export / csv.js
index 61a9cbd..f276e70 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xb2fa=['AnalyticExtractedReport','update','format','Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','CSV','find','split','then','splitSizeCsv','sequelize','query','SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t','QueryTypes','SELECT','num','Empty','length','%s\x20limit\x20%d\x20OFFSET\x20%d','push','dirname','.csv','existsSync','mkdirSync','join','each','%s%d.%s','csv','%s.%s','writeFileSync','zip','info','catch','Error\x20during\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','inspect','Failed','finally','path','lodash','zip-dir','rimraf','../../mysqldb','dbH','../../config/logger','analytics','argv'];(function(_0x8c1a1f,_0x2801b6){var _0xed69dc=function(_0x17231e){while(--_0x17231e){_0x8c1a1f['push'](_0x8c1a1f['shift']());}};_0xed69dc(++_0x2801b6);}(_0xb2fa,0x1e6));var _0xab2f=function(_0x14add3,_0x13ce8d){_0x14add3=_0x14add3-0x0;var _0x4a174f=_0xb2fa[_0x14add3];return _0x4a174f;};'use strict';var util=require('util');var path=require(_0xab2f('0x0'));var _=require(_0xab2f('0x1'));var csv=require('to-csv');var fs=require('fs');var BPromise=require('bluebird');var zipdir=require(_0xab2f('0x2'));var rimraf=require(_0xab2f('0x3'));var db=require(_0xab2f('0x4'))['db'];var dbH=require(_0xab2f('0x4'))[_0xab2f('0x5')];var logger=require(_0xab2f('0x6'))(_0xab2f('0x7'));var EXTRACTED_REPORT_ID=Number(process[_0xab2f('0x8')][0x2]);var QUERY=process[_0xab2f('0x8')][0x3];var PATH=process[_0xab2f('0x8')][0x4];var EXIT_CODE=0x0;function analyticExtractedReport(_0x2ffd67,_0x2e1ff0){var _0x3cb9b0={'status':_0x2ffd67};var _0x5d80ca={'where':{'id':EXTRACTED_REPORT_ID}};if(_0x2e1ff0){_0x3cb9b0['savename']=_0x2e1ff0;}return db[_0xab2f('0x9')][_0xab2f('0xa')](_0x3cb9b0,_0x5d80ca);}function main(){var _0x823e1=0x1388;var _0x35daba;logger['info'](util[_0xab2f('0xb')](_0xab2f('0xc'),EXTRACTED_REPORT_ID,_0xab2f('0xd')));return db['Setting'][_0xab2f('0xe')]({'where':{'id':0x1},'raw':!![],'attributes':['id',_0xab2f('0xf'),'splitSizeCsv']})[_0xab2f('0x10')](function(_0x427ec3){if(_0x427ec3){_0x35daba=_0x427ec3;_0x823e1=_0x35daba[_0xab2f('0x11')]||0x1388;}})[_0xab2f('0x10')](function(){return dbH[_0xab2f('0x12')][_0xab2f('0x13')](util[_0xab2f('0xb')](_0xab2f('0x14'),QUERY),{'type':dbH[_0xab2f('0x12')][_0xab2f('0x15')][_0xab2f('0x16')]});})[_0xab2f('0x10')](function(_0x12542a){if(!_0x12542a[0x0][_0xab2f('0x17')]){return analyticExtractedReport(_0xab2f('0x18'));}var _0x1ab66e=[];var _0x1f8143=0x0;var _0xff5a13=!![];if(_0x12542a&&_0x12542a[_0xab2f('0x19')]){var _0x1405ce=_0x12542a[0x0]['num']%(_0x1f8143+_0x823e1);if(_0x35daba['split']){for(;_0xff5a13;_0x1f8143+=_0x823e1,_0x1405ce=_0x12542a[0x0]['num']%(_0x1f8143+_0x823e1)){if(_0x1405ce==0x0||_0x1405ce==_0x12542a[0x0]['num']){_0xff5a13=![];}_0x1ab66e['push'](dbH[_0xab2f('0x12')][_0xab2f('0x13')](util[_0xab2f('0xb')](_0xab2f('0x1a'),QUERY,_0x823e1,_0x1f8143),{'type':dbH['sequelize'][_0xab2f('0x15')]['SELECT']}));}}else{_0x1ab66e[_0xab2f('0x1b')](dbH[_0xab2f('0x12')][_0xab2f('0x13')](QUERY,{'type':dbH[_0xab2f('0x12')][_0xab2f('0x15')][_0xab2f('0x16')]}));}}var _0x233d48=path[_0xab2f('0x1c')](PATH);var _0x19c303=path['basename'](PATH,_0xab2f('0x1d'));var _0x113b29=_0x35daba['split']&&_0x1ab66e['length']>0x1;var _0x1e94c9=[];if(!fs[_0xab2f('0x1e')](path['join'](_0x233d48,_0x19c303))&&_0x113b29){fs[_0xab2f('0x1f')](path[_0xab2f('0x20')](_0x233d48,_0x19c303));}return BPromise[_0xab2f('0x21')](_0x1ab66e,function(_0x26422d){_0x1e94c9[_0xab2f('0x1b')](_0x26422d);})[_0xab2f('0x10')](function(){for(var _0xe58e5a=0x0;_0xe58e5a<_0x1e94c9['length'];_0xe58e5a+=0x1){var _0x249fb2;var _0x4220c8=_0x1e94c9[_0xe58e5a];if(_0x113b29){_0x249fb2=path[_0xab2f('0x20')](_0x233d48,_0x19c303,util['format'](_0xab2f('0x22'),_0x19c303,_0xe58e5a,_0xab2f('0x23')));}else{_0x249fb2=path[_0xab2f('0x20')](_0x233d48,util[_0xab2f('0xb')](_0xab2f('0x24'),_0x19c303,_0xab2f('0x23')));}fs[_0xab2f('0x25')](_0x249fb2,csv(_0x4220c8));}})[_0xab2f('0x10')](function(){if(_0x113b29){zipdir(path['join'](_0x233d48,_0x19c303),{'saveTo':path['join'](_0x233d48,util[_0xab2f('0xb')](_0xab2f('0x24'),_0x19c303,_0xab2f('0x26')))},function(_0x58f7c3,_0x173fde){});rimraf(path['join'](_0x233d48,_0x19c303),function(){});}})['then'](function(){logger[_0xab2f('0x27')](util[_0xab2f('0xb')]('Extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format\x20completed',EXTRACTED_REPORT_ID,_0xab2f('0xd')));return analyticExtractedReport('Completed',_0x113b29?util['format']('%s.%s',_0x19c303,_0x113b29?_0xab2f('0x26'):_0xab2f('0x23')):null);});})[_0xab2f('0x28')](function(_0x579ee0){logger['info'](util[_0xab2f('0xb')](_0xab2f('0x29'),EXTRACTED_REPORT_ID,'CSV'),util[_0xab2f('0x2a')](_0x579ee0,{'showHidden':![],'depth':null}));EXIT_CODE=0x1;return analyticExtractedReport(_0xab2f('0x2b'));})[_0xab2f('0x2c')](function(){process['exit'](EXIT_CODE);});}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