0190b9a76e61f8ecf709cff0dbc39bf73753718d
[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 _0x5800=['getQueryInterface','Migration\x20tried\x20to\x20use\x20old\x20style\x20\x22done\x22\x20callback.\x20Please\x20upgrade\x20to\x20\x22umzug\x22\x20and\x20return\x20a\x20promise\x20instead.','join','map','Database\x20migrated\x20successfully\x20from\x20version\x20','\x20to\x20','last','UniqueConstraintError','Database\x20already\x20up-to-date','path','lodash','pkginfo','version','child_process','exec','../../config/environment','update','simple-git','index','exports','query','latest','fetch','tags','status','json','origin','master','error','info','git\x20fetch\x20origin\x20master','reset','--hard','FETCH_HEAD','git\x20reset\x20--hard\x20FETCH_HEAD','pull','npm\x20install\x20--production','restart','motion2','then','pm2\x20restart\x20motion\x20%s','Your\x20system\x20has\x20been\x20restart\x20successfully','catch','readdirSync','root','server','migrations','length','replace','.js','push','sort','sequelize','Migration'];(function(_0x47dd12,_0x2ac0e0){var _0x5a2e04=function(_0x73cb8){while(--_0x73cb8){_0x47dd12['push'](_0x47dd12['shift']());}};_0x5a2e04(++_0x2ac0e0);}(_0x5800,0x1b9));var _0x0580=function(_0x21ff61,_0x4b2027){_0x21ff61=_0x21ff61-0x0;var _0x21cf68=_0x5800[_0x21ff61];return _0x21cf68;};'use strict';var Umzug=require('umzug');var path=require(_0x0580('0x0'));var fs=require('fs');var _=require(_0x0580('0x1'));var pkginfo=require(_0x0580('0x2'))(module,_0x0580('0x3'));var compareVersions=require('compare-versions');var exec=require(_0x0580('0x4'))[_0x0580('0x5')];var db=require('../../mysqldb')['db'];var config=require(_0x0580('0x6'));var pm2=require('../../config/pm2');var logger=require('../../config/logger')(_0x0580('0x7'));var git=require(_0x0580('0x8'))(config['root']);exports[_0x0580('0x9')]=function(_0x5c4ab8,_0x1e4b42){var _0x51bb48={'current':module[_0x0580('0xa')][_0x0580('0x3')],'phonebar':0x2};if(_0x5c4ab8[_0x0580('0xb')]&&_0x5c4ab8[_0x0580('0xb')][_0x0580('0xc')]){return git[_0x0580('0xd')]()[_0x0580('0xe')](function(_0x1edc39,_0x4a6786){_0x51bb48[_0x0580('0xc')]=(_0x1edc39?module[_0x0580('0xa')][_0x0580('0x3')]:_0x4a6786['latest'])||'2.0.0';return _0x1e4b42[_0x0580('0xf')](0xc8)[_0x0580('0x10')](_0x51bb48);});}else{return _0x1e4b42[_0x0580('0xf')](0xc8)['json'](_0x51bb48);}};exports[_0x0580('0xd')]=function(_0x41ec01,_0x45d8b2){return git['fetch']([_0x0580('0x11'),_0x0580('0x12')],function(_0x473bcd){if(_0x473bcd){logger[_0x0580('0x13')](_0x473bcd);return _0x45d8b2[_0x0580('0xf')](0x1f4)[_0x0580('0x10')](_0x473bcd);}logger[_0x0580('0x14')]('git\x20fetch');return _0x45d8b2[_0x0580('0xf')](0xc8)[_0x0580('0x10')]({'output':_0x0580('0x15')});});};exports[_0x0580('0x16')]=function(_0x18739d,_0x549e64){return git[_0x0580('0x16')]([_0x0580('0x17'),_0x0580('0x18')],function(_0x5b3db9){if(_0x5b3db9){logger[_0x0580('0x13')](_0x5b3db9);return _0x549e64[_0x0580('0xf')](0x1f4)[_0x0580('0x10')](_0x5b3db9);}logger[_0x0580('0x14')](_0x0580('0x19'));return _0x549e64[_0x0580('0xf')](0xc8)[_0x0580('0x10')]({'output':'git\x20reset\x20--hard'});});};exports[_0x0580('0x1a')]=function(_0x3c9415,_0xab9d36){exec(_0x0580('0x1b'),function(_0x23cfa8,_0x36f360,_0x180fc3){logger[_0x0580('0x14')](_0x36f360);logger[_0x0580('0x14')](_0x180fc3);if(_0x23cfa8){logger[_0x0580('0x13')](_0x23cfa8);return _0xab9d36[_0x0580('0xf')](0x1f4)[_0x0580('0x10')](_0x23cfa8);}return _0xab9d36[_0x0580('0xf')](0xc8)['json']({'output':_0x36f360});});};exports['restart']=function(_0x137ac6,_0x5ee76e){return pm2[_0x0580('0x1c')](_0x0580('0x1d'))[_0x0580('0x1e')](function(_0x1833db){logger[_0x0580('0x14')](_0x0580('0x1f'),_0x1833db);return _0x5ee76e[_0x0580('0xf')](0xc8)[_0x0580('0x10')]({'output':_0x0580('0x20')});})[_0x0580('0x21')](function(_0x22a5c2){logger['error'](_0x22a5c2);return _0x5ee76e[_0x0580('0xf')](0x1f4)[_0x0580('0x10')](_0x22a5c2);});};exports['migrations']=function(_0x36333e,_0x2720f3){var _0xae8068=fs[_0x0580('0x22')](path['join'](config[_0x0580('0x23')],_0x0580('0x24'),_0x0580('0x25')));var _0x457f1b=[];for(var _0x2522df=0x0;_0x2522df<_0xae8068[_0x0580('0x26')];_0x2522df++){var _0x3429ed=_0xae8068[_0x2522df][_0x0580('0x27')](_0x0580('0x28'),'');if(compareVersions(module[_0x0580('0xa')][_0x0580('0x3')],_0x3429ed)===-0x1){_0x457f1b[_0x0580('0x29')](_0x3429ed);}}if(_0x457f1b['length']){var _0x5227ed=_0x457f1b[_0x0580('0x2a')](compareVersions);var _0x1eaef0=new Umzug({'storage':_0x0580('0x2b'),'storageOptions':{'model':db[_0x0580('0x2c')],'modelName':_0x0580('0x2c'),'columnName':_0x0580('0x3')},'migrations':{'params':[db[_0x0580('0x2b')][_0x0580('0x2d')](),db[_0x0580('0x2b')]['constructor'],function(){throw new Error(_0x0580('0x2e'));}],'path':path[_0x0580('0x2f')](config[_0x0580('0x23')],_0x0580('0x24'),_0x0580('0x25')),'pattern':/\.js$/}});_0x1eaef0['up']({'migrations':_[_0x0580('0x30')](_0x5227ed,function(_0x4ce695){return _0x4ce695+_0x0580('0x28');})})['then'](function(){return _0x2720f3['status'](0xc8)[_0x0580('0x10')]({'output':_0x0580('0x31')+module[_0x0580('0xa')][_0x0580('0x3')]+_0x0580('0x32')+_[_0x0580('0x33')](_0x5227ed),'migrations':_['join'](_0x5227ed)});})[_0x0580('0x21')](function(_0xb89e6c){if(_0xb89e6c instanceof db[_0x0580('0x2b')][_0x0580('0x34')]){return _0x2720f3['status'](0xc8)[_0x0580('0x10')]({'output':_0x0580('0x35')});}else{return _0x2720f3['status'](0x1f4)[_0x0580('0x10')](_0xb89e6c);}});}else{return _0x2720f3[_0x0580('0xf')](0xc8)[_0x0580('0x10')]({'output':'Database\x20already\x20up-to-date'});}};