<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\AdminManager\Util; use App\Constant\AppConstant; use Chumper\Zipper\Zipper; use Illuminate\Support\Facades\Artisan; use ModStart\Core\Exception\BizException; use ModStart\Core\Input\Response; use ModStart\Core\Util\CurlUtil; use ModStart\Core\Util\FileUtil; use ModStart\ModStart; class UpgradeUtil { const REMOTE_BASE = 'https://modstart.com'; private static function baseRequest($EKog2, $xJzrK = array(), $GA_R3 = null) { return CurlUtil::postJSONBody(self::REMOTE_BASE . $EKog2, $xJzrK, array('header' => array('api-token' => $GA_R3, 'X-Requested-With' => 'XMLHttpRequest'))); } public static function latest() { goto E_s5a; E_s5a: $yCUD1 = self::baseRequest('/api/app/latest', array('app' => AppConstant::APP, 'version' => AppConstant::VERSION)); goto qBRhg; dIZ83: return $yCUD1['data']; goto e8zE5; qBRhg: BizException::throwsIfResponseError($yCUD1); goto dIZ83; e8zE5: } public static function downloadPackage($GA_R3, $NMaTV, $g_V3S, $Wgcnm) { goto NBoLc; DSrvK: return Response::generateSuccessData(array('diffContentFile' => $TiNKC, 'package' => $mQcOS, 'packageSize' => filesize($mQcOS))); goto gLkok; lMWPu: BizException::throwsIf('文件MD5校验失败', md5_file($mQcOS) != $Yn3XW); goto ZA4U6; Ww2N4: $mQcOS = FileUtil::generateLocalTempPath('zip'); goto Y05Yo; LpQwr: $xJzrK = CurlUtil::getRaw($HDfwB); goto bfkcy; WpyIU: $HDfwB = $yCUD1['data']['package']; goto uLqfW; NBoLc: $yCUD1 = self::baseRequest('/api/app/download_package', array('app' => $NMaTV, 'fromVersion' => $g_V3S, 'toVersion' => $Wgcnm), $GA_R3); goto BoIo1; bfkcy: BizException::throwsIfEmpty('安装包获取失败', $xJzrK); goto Ww2N4; BoIo1: BizException::throwsIfResponseError($yCUD1); goto WpyIU; ZA4U6: $TiNKC = FileUtil::generateLocalTempPath('json'); goto wU7yl; uLqfW: $Yn3XW = $yCUD1['data']['packageMd5']; goto VSO02; Y05Yo: file_put_contents($mQcOS, $xJzrK); goto lMWPu; wU7yl: file_put_contents($TiNKC, $vddDn); goto DSrvK; VSO02: $vddDn = $yCUD1['data']['diffContent']; goto LpQwr; gLkok: } public static function upgradePackage($HDfwB, $TiNKC) { goto otgLu; VPbQ3: $ac7RJ->close(); goto TbUP8; LcCC4: if (!empty($vddDn['delete'])) { goto GGXFO; S7PUC: foreach ($vddDn['delete'] as $rZJie) { if (file_exists($v1O63 = base_path($rZJie))) { @unlink($v1O63); $gS7dY[] = "> {$rZJie}"; } } goto YUWwV; GGXFO: $gS7dY[] = '删除文件：'; goto S7PUC; YUWwV: $gS7dY[] = ''; goto FXOr2; FXOr2: } goto VPbQ3; dg3R3: $LAwgR = Artisan::call('modstart:module-install-all'); goto zsW4E; ezIdB: $yCUD1 = FileUtil::filePathWritableCheck($eVOe0); goto bac05; TbUP8: ModStart::clearCache(); goto fI_gB; cCUNc: $gS7dY = array(); goto uyorD; uyorD: if (!empty($vddDn['add'])) { goto DieCe; TQNn8: foreach ($vddDn['add'] as $rZJie) { goto BVdt1; thNh5: $gS7dY[] = "> {$rZJie}"; goto fSWOu; WXQen: FileUtil::write(base_path($rZJie), $ZA40Q); goto thNh5; BVdt1: $ZA40Q = $ac7RJ->getFileContent($rZJie); goto WXQen; fSWOu: } goto pcdZW; pcdZW: $gS7dY[] = ''; goto ZKdhM; DieCe: $gS7dY[] = '新增文件：'; goto TQNn8; ZKdhM: } goto tgcu9; O8e_P: return Response::generateSuccessData(array('logs' => $gS7dY)); goto vWZsH; fI_gB: try { $LAwgR = Artisan::call('migrate'); } catch (\Exception $Q19lV) { $LAwgR = -1; } goto kCA9E; rHV30: $eVOe0 = array(); goto iP2pY; tsn5_: $vddDn = @json_decode(file_get_contents($TiNKC), true); goto qjHgc; kCA9E: BizException::throwsIf('调用 php artisan migrate 失败', 0 != $LAwgR); goto dg3R3; zsW4E: BizException::throwsIf('调用 php artisan modstart:module-install-all 失败', 0 != $LAwgR); goto sEm8X; Q7Sp4: $ac7RJ = new Zipper(); goto i7GOH; i7GOH: $ac7RJ->make($HDfwB); goto cCUNc; otgLu: BizException::throwsIf('package不存在', !file_exists($HDfwB)); goto RiYKf; qjHgc: BizException::throwsIf('diffContent为空', empty($vddDn)); goto rHV30; tgcu9: if (!empty($vddDn['update'])) { goto KrbCx; AbwOW: foreach ($vddDn['update'] as $rZJie) { goto smxUM; apmdq: FileUtil::write(base_path($rZJie), $ZA40Q); goto IZen6; smxUM: $ZA40Q = $ac7RJ->getFileContent($rZJie); goto apmdq; IZen6: $gS7dY[] = "> {$rZJie}"; goto myAcv; myAcv: } goto szAli; szAli: $gS7dY[] = ''; goto RSueY; KrbCx: $gS7dY[] = '修改文件：'; goto AbwOW; RSueY: } goto LcCC4; RiYKf: BizException::throwsIf('diffContentFile不存在', !file_exists($TiNKC)); goto tsn5_; sEm8X: FileUtil::safeCleanLocalTemp($HDfwB); goto zZlfS; zZlfS: FileUtil::safeCleanLocalTemp($TiNKC); goto O8e_P; bac05: BizException::throwsIfResponseError($yCUD1); goto Q7Sp4; iP2pY: if (!empty($vddDn['add'])) { $eVOe0 = array_merge($eVOe0, $vddDn['add']); } goto zqwcD; zqwcD: if (!empty($vddDn['update'])) { $eVOe0 = array_merge($eVOe0, $vddDn['update']); } goto ezIdB; vWZsH: } }