d9af7e4b10f0468a05fa3e71d4f29d1fe2e8a1af
[motion2.git] / server / api / version / version.controller.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 _0x1fbc=['replace','push','sort','Migration','sequelize','getQueryInterface','constructor','map','.js','\x20to\x20','UniqueConstraintError','Database\x20already\x20up-to-date','umzug','path','lodash','pkginfo','compare-versions','child_process','../../mysqldb','../../config/environment','../../config/logger','update','simple-git','exports','version','query','latest','fetch','tags','status','master','error','json','info','git\x20fetch','reset','--hard','FETCH_HEAD','git\x20reset\x20--hard\x20FETCH_HEAD','git\x20reset\x20--hard','pull','npm\x20install\x20--production','restart','motion2','then','pm2\x20restart\x20motion\x20%s','catch','migrations','readdirSync','join','root','server','length'];(function(_0x502c7d,_0x2f1285){var _0x30b7ed=function(_0x2d92f3){while(--_0x2d92f3){_0x502c7d['push'](_0x502c7d['shift']());}};_0x30b7ed(++_0x2f1285);}(_0x1fbc,0x76));var _0xc1fb=function(_0x1d5a1c,_0x183e21){_0x1d5a1c=_0x1d5a1c-0x0;var _0x3430ac=_0x1fbc[_0x1d5a1c];return _0x3430ac;};'use strict';var Umzug=require(_0xc1fb('0x0'));var path=require(_0xc1fb('0x1'));var fs=require('fs');var _=require(_0xc1fb('0x2'));var pkginfo=require(_0xc1fb('0x3'))(module,'version');var compareVersions=require(_0xc1fb('0x4'));var exec=require(_0xc1fb('0x5'))['exec'];var db=require(_0xc1fb('0x6'))['db'];var config=require(_0xc1fb('0x7'));var pm2=require('../../config/pm2');var logger=require(_0xc1fb('0x8'))(_0xc1fb('0x9'));var git=require(_0xc1fb('0xa'))(config['root']);exports['index']=function(_0x3f5dcb,_0x185f02){var _0x177391={'current':module[_0xc1fb('0xb')][_0xc1fb('0xc')],'phonebar':0x2};if(_0x3f5dcb['query']&&_0x3f5dcb[_0xc1fb('0xd')][_0xc1fb('0xe')]){return git[_0xc1fb('0xf')]()[_0xc1fb('0x10')](function(_0x216c83,_0x2a5806){_0x177391['latest']=(_0x216c83?module['exports'][_0xc1fb('0xc')]:_0x2a5806[_0xc1fb('0xe')])||'2.0.0';return _0x185f02[_0xc1fb('0x11')](0xc8)['json'](_0x177391);});}else{return _0x185f02['status'](0xc8)['json'](_0x177391);}};exports[_0xc1fb('0xf')]=function(_0x4a33d9,_0x3d9d35){return git['fetch'](['origin',_0xc1fb('0x12')],function(_0x15800b){if(_0x15800b){logger[_0xc1fb('0x13')](_0x15800b);return _0x3d9d35[_0xc1fb('0x11')](0x1f4)[_0xc1fb('0x14')](_0x15800b);}logger[_0xc1fb('0x15')](_0xc1fb('0x16'));return _0x3d9d35[_0xc1fb('0x11')](0xc8)[_0xc1fb('0x14')]({'output':'git\x20fetch\x20origin\x20master'});});};exports[_0xc1fb('0x17')]=function(_0x402fc4,_0x5c013e){return git[_0xc1fb('0x17')]([_0xc1fb('0x18'),_0xc1fb('0x19')],function(_0x3e955b){if(_0x3e955b){logger[_0xc1fb('0x13')](_0x3e955b);return _0x5c013e[_0xc1fb('0x11')](0x1f4)[_0xc1fb('0x14')](_0x3e955b);}logger['info'](_0xc1fb('0x1a'));return _0x5c013e[_0xc1fb('0x11')](0xc8)[_0xc1fb('0x14')]({'output':_0xc1fb('0x1b')});});};exports[_0xc1fb('0x1c')]=function(_0xa10d84,_0x513d00){exec(_0xc1fb('0x1d'),function(_0x3b3ce9,_0x1d3347,_0xf1a12e){logger[_0xc1fb('0x15')](_0x1d3347);logger[_0xc1fb('0x15')](_0xf1a12e);if(_0x3b3ce9){logger[_0xc1fb('0x13')](_0x3b3ce9);return _0x513d00[_0xc1fb('0x11')](0x1f4)[_0xc1fb('0x14')](_0x3b3ce9);}return _0x513d00[_0xc1fb('0x11')](0xc8)[_0xc1fb('0x14')]({'output':_0x1d3347});});};exports[_0xc1fb('0x1e')]=function(_0x133b4e,_0x30ba13){return pm2[_0xc1fb('0x1e')](_0xc1fb('0x1f'))[_0xc1fb('0x20')](function(_0x26c285){logger[_0xc1fb('0x15')](_0xc1fb('0x21'),_0x26c285);return _0x30ba13[_0xc1fb('0x11')](0xc8)[_0xc1fb('0x14')]({'output':'Your\x20system\x20has\x20been\x20restart\x20successfully'});})[_0xc1fb('0x22')](function(_0x47484c){logger[_0xc1fb('0x13')](_0x47484c);return _0x30ba13[_0xc1fb('0x11')](0x1f4)[_0xc1fb('0x14')](_0x47484c);});};exports[_0xc1fb('0x23')]=function(_0x157036,_0x20472f){var _0x1b6b3c=fs[_0xc1fb('0x24')](path[_0xc1fb('0x25')](config[_0xc1fb('0x26')],_0xc1fb('0x27'),_0xc1fb('0x23')));var _0x278e91=[];for(var _0x5ab4f5=0x0;_0x5ab4f5<_0x1b6b3c[_0xc1fb('0x28')];_0x5ab4f5++){var _0x27ae3e=_0x1b6b3c[_0x5ab4f5][_0xc1fb('0x29')]('.js','');if(compareVersions(module[_0xc1fb('0xb')][_0xc1fb('0xc')],_0x27ae3e)===-0x1){_0x278e91[_0xc1fb('0x2a')](_0x27ae3e);}}if(_0x278e91[_0xc1fb('0x28')]){var _0x176af7=_0x278e91[_0xc1fb('0x2b')](compareVersions);var _0x19d284=new Umzug({'storage':'sequelize','storageOptions':{'model':db[_0xc1fb('0x2c')],'modelName':'Migration','columnName':_0xc1fb('0xc')},'migrations':{'params':[db[_0xc1fb('0x2d')][_0xc1fb('0x2e')](),db[_0xc1fb('0x2d')][_0xc1fb('0x2f')],function(){throw new Error('Migration\x20tried\x20to\x20use\x20old\x20style\x20\x22done\x22\x20callback.\x20Please\x20upgrade\x20to\x20\x22umzug\x22\x20and\x20return\x20a\x20promise\x20instead.');}],'path':path[_0xc1fb('0x25')](config[_0xc1fb('0x26')],_0xc1fb('0x27'),_0xc1fb('0x23')),'pattern':/\.js$/}});_0x19d284['up']({'migrations':_[_0xc1fb('0x30')](_0x176af7,function(_0x1d632d){return _0x1d632d+_0xc1fb('0x31');})})[_0xc1fb('0x20')](function(){return _0x20472f['status'](0xc8)[_0xc1fb('0x14')]({'output':'Database\x20migrated\x20successfully\x20from\x20version\x20'+module[_0xc1fb('0xb')][_0xc1fb('0xc')]+_0xc1fb('0x32')+_['last'](_0x176af7),'migrations':_[_0xc1fb('0x25')](_0x176af7)});})[_0xc1fb('0x22')](function(_0x472d50){if(_0x472d50 instanceof db[_0xc1fb('0x2d')][_0xc1fb('0x33')]){return _0x20472f[_0xc1fb('0x11')](0xc8)['json']({'output':'Database\x20already\x20up-to-date'});}else{return _0x20472f[_0xc1fb('0x11')](0x1f4)[_0xc1fb('0x14')](_0x472d50);}});}else{return _0x20472f['status'](0xc8)['json']({'output':_0xc1fb('0x34')});}};