<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\AdminManager\Admin\Controller; use App\Constant\AppConstant; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\Artisan; use ModStart\Admin\Auth\AdminPermission; use ModStart\Core\Exception\BizException; use ModStart\Core\Input\InputPackage; use ModStart\Core\Input\Request; use ModStart\Core\Input\Response; use ModStart\Core\Util\FileUtil; use Module\AdminManager\Util\ModuleUtil; use Module\AdminManager\Util\UpgradeUtil; class UpgradeController extends Controller { public static $PermitMethodMap = array('index' => '@SystemUpgrade', 'info' => '@SystemUpgrade', 'auth' => '@SystemUpgrade'); private function doFinish($BdPDx, $G2Zzj = null) { return Response::generateSuccessData(array('msg' => array_map(function ($YaV4m) { return '<i class="iconfont icon-hr"></i> ' . $YaV4m; }, $BdPDx), 'logs' => $G2Zzj, 'finish' => true)); } private function doNext($jtb0o, $BdPDx = array(), $avcnU = array()) { goto z8odN; U4dSX: $avcnU = array_merge($Km8YS->getJsonAsInput('data')->all(), $avcnU); goto jilGv; jilGv: return Response::generateSuccessData(array('msg' => array_map(function ($YaV4m) { if (!starts_with($YaV4m, '<')) { $YaV4m = "<span class='ub-text-white'>{$YaV4m}</span>"; } return '<i class="iconfont icon-hr"></i> ' . $YaV4m; }, $BdPDx), 'step' => $jtb0o, 'data' => $avcnU, 'finish' => false)); goto QpTEc; z8odN: $Km8YS = InputPackage::buildFromInput(); goto U4dSX; QpTEc: } public function index() { goto QiD7E; Bv2jo: return view('module::AdminManager.View.admin.upgrade'); goto CPYro; cHPvX: if (Request::isPost()) { goto Dz4Hw; FMFWl: $vodoI = $WcQIz->getTrimString('toVersion'); goto g1nL6; snG2Y: $jtb0o = $Km8YS->getTrimString('step'); goto tfHCY; g1nL6: BizException::throwsIfEmpty('toVersion为空', $vodoI); goto HYGPu; RU8g_: $WcQIz = $Km8YS->getJsonAsInput('data'); goto FMFWl; phirH: $Km8YS = InputPackage::buildFromInput(); goto snG2Y; tfHCY: $MMmFM = $Km8YS->getTrimString('token'); goto RU8g_; Dz4Hw: AdminPermission::demoCheck(); goto phirH; HYGPu: switch ($jtb0o) { case 'upgradePackage': goto xwKYj; xwKYj: $pd0Ai = $WcQIz->getTrimString('package'); goto ji2s0; ZlySc: BizException::throwsIfResponseError($rhLXE); goto KSRTk; KSRTk: return $this->doFinish(array('<span class="ub-text-success">升级完成，请 <a href="javascript:;" onclick="window.location.reload()">刷新后台</a> 查看最新系统</span>'), $rhLXE['data']['logs']); goto jQC7s; ji2s0: $kO40W = $WcQIz->getTrimString('diffContentFile'); goto kN533; P8TVx: BizException::throwsIfEmpty('diffContentFile为空', $kO40W); goto cl7Q0; cl7Q0: $rhLXE = UpgradeUtil::upgradePackage($pd0Ai, $kO40W); goto ZlySc; kN533: BizException::throwsIfEmpty('package为空', $pd0Ai); goto P8TVx; jQC7s: case 'downloadPackage': goto sylhQ; bE8nc: return $this->doNext('upgradePackage', array('<span class="ub-text-success">获取安装包完成，大小 ' . FileUtil::formatByte($rhLXE['data']['packageSize']) . '</span>', '<span class="ub-text-white">开始解压升级装包...</span>'), array('package' => $rhLXE['data']['package'], 'diffContentFile' => $rhLXE['data']['diffContentFile'])); goto MNDpC; Wj1we: BizException::throwsIfResponseError($rhLXE); goto bE8nc; sylhQ: $rhLXE = UpgradeUtil::downloadPackage($MMmFM, AppConstant::APP, AppConstant::VERSION, $vodoI); goto Wj1we; MNDpC: case 'checkPackage': goto fmGki; fmGki: try { $Jk1lG = Artisan::call('migrate'); } catch (\Exception $qoTNG) { $Jk1lG = -1; } goto huoyV; SJ_um: return $this->doNext('downloadPackage', array('PHP版本: v' . PHP_VERSION, '<span class="ub-text-success">预检通过</span>', '<span class="ub-text-white">开始下载升级包...</span>')); goto B3Kp3; huoyV: BizException::throwsIf('调用 php artisan 命令失败，不能自动升级', 0 != $Jk1lG); goto SJ_um; B3Kp3: default: return $this->doNext('checkPackage', array('<span class="ub-text-success">开始升级系统，从 V' . AppConstant::VERSION . ' 到 V' . $vodoI . '</span>', '<span class="ub-text-white">开始预检系统...</span>')); } goto Gp2ER; Gp2ER: } goto Bv2jo; QiD7E: if (config('modstart.admin.upgradeDisable', false)) { return Response::sendError('系统升级功能已关闭'); } goto cHPvX; CPYro: } public function auth() { return view('module::AdminManager.View.admin.auth', array('modules' => ModuleUtil::modules())); } public function info() { $F01p4 = UpgradeUtil::latest(); return Response::generateSuccessData(array('version' => AppConstant::VERSION, 'latestVersion' => $F01p4['latestVersion'], 'autoUpgrade' => $F01p4['autoUpgrade'])); } }