1369a534f8b5a6641b24f5fe4bde63223137110c
[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 _0x4d63=['Database\x20migrated\x20successfully\x20from\x20version\x20','\x20to\x20','Database\x20already\x20up-to-date','umzug','path','compare-versions','../../mysqldb','../../config/environment','../../config/logger','simple-git','root','index','exports','version','query','latest','tags','2.0.0','json','fetch','master','error','git\x20fetch\x20origin\x20master','reset','--hard','status','info','git\x20reset\x20--hard','pull','npm\x20install\x20--production','restart','motion2','then','Your\x20system\x20has\x20been\x20restart\x20successfully','catch','readdirSync','server','migrations','replace','.js','push','length','sort','Migration','sequelize','getQueryInterface','join','map'];(function(_0x53b74a,_0x40eddd){var _0x5a7c78=function(_0x465f38){while(--_0x465f38){_0x53b74a['push'](_0x53b74a['shift']());}};_0x5a7c78(++_0x40eddd);}(_0x4d63,0xf3));var _0x34d6=function(_0x2641f9,_0x26715f){_0x2641f9=_0x2641f9-0x0;var _0x585741=_0x4d63[_0x2641f9];return _0x585741;};'use strict';var Umzug=require(_0x34d6('0x0'));var path=require(_0x34d6('0x1'));var fs=require('fs');var _=require('lodash');var pkginfo=require('pkginfo')(module,'version');var compareVersions=require(_0x34d6('0x2'));var exec=require('child_process')['exec'];var db=require(_0x34d6('0x3'))['db'];var config=require(_0x34d6('0x4'));var pm2=require('../../config/pm2');var logger=require(_0x34d6('0x5'))('update');var git=require(_0x34d6('0x6'))(config[_0x34d6('0x7')]);exports[_0x34d6('0x8')]=function(_0x465cd1,_0x13b571){var _0xe9d64b={'current':module[_0x34d6('0x9')][_0x34d6('0xa')],'phonebar':0x2};if(_0x465cd1[_0x34d6('0xb')]&&_0x465cd1[_0x34d6('0xb')][_0x34d6('0xc')]){return git['fetch']()[_0x34d6('0xd')](function(_0x28db60,_0x128eb1){_0xe9d64b[_0x34d6('0xc')]=(_0x28db60?module[_0x34d6('0x9')][_0x34d6('0xa')]:_0x128eb1[_0x34d6('0xc')])||_0x34d6('0xe');return _0x13b571['status'](0xc8)[_0x34d6('0xf')](_0xe9d64b);});}else{return _0x13b571['status'](0xc8)[_0x34d6('0xf')](_0xe9d64b);}};exports[_0x34d6('0x10')]=function(_0x338f6e,_0x4b72c6){return git[_0x34d6('0x10')](['origin',_0x34d6('0x11')],function(_0x5c2a1a){if(_0x5c2a1a){logger[_0x34d6('0x12')](_0x5c2a1a);return _0x4b72c6['status'](0x1f4)['json'](_0x5c2a1a);}logger['info']('git\x20fetch');return _0x4b72c6['status'](0xc8)[_0x34d6('0xf')]({'output':_0x34d6('0x13')});});};exports['reset']=function(_0x9bcf5c,_0x1807a0){return git[_0x34d6('0x14')]([_0x34d6('0x15'),'FETCH_HEAD'],function(_0x370ef8){if(_0x370ef8){logger[_0x34d6('0x12')](_0x370ef8);return _0x1807a0[_0x34d6('0x16')](0x1f4)['json'](_0x370ef8);}logger[_0x34d6('0x17')]('git\x20reset\x20--hard\x20FETCH_HEAD');return _0x1807a0[_0x34d6('0x16')](0xc8)['json']({'output':_0x34d6('0x18')});});};exports[_0x34d6('0x19')]=function(_0x7ee1de,_0x152ff2){exec(_0x34d6('0x1a'),function(_0x163269,_0x4f5bd6,_0x4e6ba7){logger[_0x34d6('0x17')](_0x4f5bd6);logger[_0x34d6('0x17')](_0x4e6ba7);if(_0x163269){logger[_0x34d6('0x12')](_0x163269);return _0x152ff2['status'](0x1f4)[_0x34d6('0xf')](_0x163269);}return _0x152ff2[_0x34d6('0x16')](0xc8)['json']({'output':_0x4f5bd6});});};exports['restart']=function(_0x31ddb8,_0x111870){return pm2[_0x34d6('0x1b')](_0x34d6('0x1c'))[_0x34d6('0x1d')](function(_0x4ed111){logger[_0x34d6('0x17')]('pm2\x20restart\x20motion\x20%s',_0x4ed111);return _0x111870[_0x34d6('0x16')](0xc8)['json']({'output':_0x34d6('0x1e')});})[_0x34d6('0x1f')](function(_0x5d9a48){logger[_0x34d6('0x12')](_0x5d9a48);return _0x111870[_0x34d6('0x16')](0x1f4)[_0x34d6('0xf')](_0x5d9a48);});};exports['migrations']=function(_0x40e3ae,_0x24f8da){var _0x3a72ce=fs[_0x34d6('0x20')](path['join'](config[_0x34d6('0x7')],_0x34d6('0x21'),_0x34d6('0x22')));var _0x509636=[];for(var _0x2f6b3c=0x0;_0x2f6b3c<_0x3a72ce['length'];_0x2f6b3c++){var _0x3806bb=_0x3a72ce[_0x2f6b3c][_0x34d6('0x23')](_0x34d6('0x24'),'');if(compareVersions(module[_0x34d6('0x9')]['version'],_0x3806bb)===-0x1){_0x509636[_0x34d6('0x25')](_0x3806bb);}}if(_0x509636[_0x34d6('0x26')]){var _0x3f33e1=_0x509636[_0x34d6('0x27')](compareVersions);var _0x196937=new Umzug({'storage':'sequelize','storageOptions':{'model':db[_0x34d6('0x28')],'modelName':_0x34d6('0x28'),'columnName':_0x34d6('0xa')},'migrations':{'params':[db[_0x34d6('0x29')][_0x34d6('0x2a')](),db[_0x34d6('0x29')]['constructor'],function(){throw new Error('Migration\x20tried\x20to\x20use\x20old\x20style\x20\x22done\x22\x20callback.\x20Please\x20upgrade\x20to\x20\x22umzug\x22\x20and\x20return\x20a\x20promise\x20instead.');}],'path':path[_0x34d6('0x2b')](config[_0x34d6('0x7')],_0x34d6('0x21'),'migrations'),'pattern':/\.js$/}});_0x196937['up']({'migrations':_[_0x34d6('0x2c')](_0x3f33e1,function(_0x33f612){return _0x33f612+_0x34d6('0x24');})})['then'](function(){return _0x24f8da[_0x34d6('0x16')](0xc8)[_0x34d6('0xf')]({'output':_0x34d6('0x2d')+module[_0x34d6('0x9')][_0x34d6('0xa')]+_0x34d6('0x2e')+_['last'](_0x3f33e1),'migrations':_[_0x34d6('0x2b')](_0x3f33e1)});})[_0x34d6('0x1f')](function(_0x4b88dc){if(_0x4b88dc instanceof db[_0x34d6('0x29')]['UniqueConstraintError']){return _0x24f8da[_0x34d6('0x16')](0xc8)[_0x34d6('0xf')]({'output':_0x34d6('0x2f')});}else{return _0x24f8da[_0x34d6('0x16')](0x1f4)['json'](_0x4b88dc);}});}else{return _0x24f8da[_0x34d6('0x16')](0xc8)[_0x34d6('0xf')]({'output':_0x34d6('0x2f')});}};