14aeca170ca2cd193112b28a33353229b90cd533
[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 _0x8ffa=['catch','join','migrations','length','.js','sequelize','Migration','getQueryInterface','constructor','server','map','Database\x20migrated\x20successfully\x20from\x20version\x20','\x20to\x20','last','UniqueConstraintError','Database\x20already\x20up-to-date','lodash','version','compare-versions','child_process','exec','../../mysqldb','../../config/environment','../../config/pm2','../../config/logger','simple-git','root','index','exports','query','latest','fetch','tags','2.0.0','json','status','origin','error','info','reset','--hard','git\x20reset\x20--hard','pull','restart','motion2','then','pm2\x20restart\x20motion\x20%s','Your\x20system\x20has\x20been\x20restart\x20successfully'];(function(_0x308944,_0x1c462e){var _0x2bf805=function(_0x1e6564){while(--_0x1e6564){_0x308944['push'](_0x308944['shift']());}};_0x2bf805(++_0x1c462e);}(_0x8ffa,0xa0));var _0xa8ff=function(_0x4119aa,_0x56fd46){_0x4119aa=_0x4119aa-0x0;var _0x2816c5=_0x8ffa[_0x4119aa];return _0x2816c5;};'use strict';var Umzug=require('umzug');var path=require('path');var fs=require('fs');var _=require(_0xa8ff('0x0'));var pkginfo=require('pkginfo')(module,_0xa8ff('0x1'));var compareVersions=require(_0xa8ff('0x2'));var exec=require(_0xa8ff('0x3'))[_0xa8ff('0x4')];var db=require(_0xa8ff('0x5'))['db'];var config=require(_0xa8ff('0x6'));var pm2=require(_0xa8ff('0x7'));var logger=require(_0xa8ff('0x8'))('update');var git=require(_0xa8ff('0x9'))(config[_0xa8ff('0xa')]);exports[_0xa8ff('0xb')]=function(_0x3c71af,_0x438779){var _0x3d9514={'current':module[_0xa8ff('0xc')][_0xa8ff('0x1')],'phonebar':0x2};if(_0x3c71af[_0xa8ff('0xd')]&&_0x3c71af[_0xa8ff('0xd')][_0xa8ff('0xe')]){return git[_0xa8ff('0xf')]()[_0xa8ff('0x10')](function(_0x5f3372,_0x356ac9){_0x3d9514[_0xa8ff('0xe')]=(_0x5f3372?module['exports'][_0xa8ff('0x1')]:_0x356ac9[_0xa8ff('0xe')])||_0xa8ff('0x11');return _0x438779['status'](0xc8)[_0xa8ff('0x12')](_0x3d9514);});}else{return _0x438779[_0xa8ff('0x13')](0xc8)[_0xa8ff('0x12')](_0x3d9514);}};exports['fetch']=function(_0x13ff2e,_0x2baeee){return git[_0xa8ff('0xf')]([_0xa8ff('0x14'),'master'],function(_0x27c339){if(_0x27c339){logger[_0xa8ff('0x15')](_0x27c339);return _0x2baeee[_0xa8ff('0x13')](0x1f4)[_0xa8ff('0x12')](_0x27c339);}logger[_0xa8ff('0x16')]('git\x20fetch');return _0x2baeee[_0xa8ff('0x13')](0xc8)[_0xa8ff('0x12')]({'output':'git\x20fetch\x20origin\x20master'});});};exports['reset']=function(_0x1db2e4,_0x3c60ad){return git[_0xa8ff('0x17')]([_0xa8ff('0x18'),'FETCH_HEAD'],function(_0x2bb31f){if(_0x2bb31f){logger[_0xa8ff('0x15')](_0x2bb31f);return _0x3c60ad['status'](0x1f4)['json'](_0x2bb31f);}logger[_0xa8ff('0x16')]('git\x20reset\x20--hard\x20FETCH_HEAD');return _0x3c60ad[_0xa8ff('0x13')](0xc8)['json']({'output':_0xa8ff('0x19')});});};exports[_0xa8ff('0x1a')]=function(_0x294068,_0x444aee){exec('npm\x20install\x20--production',function(_0xbe0fae,_0x164324,_0x3d53dd){logger[_0xa8ff('0x16')](_0x164324);logger['info'](_0x3d53dd);if(_0xbe0fae){logger[_0xa8ff('0x15')](_0xbe0fae);return _0x444aee[_0xa8ff('0x13')](0x1f4)[_0xa8ff('0x12')](_0xbe0fae);}return _0x444aee[_0xa8ff('0x13')](0xc8)[_0xa8ff('0x12')]({'output':_0x164324});});};exports['restart']=function(_0x5178bb,_0x1ce91e){return pm2[_0xa8ff('0x1b')](_0xa8ff('0x1c'))[_0xa8ff('0x1d')](function(_0x187518){logger['info'](_0xa8ff('0x1e'),_0x187518);return _0x1ce91e[_0xa8ff('0x13')](0xc8)[_0xa8ff('0x12')]({'output':_0xa8ff('0x1f')});})[_0xa8ff('0x20')](function(_0x43da2b){logger[_0xa8ff('0x15')](_0x43da2b);return _0x1ce91e['status'](0x1f4)[_0xa8ff('0x12')](_0x43da2b);});};exports['migrations']=function(_0x3e5a53,_0x3ad78f){var _0x5bf03e=fs['readdirSync'](path[_0xa8ff('0x21')](config['root'],'server',_0xa8ff('0x22')));var _0x7c29f2=[];for(var _0x1d5f6a=0x0;_0x1d5f6a<_0x5bf03e[_0xa8ff('0x23')];_0x1d5f6a++){var _0x5db3b1=_0x5bf03e[_0x1d5f6a]['replace'](_0xa8ff('0x24'),'');if(compareVersions(module[_0xa8ff('0xc')][_0xa8ff('0x1')],_0x5db3b1)===-0x1){_0x7c29f2['push'](_0x5db3b1);}}if(_0x7c29f2[_0xa8ff('0x23')]){var _0x5c8642=_0x7c29f2['sort'](compareVersions);var _0x594ce7=new Umzug({'storage':_0xa8ff('0x25'),'storageOptions':{'model':db['Migration'],'modelName':_0xa8ff('0x26'),'columnName':'version'},'migrations':{'params':[db[_0xa8ff('0x25')][_0xa8ff('0x27')](),db[_0xa8ff('0x25')][_0xa8ff('0x28')],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[_0xa8ff('0x21')](config[_0xa8ff('0xa')],_0xa8ff('0x29'),_0xa8ff('0x22')),'pattern':/\.js$/}});_0x594ce7['up']({'migrations':_[_0xa8ff('0x2a')](_0x5c8642,function(_0x160b92){return _0x160b92+'.js';})})['then'](function(){return _0x3ad78f[_0xa8ff('0x13')](0xc8)[_0xa8ff('0x12')]({'output':_0xa8ff('0x2b')+module[_0xa8ff('0xc')][_0xa8ff('0x1')]+_0xa8ff('0x2c')+_[_0xa8ff('0x2d')](_0x5c8642),'migrations':_[_0xa8ff('0x21')](_0x5c8642)});})[_0xa8ff('0x20')](function(_0x1809bf){if(_0x1809bf instanceof db['sequelize'][_0xa8ff('0x2e')]){return _0x3ad78f['status'](0xc8)[_0xa8ff('0x12')]({'output':_0xa8ff('0x2f')});}else{return _0x3ad78f[_0xa8ff('0x13')](0x1f4)[_0xa8ff('0x12')](_0x1809bf);}});}else{return _0x3ad78f[_0xa8ff('0x13')](0xc8)[_0xa8ff('0x12')]({'output':'Database\x20already\x20up-to-date'});}};