46eda82d623d6adfd02a5fa2591df4e4f56438bf
[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 _0xa83a=['git\x20fetch','git\x20fetch\x20origin\x20master','reset','--hard','FETCH_HEAD','git\x20reset\x20--hard\x20FETCH_HEAD','git\x20reset\x20--hard','pull','npm\x20install\x20--production','restart','then','pm2\x20restart\x20motion\x20%s','Your\x20system\x20has\x20been\x20restart\x20successfully','migrations','readdirSync','server','length','replace','.js','sort','Migration','sequelize','constructor','Migration\x20tried\x20to\x20use\x20old\x20style\x20\x22done\x22\x20callback.\x20Please\x20upgrade\x20to\x20\x22umzug\x22\x20and\x20return\x20a\x20promise\x20instead.','map','Database\x20migrated\x20successfully\x20from\x20version\x20','\x20to\x20','join','catch','Database\x20already\x20up-to-date','path','lodash','version','compare-versions','child_process','exec','../../mysqldb','../../config/pm2','../../config/logger','update','simple-git','root','exports','query','latest','fetch','tags','2.0.0','json','status','master','error','info'];(function(_0x32d776,_0x5499c8){var _0x6b5ee9=function(_0x1ac4cb){while(--_0x1ac4cb){_0x32d776['push'](_0x32d776['shift']());}};_0x6b5ee9(++_0x5499c8);}(_0xa83a,0x88));var _0xaa83=function(_0x330d15,_0x4592f8){_0x330d15=_0x330d15-0x0;var _0x1cdef6=_0xa83a[_0x330d15];return _0x1cdef6;};'use strict';var Umzug=require('umzug');var path=require(_0xaa83('0x0'));var fs=require('fs');var _=require(_0xaa83('0x1'));var pkginfo=require('pkginfo')(module,_0xaa83('0x2'));var compareVersions=require(_0xaa83('0x3'));var exec=require(_0xaa83('0x4'))[_0xaa83('0x5')];var db=require(_0xaa83('0x6'))['db'];var config=require('../../config/environment');var pm2=require(_0xaa83('0x7'));var logger=require(_0xaa83('0x8'))(_0xaa83('0x9'));var git=require(_0xaa83('0xa'))(config[_0xaa83('0xb')]);exports['index']=function(_0x5d5a47,_0x582edf){var _0x32e39d={'current':module[_0xaa83('0xc')][_0xaa83('0x2')],'phonebar':0x2};if(_0x5d5a47[_0xaa83('0xd')]&&_0x5d5a47[_0xaa83('0xd')][_0xaa83('0xe')]){return git[_0xaa83('0xf')]()[_0xaa83('0x10')](function(_0x4a6325,_0x3ea390){_0x32e39d[_0xaa83('0xe')]=(_0x4a6325?module['exports'][_0xaa83('0x2')]:_0x3ea390['latest'])||_0xaa83('0x11');return _0x582edf['status'](0xc8)[_0xaa83('0x12')](_0x32e39d);});}else{return _0x582edf[_0xaa83('0x13')](0xc8)[_0xaa83('0x12')](_0x32e39d);}};exports['fetch']=function(_0x432182,_0x178b4d){return git[_0xaa83('0xf')](['origin',_0xaa83('0x14')],function(_0x44695c){if(_0x44695c){logger[_0xaa83('0x15')](_0x44695c);return _0x178b4d[_0xaa83('0x13')](0x1f4)[_0xaa83('0x12')](_0x44695c);}logger[_0xaa83('0x16')](_0xaa83('0x17'));return _0x178b4d[_0xaa83('0x13')](0xc8)[_0xaa83('0x12')]({'output':_0xaa83('0x18')});});};exports[_0xaa83('0x19')]=function(_0x1702c3,_0x593277){return git['reset']([_0xaa83('0x1a'),_0xaa83('0x1b')],function(_0x300d87){if(_0x300d87){logger[_0xaa83('0x15')](_0x300d87);return _0x593277[_0xaa83('0x13')](0x1f4)['json'](_0x300d87);}logger[_0xaa83('0x16')](_0xaa83('0x1c'));return _0x593277['status'](0xc8)['json']({'output':_0xaa83('0x1d')});});};exports[_0xaa83('0x1e')]=function(_0x1ed5a7,_0x5a69aa){exec(_0xaa83('0x1f'),function(_0x35d82e,_0x43a842,_0x3acc81){logger[_0xaa83('0x16')](_0x43a842);logger[_0xaa83('0x16')](_0x3acc81);if(_0x35d82e){logger[_0xaa83('0x15')](_0x35d82e);return _0x5a69aa[_0xaa83('0x13')](0x1f4)[_0xaa83('0x12')](_0x35d82e);}return _0x5a69aa[_0xaa83('0x13')](0xc8)[_0xaa83('0x12')]({'output':_0x43a842});});};exports[_0xaa83('0x20')]=function(_0x53d4a9,_0x300c87){return pm2[_0xaa83('0x20')]('motion2')[_0xaa83('0x21')](function(_0x316dc3){logger[_0xaa83('0x16')](_0xaa83('0x22'),_0x316dc3);return _0x300c87[_0xaa83('0x13')](0xc8)['json']({'output':_0xaa83('0x23')});})['catch'](function(_0x103ee3){logger[_0xaa83('0x15')](_0x103ee3);return _0x300c87['status'](0x1f4)[_0xaa83('0x12')](_0x103ee3);});};exports[_0xaa83('0x24')]=function(_0x519457,_0x9f6506){var _0x259d01=fs[_0xaa83('0x25')](path['join'](config[_0xaa83('0xb')],_0xaa83('0x26'),_0xaa83('0x24')));var _0x4190e7=[];for(var _0x50684c=0x0;_0x50684c<_0x259d01[_0xaa83('0x27')];_0x50684c++){var _0x4916eb=_0x259d01[_0x50684c][_0xaa83('0x28')](_0xaa83('0x29'),'');if(compareVersions(module['exports']['version'],_0x4916eb)===-0x1){_0x4190e7['push'](_0x4916eb);}}if(_0x4190e7[_0xaa83('0x27')]){var _0x18df85=_0x4190e7[_0xaa83('0x2a')](compareVersions);var _0x197bbd=new Umzug({'storage':'sequelize','storageOptions':{'model':db[_0xaa83('0x2b')],'modelName':'Migration','columnName':_0xaa83('0x2')},'migrations':{'params':[db[_0xaa83('0x2c')]['getQueryInterface'](),db[_0xaa83('0x2c')][_0xaa83('0x2d')],function(){throw new Error(_0xaa83('0x2e'));}],'path':path['join'](config[_0xaa83('0xb')],'server','migrations'),'pattern':/\.js$/}});_0x197bbd['up']({'migrations':_[_0xaa83('0x2f')](_0x18df85,function(_0x1cb7b7){return _0x1cb7b7+'.js';})})[_0xaa83('0x21')](function(){return _0x9f6506[_0xaa83('0x13')](0xc8)[_0xaa83('0x12')]({'output':_0xaa83('0x30')+module[_0xaa83('0xc')]['version']+_0xaa83('0x31')+_['last'](_0x18df85),'migrations':_[_0xaa83('0x32')](_0x18df85)});})[_0xaa83('0x33')](function(_0x442362){if(_0x442362 instanceof db[_0xaa83('0x2c')]['UniqueConstraintError']){return _0x9f6506[_0xaa83('0x13')](0xc8)[_0xaa83('0x12')]({'output':_0xaa83('0x34')});}else{return _0x9f6506['status'](0x1f4)[_0xaa83('0x12')](_0x442362);}});}else{return _0x9f6506[_0xaa83('0x13')](0xc8)[_0xaa83('0x12')]({'output':_0xaa83('0x34')});}};