22d7b817948cebaa92a60eedbbf56ace2c14e0f3
[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 _0x5f66=['../../config/logger','update','index','exports','latest','fetch','tags','status','json','origin','master','error','git\x20fetch\x20origin\x20master','reset','--hard','git\x20reset\x20--hard\x20FETCH_HEAD','git\x20reset\x20--hard','pull','npm\x20install\x20--production','restart','motion2','then','catch','migrations','readdirSync','join','root','server','replace','.js','push','length','sort','sequelize','Migration','constructor','Migration\x20tried\x20to\x20use\x20old\x20style\x20\x22done\x22\x20callback.\x20Please\x20upgrade\x20to\x20\x22umzug\x22\x20and\x20return\x20a\x20promise\x20instead.','map','last','UniqueConstraintError','path','pkginfo','version','compare-versions','child_process','exec','../../config/environment'];(function(_0x4709c0,_0x3396c7){var _0x13348b=function(_0x426235){while(--_0x426235){_0x4709c0['push'](_0x4709c0['shift']());}};_0x13348b(++_0x3396c7);}(_0x5f66,0x1a0));var _0x65f6=function(_0x19e35c,_0x29cd1e){_0x19e35c=_0x19e35c-0x0;var _0x3e1fe8=_0x5f66[_0x19e35c];return _0x3e1fe8;};'use strict';var Umzug=require('umzug');var path=require(_0x65f6('0x0'));var fs=require('fs');var _=require('lodash');var pkginfo=require(_0x65f6('0x1'))(module,_0x65f6('0x2'));var compareVersions=require(_0x65f6('0x3'));var exec=require(_0x65f6('0x4'))[_0x65f6('0x5')];var db=require('../../mysqldb')['db'];var config=require(_0x65f6('0x6'));var pm2=require('../../config/pm2');var logger=require(_0x65f6('0x7'))(_0x65f6('0x8'));var git=require('simple-git')(config['root']);exports[_0x65f6('0x9')]=function(_0x2c6571,_0x112079){var _0x8f6451={'current':module[_0x65f6('0xa')][_0x65f6('0x2')],'phonebar':0x2};if(_0x2c6571['query']&&_0x2c6571['query'][_0x65f6('0xb')]){return git[_0x65f6('0xc')]()[_0x65f6('0xd')](function(_0x25c416,_0x50d26d){_0x8f6451[_0x65f6('0xb')]=(_0x25c416?module['exports']['version']:_0x50d26d[_0x65f6('0xb')])||'2.0.0';return _0x112079[_0x65f6('0xe')](0xc8)['json'](_0x8f6451);});}else{return _0x112079[_0x65f6('0xe')](0xc8)[_0x65f6('0xf')](_0x8f6451);}};exports[_0x65f6('0xc')]=function(_0x217570,_0x369f96){return git[_0x65f6('0xc')]([_0x65f6('0x10'),_0x65f6('0x11')],function(_0x46dbc6){if(_0x46dbc6){logger[_0x65f6('0x12')](_0x46dbc6);return _0x369f96['status'](0x1f4)[_0x65f6('0xf')](_0x46dbc6);}logger['info']('git\x20fetch');return _0x369f96[_0x65f6('0xe')](0xc8)[_0x65f6('0xf')]({'output':_0x65f6('0x13')});});};exports[_0x65f6('0x14')]=function(_0x1b1cbb,_0x1f974c){return git[_0x65f6('0x14')]([_0x65f6('0x15'),'FETCH_HEAD'],function(_0x4d79a1){if(_0x4d79a1){logger[_0x65f6('0x12')](_0x4d79a1);return _0x1f974c['status'](0x1f4)['json'](_0x4d79a1);}logger['info'](_0x65f6('0x16'));return _0x1f974c[_0x65f6('0xe')](0xc8)['json']({'output':_0x65f6('0x17')});});};exports[_0x65f6('0x18')]=function(_0xbee6a4,_0x3876ed){exec(_0x65f6('0x19'),function(_0xc139c2,_0x581374,_0x197a49){logger['info'](_0x581374);logger['info'](_0x197a49);if(_0xc139c2){logger[_0x65f6('0x12')](_0xc139c2);return _0x3876ed[_0x65f6('0xe')](0x1f4)['json'](_0xc139c2);}return _0x3876ed[_0x65f6('0xe')](0xc8)[_0x65f6('0xf')]({'output':_0x581374});});};exports[_0x65f6('0x1a')]=function(_0x2774a1,_0x4f5a69){return pm2[_0x65f6('0x1a')](_0x65f6('0x1b'))[_0x65f6('0x1c')](function(_0x5963e0){logger['info']('pm2\x20restart\x20motion\x20%s',_0x5963e0);return _0x4f5a69[_0x65f6('0xe')](0xc8)[_0x65f6('0xf')]({'output':'Your\x20system\x20has\x20been\x20restart\x20successfully'});})[_0x65f6('0x1d')](function(_0x28f710){logger['error'](_0x28f710);return _0x4f5a69[_0x65f6('0xe')](0x1f4)[_0x65f6('0xf')](_0x28f710);});};exports[_0x65f6('0x1e')]=function(_0x559330,_0x4ac04b){var _0x488d36=fs[_0x65f6('0x1f')](path[_0x65f6('0x20')](config[_0x65f6('0x21')],_0x65f6('0x22'),_0x65f6('0x1e')));var _0x14a387=[];for(var _0x144e55=0x0;_0x144e55<_0x488d36['length'];_0x144e55++){var _0x4ea23d=_0x488d36[_0x144e55][_0x65f6('0x23')](_0x65f6('0x24'),'');if(compareVersions(module['exports']['version'],_0x4ea23d)===-0x1){_0x14a387[_0x65f6('0x25')](_0x4ea23d);}}if(_0x14a387[_0x65f6('0x26')]){var _0x11fe3b=_0x14a387[_0x65f6('0x27')](compareVersions);var _0x1217fd=new Umzug({'storage':_0x65f6('0x28'),'storageOptions':{'model':db['Migration'],'modelName':_0x65f6('0x29'),'columnName':_0x65f6('0x2')},'migrations':{'params':[db[_0x65f6('0x28')]['getQueryInterface'](),db[_0x65f6('0x28')][_0x65f6('0x2a')],function(){throw new Error(_0x65f6('0x2b'));}],'path':path[_0x65f6('0x20')](config[_0x65f6('0x21')],_0x65f6('0x22'),'migrations'),'pattern':/\.js$/}});_0x1217fd['up']({'migrations':_[_0x65f6('0x2c')](_0x11fe3b,function(_0x1b24ea){return _0x1b24ea+'.js';})})[_0x65f6('0x1c')](function(){return _0x4ac04b['status'](0xc8)[_0x65f6('0xf')]({'output':'Database\x20migrated\x20successfully\x20from\x20version\x20'+module[_0x65f6('0xa')][_0x65f6('0x2')]+'\x20to\x20'+_[_0x65f6('0x2d')](_0x11fe3b),'migrations':_[_0x65f6('0x20')](_0x11fe3b)});})[_0x65f6('0x1d')](function(_0x515648){if(_0x515648 instanceof db['sequelize'][_0x65f6('0x2e')]){return _0x4ac04b['status'](0xc8)[_0x65f6('0xf')]({'output':'Database\x20already\x20up-to-date'});}else{return _0x4ac04b[_0x65f6('0xe')](0x1f4)[_0x65f6('0xf')](_0x515648);}});}else{return _0x4ac04b['status'](0xc8)[_0x65f6('0xf')]({'output':'Database\x20already\x20up-to-date'});}};