Built motion from commit 42801a18.|2.6.28
[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 _0x4b78=['last','catch','UniqueConstraintError','Database\x20already\x20up-to-date','path','pkginfo','version','compare-versions','child_process','exec','../../mysqldb','../../config/environment','../../config/pm2','../../config/logger','update','simple-git','root','exports','query','latest','fetch','tags','status','json','origin','master','error','git\x20fetch','git\x20fetch\x20origin\x20master','reset','FETCH_HEAD','info','git\x20reset\x20--hard\x20FETCH_HEAD','git\x20reset\x20--hard','restart','motion2','then','pm2\x20restart\x20motion\x20%s','Your\x20system\x20has\x20been\x20restart\x20successfully','migrations','readdirSync','join','replace','.js','push','length','sort','Migration','sequelize','getQueryInterface','Migration\x20tried\x20to\x20use\x20old\x20style\x20\x22done\x22\x20callback.\x20Please\x20upgrade\x20to\x20\x22umzug\x22\x20and\x20return\x20a\x20promise\x20instead.','server','\x20to\x20'];(function(_0x51878f,_0x1c88c6){var _0x311bc2=function(_0x31ed2b){while(--_0x31ed2b){_0x51878f['push'](_0x51878f['shift']());}};_0x311bc2(++_0x1c88c6);}(_0x4b78,0x1ac));var _0x84b7=function(_0x44ead3,_0x1b7866){_0x44ead3=_0x44ead3-0x0;var _0x1110c9=_0x4b78[_0x44ead3];return _0x1110c9;};'use strict';var Umzug=require('umzug');var path=require(_0x84b7('0x0'));var fs=require('fs');var _=require('lodash');var pkginfo=require(_0x84b7('0x1'))(module,_0x84b7('0x2'));var compareVersions=require(_0x84b7('0x3'));var exec=require(_0x84b7('0x4'))[_0x84b7('0x5')];var db=require(_0x84b7('0x6'))['db'];var config=require(_0x84b7('0x7'));var pm2=require(_0x84b7('0x8'));var logger=require(_0x84b7('0x9'))(_0x84b7('0xa'));var git=require(_0x84b7('0xb'))(config[_0x84b7('0xc')]);exports['index']=function(_0x12f080,_0x516376){var _0x289a67={'current':module[_0x84b7('0xd')][_0x84b7('0x2')],'phonebar':0x2};if(_0x12f080[_0x84b7('0xe')]&&_0x12f080['query'][_0x84b7('0xf')]){return git[_0x84b7('0x10')]()[_0x84b7('0x11')](function(_0x57b627,_0x17c536){_0x289a67[_0x84b7('0xf')]=(_0x57b627?module[_0x84b7('0xd')][_0x84b7('0x2')]:_0x17c536[_0x84b7('0xf')])||'2.0.0';return _0x516376[_0x84b7('0x12')](0xc8)[_0x84b7('0x13')](_0x289a67);});}else{return _0x516376[_0x84b7('0x12')](0xc8)[_0x84b7('0x13')](_0x289a67);}};exports[_0x84b7('0x10')]=function(_0x569edb,_0x5eb55b){return git['fetch']([_0x84b7('0x14'),_0x84b7('0x15')],function(_0x33b7ed){if(_0x33b7ed){logger[_0x84b7('0x16')](_0x33b7ed);return _0x5eb55b[_0x84b7('0x12')](0x1f4)[_0x84b7('0x13')](_0x33b7ed);}logger['info'](_0x84b7('0x17'));return _0x5eb55b[_0x84b7('0x12')](0xc8)[_0x84b7('0x13')]({'output':_0x84b7('0x18')});});};exports['reset']=function(_0x2f407b,_0x255e18){return git[_0x84b7('0x19')](['--hard',_0x84b7('0x1a')],function(_0x169283){if(_0x169283){logger[_0x84b7('0x16')](_0x169283);return _0x255e18[_0x84b7('0x12')](0x1f4)[_0x84b7('0x13')](_0x169283);}logger[_0x84b7('0x1b')](_0x84b7('0x1c'));return _0x255e18[_0x84b7('0x12')](0xc8)[_0x84b7('0x13')]({'output':_0x84b7('0x1d')});});};exports['pull']=function(_0x48b89d,_0x36d128){exec('npm\x20install\x20--production',function(_0x47803b,_0x7e358a,_0x27bfbe){logger[_0x84b7('0x1b')](_0x7e358a);logger[_0x84b7('0x1b')](_0x27bfbe);if(_0x47803b){logger[_0x84b7('0x16')](_0x47803b);return _0x36d128[_0x84b7('0x12')](0x1f4)[_0x84b7('0x13')](_0x47803b);}return _0x36d128[_0x84b7('0x12')](0xc8)['json']({'output':_0x7e358a});});};exports[_0x84b7('0x1e')]=function(_0x2bb188,_0x1c0240){return pm2[_0x84b7('0x1e')](_0x84b7('0x1f'))[_0x84b7('0x20')](function(_0x4b0e11){logger['info'](_0x84b7('0x21'),_0x4b0e11);return _0x1c0240[_0x84b7('0x12')](0xc8)['json']({'output':_0x84b7('0x22')});})['catch'](function(_0x4b11bd){logger[_0x84b7('0x16')](_0x4b11bd);return _0x1c0240[_0x84b7('0x12')](0x1f4)[_0x84b7('0x13')](_0x4b11bd);});};exports[_0x84b7('0x23')]=function(_0x50521c,_0x28e93c){var _0x3469e7=fs[_0x84b7('0x24')](path[_0x84b7('0x25')](config['root'],'server',_0x84b7('0x23')));var _0x105a83=[];for(var _0x15f9ec=0x0;_0x15f9ec<_0x3469e7['length'];_0x15f9ec++){var _0x584729=_0x3469e7[_0x15f9ec][_0x84b7('0x26')](_0x84b7('0x27'),'');if(compareVersions(module[_0x84b7('0xd')][_0x84b7('0x2')],_0x584729)===-0x1){_0x105a83[_0x84b7('0x28')](_0x584729);}}if(_0x105a83[_0x84b7('0x29')]){var _0x1fa51d=_0x105a83[_0x84b7('0x2a')](compareVersions);var _0x425d80=new Umzug({'storage':'sequelize','storageOptions':{'model':db[_0x84b7('0x2b')],'modelName':_0x84b7('0x2b'),'columnName':_0x84b7('0x2')},'migrations':{'params':[db[_0x84b7('0x2c')][_0x84b7('0x2d')](),db['sequelize']['constructor'],function(){throw new Error(_0x84b7('0x2e'));}],'path':path[_0x84b7('0x25')](config[_0x84b7('0xc')],_0x84b7('0x2f'),_0x84b7('0x23')),'pattern':/\.js$/}});_0x425d80['up']({'migrations':_['map'](_0x1fa51d,function(_0x1114fd){return _0x1114fd+_0x84b7('0x27');})})['then'](function(){return _0x28e93c[_0x84b7('0x12')](0xc8)[_0x84b7('0x13')]({'output':'Database\x20migrated\x20successfully\x20from\x20version\x20'+module[_0x84b7('0xd')][_0x84b7('0x2')]+_0x84b7('0x30')+_[_0x84b7('0x31')](_0x1fa51d),'migrations':_[_0x84b7('0x25')](_0x1fa51d)});})[_0x84b7('0x32')](function(_0x4bdb25){if(_0x4bdb25 instanceof db[_0x84b7('0x2c')][_0x84b7('0x33')]){return _0x28e93c[_0x84b7('0x12')](0xc8)[_0x84b7('0x13')]({'output':_0x84b7('0x34')});}else{return _0x28e93c['status'](0x1f4)['json'](_0x4bdb25);}});}else{return _0x28e93c[_0x84b7('0x12')](0xc8)[_0x84b7('0x13')]({'output':_0x84b7('0x34')});}};