1440de5ae7ff7b018d0ed15f052a2426eab1aa00
[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 _0x4977=['FETCH_HEAD','git\x20reset\x20--hard\x20FETCH_HEAD','git\x20reset\x20--hard','pull','npm\x20install\x20--production','restart','motion2','pm2\x20restart\x20motion\x20%s','migrations','readdirSync','server','length','replace','.js','sort','sequelize','Migration','getQueryInterface','constructor','Migration\x20tried\x20to\x20use\x20old\x20style\x20\x22done\x22\x20callback.\x20Please\x20upgrade\x20to\x20\x22umzug\x22\x20and\x20return\x20a\x20promise\x20instead.','join','map','then','\x20to\x20','last','catch','UniqueConstraintError','Database\x20already\x20up-to-date','path','lodash','pkginfo','version','compare-versions','child_process','../../mysqldb','../../config/environment','../../config/pm2','update','simple-git','root','index','exports','query','latest','fetch','status','json','origin','error','info','git\x20fetch\x20origin\x20master','reset','--hard'];(function(_0x3cbe1c,_0x4bcabd){var _0x5ee08b=function(_0x5c53e6){while(--_0x5c53e6){_0x3cbe1c['push'](_0x3cbe1c['shift']());}};_0x5ee08b(++_0x4bcabd);}(_0x4977,0x18f));var _0x7497=function(_0x33154e,_0x4c956b){_0x33154e=_0x33154e-0x0;var _0x41ebf9=_0x4977[_0x33154e];return _0x41ebf9;};'use strict';var Umzug=require('umzug');var path=require(_0x7497('0x0'));var fs=require('fs');var _=require(_0x7497('0x1'));var pkginfo=require(_0x7497('0x2'))(module,_0x7497('0x3'));var compareVersions=require(_0x7497('0x4'));var exec=require(_0x7497('0x5'))['exec'];var db=require(_0x7497('0x6'))['db'];var config=require(_0x7497('0x7'));var pm2=require(_0x7497('0x8'));var logger=require('../../config/logger')(_0x7497('0x9'));var git=require(_0x7497('0xa'))(config[_0x7497('0xb')]);exports[_0x7497('0xc')]=function(_0x20e59e,_0x6e6067){var _0x4bd4b5={'current':module[_0x7497('0xd')]['version'],'phonebar':0x2};if(_0x20e59e[_0x7497('0xe')]&&_0x20e59e[_0x7497('0xe')][_0x7497('0xf')]){return git[_0x7497('0x10')]()['tags'](function(_0x452ff9,_0x5ad957){_0x4bd4b5[_0x7497('0xf')]=(_0x452ff9?module[_0x7497('0xd')][_0x7497('0x3')]:_0x5ad957[_0x7497('0xf')])||'2.0.0';return _0x6e6067[_0x7497('0x11')](0xc8)[_0x7497('0x12')](_0x4bd4b5);});}else{return _0x6e6067['status'](0xc8)[_0x7497('0x12')](_0x4bd4b5);}};exports[_0x7497('0x10')]=function(_0x22b635,_0x267b7f){return git[_0x7497('0x10')]([_0x7497('0x13'),'master'],function(_0x419399){if(_0x419399){logger[_0x7497('0x14')](_0x419399);return _0x267b7f[_0x7497('0x11')](0x1f4)[_0x7497('0x12')](_0x419399);}logger[_0x7497('0x15')]('git\x20fetch');return _0x267b7f[_0x7497('0x11')](0xc8)['json']({'output':_0x7497('0x16')});});};exports['reset']=function(_0x53ecc8,_0x43bccd){return git[_0x7497('0x17')]([_0x7497('0x18'),_0x7497('0x19')],function(_0x17c66a){if(_0x17c66a){logger['error'](_0x17c66a);return _0x43bccd[_0x7497('0x11')](0x1f4)[_0x7497('0x12')](_0x17c66a);}logger[_0x7497('0x15')](_0x7497('0x1a'));return _0x43bccd[_0x7497('0x11')](0xc8)[_0x7497('0x12')]({'output':_0x7497('0x1b')});});};exports[_0x7497('0x1c')]=function(_0x40b390,_0x49c1c6){exec(_0x7497('0x1d'),function(_0x4302d4,_0x310a67,_0x28b594){logger[_0x7497('0x15')](_0x310a67);logger[_0x7497('0x15')](_0x28b594);if(_0x4302d4){logger[_0x7497('0x14')](_0x4302d4);return _0x49c1c6[_0x7497('0x11')](0x1f4)['json'](_0x4302d4);}return _0x49c1c6['status'](0xc8)[_0x7497('0x12')]({'output':_0x310a67});});};exports[_0x7497('0x1e')]=function(_0x6f4d37,_0x27e70b){return pm2['restart'](_0x7497('0x1f'))['then'](function(_0x5e553f){logger['info'](_0x7497('0x20'),_0x5e553f);return _0x27e70b['status'](0xc8)['json']({'output':'Your\x20system\x20has\x20been\x20restart\x20successfully'});})['catch'](function(_0x5509d0){logger[_0x7497('0x14')](_0x5509d0);return _0x27e70b[_0x7497('0x11')](0x1f4)['json'](_0x5509d0);});};exports[_0x7497('0x21')]=function(_0x577644,_0x24136c){var _0x4dcc21=fs[_0x7497('0x22')](path['join'](config[_0x7497('0xb')],_0x7497('0x23'),'migrations'));var _0x2b9250=[];for(var _0xd166ff=0x0;_0xd166ff<_0x4dcc21[_0x7497('0x24')];_0xd166ff++){var _0x2ba166=_0x4dcc21[_0xd166ff][_0x7497('0x25')](_0x7497('0x26'),'');if(compareVersions(module[_0x7497('0xd')][_0x7497('0x3')],_0x2ba166)===-0x1){_0x2b9250['push'](_0x2ba166);}}if(_0x2b9250[_0x7497('0x24')]){var _0x46b665=_0x2b9250[_0x7497('0x27')](compareVersions);var _0x41605b=new Umzug({'storage':_0x7497('0x28'),'storageOptions':{'model':db[_0x7497('0x29')],'modelName':'Migration','columnName':_0x7497('0x3')},'migrations':{'params':[db[_0x7497('0x28')][_0x7497('0x2a')](),db['sequelize'][_0x7497('0x2b')],function(){throw new Error(_0x7497('0x2c'));}],'path':path[_0x7497('0x2d')](config[_0x7497('0xb')],_0x7497('0x23'),'migrations'),'pattern':/\.js$/}});_0x41605b['up']({'migrations':_[_0x7497('0x2e')](_0x46b665,function(_0x2b3204){return _0x2b3204+_0x7497('0x26');})})[_0x7497('0x2f')](function(){return _0x24136c[_0x7497('0x11')](0xc8)[_0x7497('0x12')]({'output':'Database\x20migrated\x20successfully\x20from\x20version\x20'+module['exports'][_0x7497('0x3')]+_0x7497('0x30')+_[_0x7497('0x31')](_0x46b665),'migrations':_[_0x7497('0x2d')](_0x46b665)});})[_0x7497('0x32')](function(_0x20f57e){if(_0x20f57e instanceof db[_0x7497('0x28')][_0x7497('0x33')]){return _0x24136c['status'](0xc8)[_0x7497('0x12')]({'output':_0x7497('0x34')});}else{return _0x24136c[_0x7497('0x11')](0x1f4)['json'](_0x20f57e);}});}else{return _0x24136c['status'](0xc8)['json']({'output':_0x7497('0x34')});}};