355e9c3dd0b26b585ea4f3f3f88c07599076bcbd
[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 _0x84f8=['child_process','exec','../../mysqldb','../../config/pm2','update','simple-git','root','index','exports','query','latest','fetch','tags','status','origin','error','info','git\x20fetch','git\x20fetch\x20origin\x20master','reset','--hard','FETCH_HEAD','json','git\x20reset\x20--hard\x20FETCH_HEAD','git\x20reset\x20--hard','pull','restart','motion2','then','pm2\x20restart\x20motion\x20%s','Your\x20system\x20has\x20been\x20restart\x20successfully','catch','migrations','join','server','length','.js','push','sort','sequelize','Migration','getQueryInterface','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','UniqueConstraintError','Database\x20already\x20up-to-date','umzug','path','lodash','version','compare-versions'];(function(_0x20a584,_0xe384a5){var _0x4b41a8=function(_0x2127c6){while(--_0x2127c6){_0x20a584['push'](_0x20a584['shift']());}};_0x4b41a8(++_0xe384a5);}(_0x84f8,0xcf));var _0x884f=function(_0x5ec206,_0x554d38){_0x5ec206=_0x5ec206-0x0;var _0x366f25=_0x84f8[_0x5ec206];return _0x366f25;};'use strict';var Umzug=require(_0x884f('0x0'));var path=require(_0x884f('0x1'));var fs=require('fs');var _=require(_0x884f('0x2'));var pkginfo=require('pkginfo')(module,_0x884f('0x3'));var compareVersions=require(_0x884f('0x4'));var exec=require(_0x884f('0x5'))[_0x884f('0x6')];var db=require(_0x884f('0x7'))['db'];var config=require('../../config/environment');var pm2=require(_0x884f('0x8'));var logger=require('../../config/logger')(_0x884f('0x9'));var git=require(_0x884f('0xa'))(config[_0x884f('0xb')]);exports[_0x884f('0xc')]=function(_0x3d31cb,_0x28dd5c){var _0x4a6521={'current':module[_0x884f('0xd')][_0x884f('0x3')],'phonebar':0x2};if(_0x3d31cb[_0x884f('0xe')]&&_0x3d31cb[_0x884f('0xe')][_0x884f('0xf')]){return git[_0x884f('0x10')]()[_0x884f('0x11')](function(_0xd44f9f,_0x3f4897){_0x4a6521[_0x884f('0xf')]=(_0xd44f9f?module[_0x884f('0xd')]['version']:_0x3f4897[_0x884f('0xf')])||'2.0.0';return _0x28dd5c[_0x884f('0x12')](0xc8)['json'](_0x4a6521);});}else{return _0x28dd5c[_0x884f('0x12')](0xc8)['json'](_0x4a6521);}};exports[_0x884f('0x10')]=function(_0x154d58,_0xae3d5a){return git[_0x884f('0x10')]([_0x884f('0x13'),'master'],function(_0x34de86){if(_0x34de86){logger[_0x884f('0x14')](_0x34de86);return _0xae3d5a[_0x884f('0x12')](0x1f4)['json'](_0x34de86);}logger[_0x884f('0x15')](_0x884f('0x16'));return _0xae3d5a[_0x884f('0x12')](0xc8)['json']({'output':_0x884f('0x17')});});};exports['reset']=function(_0x2b3a77,_0x22b14a){return git[_0x884f('0x18')]([_0x884f('0x19'),_0x884f('0x1a')],function(_0x438e6c){if(_0x438e6c){logger[_0x884f('0x14')](_0x438e6c);return _0x22b14a[_0x884f('0x12')](0x1f4)[_0x884f('0x1b')](_0x438e6c);}logger[_0x884f('0x15')](_0x884f('0x1c'));return _0x22b14a['status'](0xc8)[_0x884f('0x1b')]({'output':_0x884f('0x1d')});});};exports[_0x884f('0x1e')]=function(_0x4b4088,_0x14a16a){exec('npm\x20install\x20--production',function(_0x249465,_0x4312a0,_0x41ebc0){logger[_0x884f('0x15')](_0x4312a0);logger[_0x884f('0x15')](_0x41ebc0);if(_0x249465){logger[_0x884f('0x14')](_0x249465);return _0x14a16a[_0x884f('0x12')](0x1f4)[_0x884f('0x1b')](_0x249465);}return _0x14a16a['status'](0xc8)[_0x884f('0x1b')]({'output':_0x4312a0});});};exports[_0x884f('0x1f')]=function(_0x8e1318,_0x209d01){return pm2[_0x884f('0x1f')](_0x884f('0x20'))[_0x884f('0x21')](function(_0x5bf54c){logger['info'](_0x884f('0x22'),_0x5bf54c);return _0x209d01[_0x884f('0x12')](0xc8)[_0x884f('0x1b')]({'output':_0x884f('0x23')});})[_0x884f('0x24')](function(_0x24bc35){logger['error'](_0x24bc35);return _0x209d01['status'](0x1f4)[_0x884f('0x1b')](_0x24bc35);});};exports[_0x884f('0x25')]=function(_0x3ee7bc,_0x15cb87){var _0x9aaa95=fs['readdirSync'](path[_0x884f('0x26')](config[_0x884f('0xb')],_0x884f('0x27'),_0x884f('0x25')));var _0x6f1860=[];for(var _0x390f34=0x0;_0x390f34<_0x9aaa95[_0x884f('0x28')];_0x390f34++){var _0x1727f3=_0x9aaa95[_0x390f34]['replace'](_0x884f('0x29'),'');if(compareVersions(module[_0x884f('0xd')][_0x884f('0x3')],_0x1727f3)===-0x1){_0x6f1860[_0x884f('0x2a')](_0x1727f3);}}if(_0x6f1860[_0x884f('0x28')]){var _0x3de848=_0x6f1860[_0x884f('0x2b')](compareVersions);var _0x25dbf0=new Umzug({'storage':_0x884f('0x2c'),'storageOptions':{'model':db[_0x884f('0x2d')],'modelName':_0x884f('0x2d'),'columnName':_0x884f('0x3')},'migrations':{'params':[db['sequelize'][_0x884f('0x2e')](),db[_0x884f('0x2c')][_0x884f('0x2f')],function(){throw new Error(_0x884f('0x30'));}],'path':path[_0x884f('0x26')](config[_0x884f('0xb')],'server',_0x884f('0x25')),'pattern':/\.js$/}});_0x25dbf0['up']({'migrations':_[_0x884f('0x31')](_0x3de848,function(_0x222e2d){return _0x222e2d+'.js';})})[_0x884f('0x21')](function(){return _0x15cb87[_0x884f('0x12')](0xc8)['json']({'output':_0x884f('0x32')+module['exports'][_0x884f('0x3')]+'\x20to\x20'+_['last'](_0x3de848),'migrations':_[_0x884f('0x26')](_0x3de848)});})[_0x884f('0x24')](function(_0x51cb52){if(_0x51cb52 instanceof db[_0x884f('0x2c')][_0x884f('0x33')]){return _0x15cb87[_0x884f('0x12')](0xc8)[_0x884f('0x1b')]({'output':_0x884f('0x34')});}else{return _0x15cb87[_0x884f('0x12')](0x1f4)[_0x884f('0x1b')](_0x51cb52);}});}else{return _0x15cb87[_0x884f('0x12')](0xc8)['json']({'output':_0x884f('0x34')});}};