eb7bd7ab805f8bc9759db94ec60218d265cecdcd
[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 _0xce88=['getQueryInterface','constructor','Migration\x20tried\x20to\x20use\x20old\x20style\x20\x22done\x22\x20callback.\x20Please\x20upgrade\x20to\x20\x22umzug\x22\x20and\x20return\x20a\x20promise\x20instead.','map','\x20to\x20','UniqueConstraintError','Database\x20already\x20up-to-date','umzug','path','pkginfo','version','compare-versions','child_process','exec','../../config/environment','../../config/pm2','update','simple-git','root','index','exports','query','fetch','tags','latest','2.0.0','status','origin','master','error','git\x20fetch','json','git\x20fetch\x20origin\x20master','reset','FETCH_HEAD','info','git\x20reset\x20--hard\x20FETCH_HEAD','pull','restart','motion2','then','pm2\x20restart\x20motion\x20%s','Your\x20system\x20has\x20been\x20restart\x20successfully','catch','readdirSync','join','server','migrations','length','replace','.js','push','Migration','sequelize'];(function(_0x54fdf9,_0x2dd76c){var _0x408938=function(_0x2990d3){while(--_0x2990d3){_0x54fdf9['push'](_0x54fdf9['shift']());}};_0x408938(++_0x2dd76c);}(_0xce88,0x181));var _0x8ce8=function(_0x13e741,_0x5d3c24){_0x13e741=_0x13e741-0x0;var _0x3f8bb3=_0xce88[_0x13e741];return _0x3f8bb3;};'use strict';var Umzug=require(_0x8ce8('0x0'));var path=require(_0x8ce8('0x1'));var fs=require('fs');var _=require('lodash');var pkginfo=require(_0x8ce8('0x2'))(module,_0x8ce8('0x3'));var compareVersions=require(_0x8ce8('0x4'));var exec=require(_0x8ce8('0x5'))[_0x8ce8('0x6')];var db=require('../../mysqldb')['db'];var config=require(_0x8ce8('0x7'));var pm2=require(_0x8ce8('0x8'));var logger=require('../../config/logger')(_0x8ce8('0x9'));var git=require(_0x8ce8('0xa'))(config[_0x8ce8('0xb')]);exports[_0x8ce8('0xc')]=function(_0x474ffe,_0x38d83d){var _0x196a85={'current':module[_0x8ce8('0xd')][_0x8ce8('0x3')],'phonebar':0x2};if(_0x474ffe[_0x8ce8('0xe')]&&_0x474ffe[_0x8ce8('0xe')]['latest']){return git[_0x8ce8('0xf')]()[_0x8ce8('0x10')](function(_0x111ced,_0x54366b){_0x196a85[_0x8ce8('0x11')]=(_0x111ced?module['exports'][_0x8ce8('0x3')]:_0x54366b[_0x8ce8('0x11')])||_0x8ce8('0x12');return _0x38d83d[_0x8ce8('0x13')](0xc8)['json'](_0x196a85);});}else{return _0x38d83d['status'](0xc8)['json'](_0x196a85);}};exports['fetch']=function(_0x9f9735,_0x446478){return git[_0x8ce8('0xf')]([_0x8ce8('0x14'),_0x8ce8('0x15')],function(_0x5834ee){if(_0x5834ee){logger[_0x8ce8('0x16')](_0x5834ee);return _0x446478[_0x8ce8('0x13')](0x1f4)['json'](_0x5834ee);}logger['info'](_0x8ce8('0x17'));return _0x446478[_0x8ce8('0x13')](0xc8)[_0x8ce8('0x18')]({'output':_0x8ce8('0x19')});});};exports[_0x8ce8('0x1a')]=function(_0x2cfd4e,_0x497495){return git[_0x8ce8('0x1a')](['--hard',_0x8ce8('0x1b')],function(_0x2f1c26){if(_0x2f1c26){logger['error'](_0x2f1c26);return _0x497495[_0x8ce8('0x13')](0x1f4)[_0x8ce8('0x18')](_0x2f1c26);}logger[_0x8ce8('0x1c')](_0x8ce8('0x1d'));return _0x497495['status'](0xc8)['json']({'output':'git\x20reset\x20--hard'});});};exports[_0x8ce8('0x1e')]=function(_0x2af22a,_0x2b3b39){exec('npm\x20install\x20--production',function(_0x147d3d,_0x186cf4,_0x1eaf41){logger['info'](_0x186cf4);logger['info'](_0x1eaf41);if(_0x147d3d){logger[_0x8ce8('0x16')](_0x147d3d);return _0x2b3b39[_0x8ce8('0x13')](0x1f4)['json'](_0x147d3d);}return _0x2b3b39[_0x8ce8('0x13')](0xc8)[_0x8ce8('0x18')]({'output':_0x186cf4});});};exports[_0x8ce8('0x1f')]=function(_0x522824,_0x5a3aae){return pm2[_0x8ce8('0x1f')](_0x8ce8('0x20'))[_0x8ce8('0x21')](function(_0x5e9076){logger['info'](_0x8ce8('0x22'),_0x5e9076);return _0x5a3aae[_0x8ce8('0x13')](0xc8)['json']({'output':_0x8ce8('0x23')});})[_0x8ce8('0x24')](function(_0x1e4960){logger[_0x8ce8('0x16')](_0x1e4960);return _0x5a3aae[_0x8ce8('0x13')](0x1f4)['json'](_0x1e4960);});};exports['migrations']=function(_0x2e1005,_0x536035){var _0x5137d9=fs[_0x8ce8('0x25')](path[_0x8ce8('0x26')](config['root'],_0x8ce8('0x27'),_0x8ce8('0x28')));var _0x2c3bbd=[];for(var _0x1a6aa7=0x0;_0x1a6aa7<_0x5137d9[_0x8ce8('0x29')];_0x1a6aa7++){var _0x205028=_0x5137d9[_0x1a6aa7][_0x8ce8('0x2a')](_0x8ce8('0x2b'),'');if(compareVersions(module['exports'][_0x8ce8('0x3')],_0x205028)===-0x1){_0x2c3bbd[_0x8ce8('0x2c')](_0x205028);}}if(_0x2c3bbd[_0x8ce8('0x29')]){var _0x472177=_0x2c3bbd['sort'](compareVersions);var _0x170842=new Umzug({'storage':'sequelize','storageOptions':{'model':db['Migration'],'modelName':_0x8ce8('0x2d'),'columnName':_0x8ce8('0x3')},'migrations':{'params':[db[_0x8ce8('0x2e')][_0x8ce8('0x2f')](),db[_0x8ce8('0x2e')][_0x8ce8('0x30')],function(){throw new Error(_0x8ce8('0x31'));}],'path':path[_0x8ce8('0x26')](config['root'],_0x8ce8('0x27'),_0x8ce8('0x28')),'pattern':/\.js$/}});_0x170842['up']({'migrations':_[_0x8ce8('0x32')](_0x472177,function(_0x4b166a){return _0x4b166a+_0x8ce8('0x2b');})})[_0x8ce8('0x21')](function(){return _0x536035[_0x8ce8('0x13')](0xc8)['json']({'output':'Database\x20migrated\x20successfully\x20from\x20version\x20'+module['exports'][_0x8ce8('0x3')]+_0x8ce8('0x33')+_['last'](_0x472177),'migrations':_[_0x8ce8('0x26')](_0x472177)});})['catch'](function(_0x1443ad){if(_0x1443ad instanceof db['sequelize'][_0x8ce8('0x34')]){return _0x536035[_0x8ce8('0x13')](0xc8)['json']({'output':'Database\x20already\x20up-to-date'});}else{return _0x536035['status'](0x1f4)[_0x8ce8('0x18')](_0x1443ad);}});}else{return _0x536035[_0x8ce8('0x13')](0xc8)[_0x8ce8('0x18')]({'output':_0x8ce8('0x35')});}};