e88712e13b4fc4f4cc53861423105f2d4add029c
[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 _0x3ad9=['migrations','readdirSync','root','server','length','replace','.js','sort','Migration','getQueryInterface','sequelize','constructor','Database\x20migrated\x20successfully\x20from\x20version\x20','\x20to\x20','last','UniqueConstraintError','Database\x20already\x20up-to-date','umzug','lodash','version','compare-versions','child_process','exec','../../mysqldb','../../config/pm2','update','index','exports','query','fetch','latest','2.0.0','status','json','origin','info','git\x20fetch','git\x20fetch\x20origin\x20master','reset','--hard','FETCH_HEAD','error','git\x20reset\x20--hard\x20FETCH_HEAD','git\x20reset\x20--hard','pull','restart','motion2','then','Your\x20system\x20has\x20been\x20restart\x20successfully','catch'];(function(_0x1098db,_0x39ba6b){var _0x14f090=function(_0x473ffe){while(--_0x473ffe){_0x1098db['push'](_0x1098db['shift']());}};_0x14f090(++_0x39ba6b);}(_0x3ad9,0xd9));var _0x93ad=function(_0x7ad6cb,_0xffee6c){_0x7ad6cb=_0x7ad6cb-0x0;var _0x22a0ba=_0x3ad9[_0x7ad6cb];return _0x22a0ba;};'use strict';var Umzug=require(_0x93ad('0x0'));var path=require('path');var fs=require('fs');var _=require(_0x93ad('0x1'));var pkginfo=require('pkginfo')(module,_0x93ad('0x2'));var compareVersions=require(_0x93ad('0x3'));var exec=require(_0x93ad('0x4'))[_0x93ad('0x5')];var db=require(_0x93ad('0x6'))['db'];var config=require('../../config/environment');var pm2=require(_0x93ad('0x7'));var logger=require('../../config/logger')(_0x93ad('0x8'));var git=require('simple-git')(config['root']);exports[_0x93ad('0x9')]=function(_0x513b93,_0x29b698){var _0x2a0dcb={'current':module[_0x93ad('0xa')][_0x93ad('0x2')],'phonebar':0x2};if(_0x513b93[_0x93ad('0xb')]&&_0x513b93['query']['latest']){return git[_0x93ad('0xc')]()['tags'](function(_0x1db9d5,_0x80c89d){_0x2a0dcb[_0x93ad('0xd')]=(_0x1db9d5?module[_0x93ad('0xa')][_0x93ad('0x2')]:_0x80c89d[_0x93ad('0xd')])||_0x93ad('0xe');return _0x29b698[_0x93ad('0xf')](0xc8)[_0x93ad('0x10')](_0x2a0dcb);});}else{return _0x29b698['status'](0xc8)[_0x93ad('0x10')](_0x2a0dcb);}};exports['fetch']=function(_0x41f2b0,_0xe9e126){return git[_0x93ad('0xc')]([_0x93ad('0x11'),'master'],function(_0x48d773){if(_0x48d773){logger['error'](_0x48d773);return _0xe9e126[_0x93ad('0xf')](0x1f4)[_0x93ad('0x10')](_0x48d773);}logger[_0x93ad('0x12')](_0x93ad('0x13'));return _0xe9e126[_0x93ad('0xf')](0xc8)[_0x93ad('0x10')]({'output':_0x93ad('0x14')});});};exports['reset']=function(_0x54ec3a,_0x221f0f){return git[_0x93ad('0x15')]([_0x93ad('0x16'),_0x93ad('0x17')],function(_0x537fc5){if(_0x537fc5){logger[_0x93ad('0x18')](_0x537fc5);return _0x221f0f[_0x93ad('0xf')](0x1f4)[_0x93ad('0x10')](_0x537fc5);}logger[_0x93ad('0x12')](_0x93ad('0x19'));return _0x221f0f['status'](0xc8)[_0x93ad('0x10')]({'output':_0x93ad('0x1a')});});};exports[_0x93ad('0x1b')]=function(_0x5c4206,_0x5c4dfa){exec('npm\x20install\x20--production',function(_0x26f116,_0x4071a4,_0x12ca87){logger['info'](_0x4071a4);logger['info'](_0x12ca87);if(_0x26f116){logger[_0x93ad('0x18')](_0x26f116);return _0x5c4dfa[_0x93ad('0xf')](0x1f4)[_0x93ad('0x10')](_0x26f116);}return _0x5c4dfa[_0x93ad('0xf')](0xc8)[_0x93ad('0x10')]({'output':_0x4071a4});});};exports[_0x93ad('0x1c')]=function(_0x4f3cc6,_0x4bffa6){return pm2['restart'](_0x93ad('0x1d'))[_0x93ad('0x1e')](function(_0x135725){logger[_0x93ad('0x12')]('pm2\x20restart\x20motion\x20%s',_0x135725);return _0x4bffa6['status'](0xc8)[_0x93ad('0x10')]({'output':_0x93ad('0x1f')});})[_0x93ad('0x20')](function(_0x4e137f){logger[_0x93ad('0x18')](_0x4e137f);return _0x4bffa6[_0x93ad('0xf')](0x1f4)[_0x93ad('0x10')](_0x4e137f);});};exports[_0x93ad('0x21')]=function(_0xca513a,_0x5c3982){var _0x471b15=fs[_0x93ad('0x22')](path['join'](config[_0x93ad('0x23')],_0x93ad('0x24'),_0x93ad('0x21')));var _0x18d388=[];for(var _0x521cd7=0x0;_0x521cd7<_0x471b15[_0x93ad('0x25')];_0x521cd7++){var _0x1cab5e=_0x471b15[_0x521cd7][_0x93ad('0x26')](_0x93ad('0x27'),'');if(compareVersions(module[_0x93ad('0xa')][_0x93ad('0x2')],_0x1cab5e)===-0x1){_0x18d388['push'](_0x1cab5e);}}if(_0x18d388['length']){var _0x929735=_0x18d388[_0x93ad('0x28')](compareVersions);var _0x216da3=new Umzug({'storage':'sequelize','storageOptions':{'model':db[_0x93ad('0x29')],'modelName':_0x93ad('0x29'),'columnName':_0x93ad('0x2')},'migrations':{'params':[db['sequelize'][_0x93ad('0x2a')](),db[_0x93ad('0x2b')][_0x93ad('0x2c')],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['join'](config[_0x93ad('0x23')],_0x93ad('0x24'),_0x93ad('0x21')),'pattern':/\.js$/}});_0x216da3['up']({'migrations':_['map'](_0x929735,function(_0x4701a7){return _0x4701a7+_0x93ad('0x27');})})[_0x93ad('0x1e')](function(){return _0x5c3982[_0x93ad('0xf')](0xc8)[_0x93ad('0x10')]({'output':_0x93ad('0x2d')+module['exports']['version']+_0x93ad('0x2e')+_[_0x93ad('0x2f')](_0x929735),'migrations':_['join'](_0x929735)});})[_0x93ad('0x20')](function(_0x40eba3){if(_0x40eba3 instanceof db[_0x93ad('0x2b')][_0x93ad('0x30')]){return _0x5c3982[_0x93ad('0xf')](0xc8)[_0x93ad('0x10')]({'output':_0x93ad('0x31')});}else{return _0x5c3982[_0x93ad('0xf')](0x1f4)[_0x93ad('0x10')](_0x40eba3);}});}else{return _0x5c3982[_0x93ad('0xf')](0xc8)['json']({'output':_0x93ad('0x31')});}};