Built motion from commit c0cdc9d8.|2.6.28
[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 _0xf6c4=['root','index','query','fetch','tags','latest','exports','2.0.0','status','json','origin','master','error','info','git\x20fetch','git\x20fetch\x20origin\x20master','reset','git\x20reset\x20--hard\x20FETCH_HEAD','pull','npm\x20install\x20--production','restart','motion2','then','pm2\x20restart\x20motion\x20%s','readdirSync','migrations','length','replace','.js','push','Migration','sequelize','constructor','Migration\x20tried\x20to\x20use\x20old\x20style\x20\x22done\x22\x20callback.\x20Please\x20upgrade\x20to\x20\x22umzug\x22\x20and\x20return\x20a\x20promise\x20instead.','join','server','map','catch','UniqueConstraintError','Database\x20already\x20up-to-date','umzug','path','lodash','version','compare-versions','child_process','../../mysqldb','../../config/environment','../../config/logger','update'];(function(_0x58518e,_0x13cc8d){var _0x658794=function(_0x484530){while(--_0x484530){_0x58518e['push'](_0x58518e['shift']());}};_0x658794(++_0x13cc8d);}(_0xf6c4,0x8c));var _0x4f6c=function(_0xa9281c,_0x4ec723){_0xa9281c=_0xa9281c-0x0;var _0x99b105=_0xf6c4[_0xa9281c];return _0x99b105;};'use strict';var Umzug=require(_0x4f6c('0x0'));var path=require(_0x4f6c('0x1'));var fs=require('fs');var _=require(_0x4f6c('0x2'));var pkginfo=require('pkginfo')(module,_0x4f6c('0x3'));var compareVersions=require(_0x4f6c('0x4'));var exec=require(_0x4f6c('0x5'))['exec'];var db=require(_0x4f6c('0x6'))['db'];var config=require(_0x4f6c('0x7'));var pm2=require('../../config/pm2');var logger=require(_0x4f6c('0x8'))(_0x4f6c('0x9'));var git=require('simple-git')(config[_0x4f6c('0xa')]);exports[_0x4f6c('0xb')]=function(_0x21a707,_0x3ef6c8){var _0x5c4a02={'current':module['exports'][_0x4f6c('0x3')],'phonebar':0x2};if(_0x21a707[_0x4f6c('0xc')]&&_0x21a707[_0x4f6c('0xc')]['latest']){return git[_0x4f6c('0xd')]()[_0x4f6c('0xe')](function(_0x310178,_0x151cc2){_0x5c4a02[_0x4f6c('0xf')]=(_0x310178?module[_0x4f6c('0x10')][_0x4f6c('0x3')]:_0x151cc2['latest'])||_0x4f6c('0x11');return _0x3ef6c8[_0x4f6c('0x12')](0xc8)[_0x4f6c('0x13')](_0x5c4a02);});}else{return _0x3ef6c8[_0x4f6c('0x12')](0xc8)['json'](_0x5c4a02);}};exports[_0x4f6c('0xd')]=function(_0x3a5ab9,_0x21f384){return git[_0x4f6c('0xd')]([_0x4f6c('0x14'),_0x4f6c('0x15')],function(_0x56b841){if(_0x56b841){logger[_0x4f6c('0x16')](_0x56b841);return _0x21f384[_0x4f6c('0x12')](0x1f4)[_0x4f6c('0x13')](_0x56b841);}logger[_0x4f6c('0x17')](_0x4f6c('0x18'));return _0x21f384[_0x4f6c('0x12')](0xc8)[_0x4f6c('0x13')]({'output':_0x4f6c('0x19')});});};exports[_0x4f6c('0x1a')]=function(_0x42ed5a,_0x541ad0){return git['reset'](['--hard','FETCH_HEAD'],function(_0x3c9732){if(_0x3c9732){logger[_0x4f6c('0x16')](_0x3c9732);return _0x541ad0[_0x4f6c('0x12')](0x1f4)[_0x4f6c('0x13')](_0x3c9732);}logger[_0x4f6c('0x17')](_0x4f6c('0x1b'));return _0x541ad0[_0x4f6c('0x12')](0xc8)['json']({'output':'git\x20reset\x20--hard'});});};exports[_0x4f6c('0x1c')]=function(_0x2ed627,_0x2a4ad3){exec(_0x4f6c('0x1d'),function(_0x3c5508,_0x5b55fe,_0x37749c){logger['info'](_0x5b55fe);logger[_0x4f6c('0x17')](_0x37749c);if(_0x3c5508){logger['error'](_0x3c5508);return _0x2a4ad3[_0x4f6c('0x12')](0x1f4)['json'](_0x3c5508);}return _0x2a4ad3[_0x4f6c('0x12')](0xc8)[_0x4f6c('0x13')]({'output':_0x5b55fe});});};exports[_0x4f6c('0x1e')]=function(_0x4d3171,_0x596071){return pm2['restart'](_0x4f6c('0x1f'))[_0x4f6c('0x20')](function(_0x5cfb41){logger[_0x4f6c('0x17')](_0x4f6c('0x21'),_0x5cfb41);return _0x596071['status'](0xc8)['json']({'output':'Your\x20system\x20has\x20been\x20restart\x20successfully'});})['catch'](function(_0x24095d){logger[_0x4f6c('0x16')](_0x24095d);return _0x596071[_0x4f6c('0x12')](0x1f4)['json'](_0x24095d);});};exports['migrations']=function(_0x2aa934,_0x37233a){var _0x5c7927=fs[_0x4f6c('0x22')](path['join'](config[_0x4f6c('0xa')],'server',_0x4f6c('0x23')));var _0x57ff7d=[];for(var _0x2917fe=0x0;_0x2917fe<_0x5c7927[_0x4f6c('0x24')];_0x2917fe++){var _0x1fa00c=_0x5c7927[_0x2917fe][_0x4f6c('0x25')](_0x4f6c('0x26'),'');if(compareVersions(module['exports'][_0x4f6c('0x3')],_0x1fa00c)===-0x1){_0x57ff7d[_0x4f6c('0x27')](_0x1fa00c);}}if(_0x57ff7d['length']){var _0xf1d192=_0x57ff7d['sort'](compareVersions);var _0x5b0bed=new Umzug({'storage':'sequelize','storageOptions':{'model':db[_0x4f6c('0x28')],'modelName':_0x4f6c('0x28'),'columnName':'version'},'migrations':{'params':[db[_0x4f6c('0x29')]['getQueryInterface'](),db['sequelize'][_0x4f6c('0x2a')],function(){throw new Error(_0x4f6c('0x2b'));}],'path':path[_0x4f6c('0x2c')](config[_0x4f6c('0xa')],_0x4f6c('0x2d'),'migrations'),'pattern':/\.js$/}});_0x5b0bed['up']({'migrations':_[_0x4f6c('0x2e')](_0xf1d192,function(_0x361b9d){return _0x361b9d+'.js';})})[_0x4f6c('0x20')](function(){return _0x37233a[_0x4f6c('0x12')](0xc8)['json']({'output':'Database\x20migrated\x20successfully\x20from\x20version\x20'+module['exports'][_0x4f6c('0x3')]+'\x20to\x20'+_['last'](_0xf1d192),'migrations':_[_0x4f6c('0x2c')](_0xf1d192)});})[_0x4f6c('0x2f')](function(_0x12e6dd){if(_0x12e6dd instanceof db[_0x4f6c('0x29')][_0x4f6c('0x30')]){return _0x37233a[_0x4f6c('0x12')](0xc8)[_0x4f6c('0x13')]({'output':'Database\x20already\x20up-to-date'});}else{return _0x37233a['status'](0x1f4)[_0x4f6c('0x13')](_0x12e6dd);}});}else{return _0x37233a[_0x4f6c('0x12')](0xc8)[_0x4f6c('0x13')]({'output':_0x4f6c('0x31')});}};