8cc073c9b1b29f82b2c35360582c749800a4f054
[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 _0xeb36=['catch','migrations','join','replace','push','sort','sequelize','getQueryInterface','Migration\x20tried\x20to\x20use\x20old\x20style\x20\x22done\x22\x20callback.\x20Please\x20upgrade\x20to\x20\x22umzug\x22\x20and\x20return\x20a\x20promise\x20instead.','server','map','Database\x20migrated\x20successfully\x20from\x20version\x20','\x20to\x20','Database\x20already\x20up-to-date','umzug','path','pkginfo','version','child_process','exec','../../mysqldb','../../config/environment','../../config/pm2','update','simple-git','root','index','exports','query','latest','2.0.0','status','json','fetch','origin','master','error','info','git\x20fetch','git\x20fetch\x20origin\x20master','reset','--hard','git\x20reset\x20--hard\x20FETCH_HEAD','git\x20reset\x20--hard','pull','npm\x20install\x20--production','restart','then','pm2\x20restart\x20motion\x20%s','Your\x20system\x20has\x20been\x20restart\x20successfully'];(function(_0x18ab2a,_0x4debcd){var _0x16dcee=function(_0x10107a){while(--_0x10107a){_0x18ab2a['push'](_0x18ab2a['shift']());}};_0x16dcee(++_0x4debcd);}(_0xeb36,0xa4));var _0x6eb3=function(_0x4bf606,_0xd9bef8){_0x4bf606=_0x4bf606-0x0;var _0x3e60bb=_0xeb36[_0x4bf606];return _0x3e60bb;};'use strict';var Umzug=require(_0x6eb3('0x0'));var path=require(_0x6eb3('0x1'));var fs=require('fs');var _=require('lodash');var pkginfo=require(_0x6eb3('0x2'))(module,_0x6eb3('0x3'));var compareVersions=require('compare-versions');var exec=require(_0x6eb3('0x4'))[_0x6eb3('0x5')];var db=require(_0x6eb3('0x6'))['db'];var config=require(_0x6eb3('0x7'));var pm2=require(_0x6eb3('0x8'));var logger=require('../../config/logger')(_0x6eb3('0x9'));var git=require(_0x6eb3('0xa'))(config[_0x6eb3('0xb')]);exports[_0x6eb3('0xc')]=function(_0xbbd186,_0x4301f2){var _0x5bf97d={'current':module[_0x6eb3('0xd')][_0x6eb3('0x3')],'phonebar':0x2};if(_0xbbd186[_0x6eb3('0xe')]&&_0xbbd186[_0x6eb3('0xe')]['latest']){return git['fetch']()['tags'](function(_0x1280ef,_0x235b95){_0x5bf97d['latest']=(_0x1280ef?module['exports'][_0x6eb3('0x3')]:_0x235b95[_0x6eb3('0xf')])||_0x6eb3('0x10');return _0x4301f2[_0x6eb3('0x11')](0xc8)[_0x6eb3('0x12')](_0x5bf97d);});}else{return _0x4301f2[_0x6eb3('0x11')](0xc8)['json'](_0x5bf97d);}};exports[_0x6eb3('0x13')]=function(_0x2a6326,_0x107ff8){return git[_0x6eb3('0x13')]([_0x6eb3('0x14'),_0x6eb3('0x15')],function(_0x1eeb1f){if(_0x1eeb1f){logger[_0x6eb3('0x16')](_0x1eeb1f);return _0x107ff8[_0x6eb3('0x11')](0x1f4)[_0x6eb3('0x12')](_0x1eeb1f);}logger[_0x6eb3('0x17')](_0x6eb3('0x18'));return _0x107ff8['status'](0xc8)[_0x6eb3('0x12')]({'output':_0x6eb3('0x19')});});};exports[_0x6eb3('0x1a')]=function(_0x36a582,_0xfc6192){return git[_0x6eb3('0x1a')]([_0x6eb3('0x1b'),'FETCH_HEAD'],function(_0x3a97c4){if(_0x3a97c4){logger['error'](_0x3a97c4);return _0xfc6192[_0x6eb3('0x11')](0x1f4)[_0x6eb3('0x12')](_0x3a97c4);}logger['info'](_0x6eb3('0x1c'));return _0xfc6192[_0x6eb3('0x11')](0xc8)[_0x6eb3('0x12')]({'output':_0x6eb3('0x1d')});});};exports[_0x6eb3('0x1e')]=function(_0x25c72c,_0x470956){exec(_0x6eb3('0x1f'),function(_0x230018,_0x558040,_0x49df09){logger[_0x6eb3('0x17')](_0x558040);logger[_0x6eb3('0x17')](_0x49df09);if(_0x230018){logger[_0x6eb3('0x16')](_0x230018);return _0x470956[_0x6eb3('0x11')](0x1f4)[_0x6eb3('0x12')](_0x230018);}return _0x470956[_0x6eb3('0x11')](0xc8)['json']({'output':_0x558040});});};exports['restart']=function(_0x9c5969,_0x130f96){return pm2[_0x6eb3('0x20')]('motion2')[_0x6eb3('0x21')](function(_0x3ae057){logger[_0x6eb3('0x17')](_0x6eb3('0x22'),_0x3ae057);return _0x130f96[_0x6eb3('0x11')](0xc8)[_0x6eb3('0x12')]({'output':_0x6eb3('0x23')});})[_0x6eb3('0x24')](function(_0x32eaff){logger[_0x6eb3('0x16')](_0x32eaff);return _0x130f96[_0x6eb3('0x11')](0x1f4)[_0x6eb3('0x12')](_0x32eaff);});};exports[_0x6eb3('0x25')]=function(_0x54944b,_0x130947){var _0x41b49b=fs['readdirSync'](path[_0x6eb3('0x26')](config[_0x6eb3('0xb')],'server',_0x6eb3('0x25')));var _0x24d805=[];for(var _0x328777=0x0;_0x328777<_0x41b49b['length'];_0x328777++){var _0x580012=_0x41b49b[_0x328777][_0x6eb3('0x27')]('.js','');if(compareVersions(module['exports'][_0x6eb3('0x3')],_0x580012)===-0x1){_0x24d805[_0x6eb3('0x28')](_0x580012);}}if(_0x24d805['length']){var _0x377e6a=_0x24d805[_0x6eb3('0x29')](compareVersions);var _0x5c1d70=new Umzug({'storage':'sequelize','storageOptions':{'model':db['Migration'],'modelName':'Migration','columnName':_0x6eb3('0x3')},'migrations':{'params':[db[_0x6eb3('0x2a')][_0x6eb3('0x2b')](),db[_0x6eb3('0x2a')]['constructor'],function(){throw new Error(_0x6eb3('0x2c'));}],'path':path['join'](config[_0x6eb3('0xb')],_0x6eb3('0x2d'),_0x6eb3('0x25')),'pattern':/\.js$/}});_0x5c1d70['up']({'migrations':_[_0x6eb3('0x2e')](_0x377e6a,function(_0x5906ec){return _0x5906ec+'.js';})})[_0x6eb3('0x21')](function(){return _0x130947[_0x6eb3('0x11')](0xc8)[_0x6eb3('0x12')]({'output':_0x6eb3('0x2f')+module[_0x6eb3('0xd')]['version']+_0x6eb3('0x30')+_['last'](_0x377e6a),'migrations':_[_0x6eb3('0x26')](_0x377e6a)});})[_0x6eb3('0x24')](function(_0x133e87){if(_0x133e87 instanceof db['sequelize']['UniqueConstraintError']){return _0x130947[_0x6eb3('0x11')](0xc8)[_0x6eb3('0x12')]({'output':_0x6eb3('0x31')});}else{return _0x130947[_0x6eb3('0x11')](0x1f4)[_0x6eb3('0x12')](_0x133e87);}});}else{return _0x130947[_0x6eb3('0x11')](0xc8)[_0x6eb3('0x12')]({'output':'Database\x20already\x20up-to-date'});}};