a44a9d5e023f41006c7477585949581f791294e8
[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 _0x0cc7=['exec','../../config/environment','../../config/logger','update','simple-git','index','exports','query','fetch','tags','latest','2.0.0','status','json','origin','master','error','info','--hard','FETCH_HEAD','pull','npm\x20install\x20--production','restart','motion2','pm2\x20restart\x20motion\x20%s','Your\x20system\x20has\x20been\x20restart\x20successfully','catch','migrations','readdirSync','join','root','server','length','.js','version','push','sort','sequelize','getQueryInterface','constructor','Migration\x20tried\x20to\x20use\x20old\x20style\x20\x22done\x22\x20callback.\x20Please\x20upgrade\x20to\x20\x22umzug\x22\x20and\x20return\x20a\x20promise\x20instead.','map','\x20to\x20','last','UniqueConstraintError','Database\x20already\x20up-to-date','path','pkginfo','child_process'];(function(_0x1abb65,_0x53ee81){var _0x2b65f2=function(_0x40ba6d){while(--_0x40ba6d){_0x1abb65['push'](_0x1abb65['shift']());}};_0x2b65f2(++_0x53ee81);}(_0x0cc7,0x1b6));var _0x70cc=function(_0xbf8ebe,_0x3b69a5){_0xbf8ebe=_0xbf8ebe-0x0;var _0x1e25e8=_0x0cc7[_0xbf8ebe];return _0x1e25e8;};'use strict';var Umzug=require('umzug');var path=require(_0x70cc('0x0'));var fs=require('fs');var _=require('lodash');var pkginfo=require(_0x70cc('0x1'))(module,'version');var compareVersions=require('compare-versions');var exec=require(_0x70cc('0x2'))[_0x70cc('0x3')];var db=require('../../mysqldb')['db'];var config=require(_0x70cc('0x4'));var pm2=require('../../config/pm2');var logger=require(_0x70cc('0x5'))(_0x70cc('0x6'));var git=require(_0x70cc('0x7'))(config['root']);exports[_0x70cc('0x8')]=function(_0x3729fd,_0x417b4d){var _0x1e4fb6={'current':module[_0x70cc('0x9')]['version'],'phonebar':0x2};if(_0x3729fd[_0x70cc('0xa')]&&_0x3729fd[_0x70cc('0xa')]['latest']){return git[_0x70cc('0xb')]()[_0x70cc('0xc')](function(_0x51ce42,_0x3d596a){_0x1e4fb6[_0x70cc('0xd')]=(_0x51ce42?module['exports']['version']:_0x3d596a['latest'])||_0x70cc('0xe');return _0x417b4d[_0x70cc('0xf')](0xc8)[_0x70cc('0x10')](_0x1e4fb6);});}else{return _0x417b4d[_0x70cc('0xf')](0xc8)[_0x70cc('0x10')](_0x1e4fb6);}};exports[_0x70cc('0xb')]=function(_0x578a9f,_0x2cfa8b){return git[_0x70cc('0xb')]([_0x70cc('0x11'),_0x70cc('0x12')],function(_0x3de189){if(_0x3de189){logger[_0x70cc('0x13')](_0x3de189);return _0x2cfa8b[_0x70cc('0xf')](0x1f4)['json'](_0x3de189);}logger[_0x70cc('0x14')]('git\x20fetch');return _0x2cfa8b['status'](0xc8)[_0x70cc('0x10')]({'output':'git\x20fetch\x20origin\x20master'});});};exports['reset']=function(_0x26ffdb,_0x3ab124){return git['reset']([_0x70cc('0x15'),_0x70cc('0x16')],function(_0x194c97){if(_0x194c97){logger[_0x70cc('0x13')](_0x194c97);return _0x3ab124[_0x70cc('0xf')](0x1f4)[_0x70cc('0x10')](_0x194c97);}logger[_0x70cc('0x14')]('git\x20reset\x20--hard\x20FETCH_HEAD');return _0x3ab124[_0x70cc('0xf')](0xc8)[_0x70cc('0x10')]({'output':'git\x20reset\x20--hard'});});};exports[_0x70cc('0x17')]=function(_0x480cab,_0x440bda){exec(_0x70cc('0x18'),function(_0xa07a74,_0x3f0a2a,_0x14c237){logger[_0x70cc('0x14')](_0x3f0a2a);logger['info'](_0x14c237);if(_0xa07a74){logger['error'](_0xa07a74);return _0x440bda['status'](0x1f4)[_0x70cc('0x10')](_0xa07a74);}return _0x440bda['status'](0xc8)[_0x70cc('0x10')]({'output':_0x3f0a2a});});};exports[_0x70cc('0x19')]=function(_0x3eef68,_0x4821cd){return pm2[_0x70cc('0x19')](_0x70cc('0x1a'))['then'](function(_0xf910fb){logger['info'](_0x70cc('0x1b'),_0xf910fb);return _0x4821cd[_0x70cc('0xf')](0xc8)[_0x70cc('0x10')]({'output':_0x70cc('0x1c')});})[_0x70cc('0x1d')](function(_0x5b54fa){logger[_0x70cc('0x13')](_0x5b54fa);return _0x4821cd['status'](0x1f4)['json'](_0x5b54fa);});};exports[_0x70cc('0x1e')]=function(_0x16c526,_0x2d1df3){var _0x3ee850=fs[_0x70cc('0x1f')](path[_0x70cc('0x20')](config[_0x70cc('0x21')],_0x70cc('0x22'),'migrations'));var _0x4b0e13=[];for(var _0x29f510=0x0;_0x29f510<_0x3ee850[_0x70cc('0x23')];_0x29f510++){var _0x59fb0b=_0x3ee850[_0x29f510]['replace'](_0x70cc('0x24'),'');if(compareVersions(module[_0x70cc('0x9')][_0x70cc('0x25')],_0x59fb0b)===-0x1){_0x4b0e13[_0x70cc('0x26')](_0x59fb0b);}}if(_0x4b0e13[_0x70cc('0x23')]){var _0x3085ee=_0x4b0e13[_0x70cc('0x27')](compareVersions);var _0x6f9b14=new Umzug({'storage':_0x70cc('0x28'),'storageOptions':{'model':db['Migration'],'modelName':'Migration','columnName':'version'},'migrations':{'params':[db[_0x70cc('0x28')][_0x70cc('0x29')](),db['sequelize'][_0x70cc('0x2a')],function(){throw new Error(_0x70cc('0x2b'));}],'path':path['join'](config['root'],'server',_0x70cc('0x1e')),'pattern':/\.js$/}});_0x6f9b14['up']({'migrations':_[_0x70cc('0x2c')](_0x3085ee,function(_0x3f788a){return _0x3f788a+'.js';})})['then'](function(){return _0x2d1df3[_0x70cc('0xf')](0xc8)[_0x70cc('0x10')]({'output':'Database\x20migrated\x20successfully\x20from\x20version\x20'+module[_0x70cc('0x9')]['version']+_0x70cc('0x2d')+_[_0x70cc('0x2e')](_0x3085ee),'migrations':_[_0x70cc('0x20')](_0x3085ee)});})[_0x70cc('0x1d')](function(_0xdaf625){if(_0xdaf625 instanceof db[_0x70cc('0x28')][_0x70cc('0x2f')]){return _0x2d1df3[_0x70cc('0xf')](0xc8)['json']({'output':_0x70cc('0x30')});}else{return _0x2d1df3[_0x70cc('0xf')](0x1f4)[_0x70cc('0x10')](_0xdaf625);}});}else{return _0x2d1df3[_0x70cc('0xf')](0xc8)[_0x70cc('0x10')]({'output':_0x70cc('0x30')});}};