976234e3ab5399885ae8d3641ae8ac9d10efc637
[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 _0x5670=['version','compare-versions','child_process','exec','../../config/environment','../../config/logger','update','exports','query','fetch','latest','2.0.0','status','json','origin','master','error','git\x20fetch\x20origin\x20master','reset','--hard','FETCH_HEAD','info','git\x20reset\x20--hard\x20FETCH_HEAD','git\x20reset\x20--hard','pull','motion2','then','pm2\x20restart\x20motion\x20%s','Your\x20system\x20has\x20been\x20restart\x20successfully','catch','root','server','migrations','length','replace','.js','push','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','\x20to\x20','last','UniqueConstraintError','Database\x20already\x20up-to-date','umzug','path','lodash','pkginfo'];(function(_0x583521,_0x13811f){var _0x260ba1=function(_0x590ff2){while(--_0x590ff2){_0x583521['push'](_0x583521['shift']());}};_0x260ba1(++_0x13811f);}(_0x5670,0x66));var _0x0567=function(_0x33ec18,_0x36209e){_0x33ec18=_0x33ec18-0x0;var _0x53d7ae=_0x5670[_0x33ec18];return _0x53d7ae;};'use strict';var Umzug=require(_0x0567('0x0'));var path=require(_0x0567('0x1'));var fs=require('fs');var _=require(_0x0567('0x2'));var pkginfo=require(_0x0567('0x3'))(module,_0x0567('0x4'));var compareVersions=require(_0x0567('0x5'));var exec=require(_0x0567('0x6'))[_0x0567('0x7')];var db=require('../../mysqldb')['db'];var config=require(_0x0567('0x8'));var pm2=require('../../config/pm2');var logger=require(_0x0567('0x9'))(_0x0567('0xa'));var git=require('simple-git')(config['root']);exports['index']=function(_0x34ba5e,_0x573b04){var _0x5e8440={'current':module[_0x0567('0xb')]['version'],'phonebar':0x2};if(_0x34ba5e[_0x0567('0xc')]&&_0x34ba5e['query']['latest']){return git[_0x0567('0xd')]()['tags'](function(_0x348148,_0x139996){_0x5e8440[_0x0567('0xe')]=(_0x348148?module[_0x0567('0xb')][_0x0567('0x4')]:_0x139996['latest'])||_0x0567('0xf');return _0x573b04[_0x0567('0x10')](0xc8)[_0x0567('0x11')](_0x5e8440);});}else{return _0x573b04[_0x0567('0x10')](0xc8)[_0x0567('0x11')](_0x5e8440);}};exports[_0x0567('0xd')]=function(_0x215603,_0x96d6fd){return git[_0x0567('0xd')]([_0x0567('0x12'),_0x0567('0x13')],function(_0x365364){if(_0x365364){logger[_0x0567('0x14')](_0x365364);return _0x96d6fd[_0x0567('0x10')](0x1f4)['json'](_0x365364);}logger['info']('git\x20fetch');return _0x96d6fd[_0x0567('0x10')](0xc8)[_0x0567('0x11')]({'output':_0x0567('0x15')});});};exports[_0x0567('0x16')]=function(_0x19f943,_0x5deb84){return git['reset']([_0x0567('0x17'),_0x0567('0x18')],function(_0x1a0d5f){if(_0x1a0d5f){logger['error'](_0x1a0d5f);return _0x5deb84[_0x0567('0x10')](0x1f4)[_0x0567('0x11')](_0x1a0d5f);}logger[_0x0567('0x19')](_0x0567('0x1a'));return _0x5deb84[_0x0567('0x10')](0xc8)[_0x0567('0x11')]({'output':_0x0567('0x1b')});});};exports[_0x0567('0x1c')]=function(_0x25197a,_0xe3cbe6){exec('npm\x20install\x20--production',function(_0x3e0295,_0x284bb0,_0x3a87e5){logger[_0x0567('0x19')](_0x284bb0);logger[_0x0567('0x19')](_0x3a87e5);if(_0x3e0295){logger[_0x0567('0x14')](_0x3e0295);return _0xe3cbe6['status'](0x1f4)[_0x0567('0x11')](_0x3e0295);}return _0xe3cbe6[_0x0567('0x10')](0xc8)[_0x0567('0x11')]({'output':_0x284bb0});});};exports['restart']=function(_0x5d10c9,_0x1a6f00){return pm2['restart'](_0x0567('0x1d'))[_0x0567('0x1e')](function(_0x491a8f){logger[_0x0567('0x19')](_0x0567('0x1f'),_0x491a8f);return _0x1a6f00[_0x0567('0x10')](0xc8)[_0x0567('0x11')]({'output':_0x0567('0x20')});})[_0x0567('0x21')](function(_0x5d85d6){logger['error'](_0x5d85d6);return _0x1a6f00['status'](0x1f4)[_0x0567('0x11')](_0x5d85d6);});};exports['migrations']=function(_0x243e54,_0x2001d2){var _0x1cf561=fs['readdirSync'](path['join'](config[_0x0567('0x22')],_0x0567('0x23'),_0x0567('0x24')));var _0x579599=[];for(var _0x2c1ca6=0x0;_0x2c1ca6<_0x1cf561[_0x0567('0x25')];_0x2c1ca6++){var _0x204ae2=_0x1cf561[_0x2c1ca6][_0x0567('0x26')](_0x0567('0x27'),'');if(compareVersions(module[_0x0567('0xb')][_0x0567('0x4')],_0x204ae2)===-0x1){_0x579599[_0x0567('0x28')](_0x204ae2);}}if(_0x579599[_0x0567('0x25')]){var _0x4f1d53=_0x579599[_0x0567('0x29')](compareVersions);var _0x53f1c6=new Umzug({'storage':_0x0567('0x2a'),'storageOptions':{'model':db[_0x0567('0x2b')],'modelName':_0x0567('0x2b'),'columnName':'version'},'migrations':{'params':[db[_0x0567('0x2a')][_0x0567('0x2c')](),db[_0x0567('0x2a')][_0x0567('0x2d')],function(){throw new Error(_0x0567('0x2e'));}],'path':path[_0x0567('0x2f')](config['root'],_0x0567('0x23'),_0x0567('0x24')),'pattern':/\.js$/}});_0x53f1c6['up']({'migrations':_[_0x0567('0x30')](_0x4f1d53,function(_0x4aa891){return _0x4aa891+_0x0567('0x27');})})['then'](function(){return _0x2001d2[_0x0567('0x10')](0xc8)[_0x0567('0x11')]({'output':'Database\x20migrated\x20successfully\x20from\x20version\x20'+module[_0x0567('0xb')]['version']+_0x0567('0x31')+_[_0x0567('0x32')](_0x4f1d53),'migrations':_[_0x0567('0x2f')](_0x4f1d53)});})[_0x0567('0x21')](function(_0x383d38){if(_0x383d38 instanceof db[_0x0567('0x2a')][_0x0567('0x33')]){return _0x2001d2[_0x0567('0x10')](0xc8)[_0x0567('0x11')]({'output':_0x0567('0x34')});}else{return _0x2001d2['status'](0x1f4)['json'](_0x383d38);}});}else{return _0x2001d2['status'](0xc8)[_0x0567('0x11')]({'output':_0x0567('0x34')});}};