<?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($N0nrY, $Pg57y = array(), $gVIp7 = null) { return CurlUtil::postJSONBody(self::REMOTE_BASE . $N0nrY, $Pg57y, array('header' => array('api-token' => $gVIp7, 'X-Requested-With' => 'XMLHttpRequest'))); } public static function latest() { goto emggy; DWRz9: BizException::throwsIfResponseError($Ecj99); goto AWuc1; emggy: $Ecj99 = self::baseRequest('/api/app/latest', array('app' => AppConstant::APP, 'version' => AppConstant::VERSION)); goto DWRz9; AWuc1: return $Ecj99['data']; goto bDbWs; bDbWs: } public static function downloadPackage($gVIp7, $P0Pq4, $EVpLi, $VVfot) { goto U8d0W; iTFYl: $mS5Yr = FileUtil::generateLocalTempPath('json'); goto e6GZL; tcfzk: file_put_contents($mTlfP, $Pg57y); goto XHUKM; jEjP6: return Response::generateSuccessData(array('diffContentFile' => $mS5Yr, 'package' => $mTlfP, 'packageSize' => filesize($mTlfP))); goto hInBJ; e6GZL: file_put_contents($mS5Yr, $YWLjt); goto jEjP6; wcH7v: $rGd6k = $Ecj99['data']['packageMd5']; goto zihT0; NTBzN: $Pg57y = CurlUtil::getRaw($Pzx09); goto vBK_M; zihT0: $YWLjt = $Ecj99['data']['diffContent']; goto NTBzN; vBK_M: BizException::throwsIfEmpty('安装包获取失败', $Pg57y); goto TWzIG; U8d0W: $Ecj99 = self::baseRequest('/api/app/download_package', array('app' => $P0Pq4, 'fromVersion' => $EVpLi, 'toVersion' => $VVfot), $gVIp7); goto Jq7FG; Jq7FG: BizException::throwsIfResponseError($Ecj99); goto fC3rm; XHUKM: BizException::throwsIf('文件MD5校验失败', md5_file($mTlfP) != $rGd6k); goto iTFYl; TWzIG: $mTlfP = FileUtil::generateLocalTempPath('zip'); goto tcfzk; fC3rm: $Pzx09 = $Ecj99['data']['package']; goto wcH7v; hInBJ: } public static function upgradePackage($Pzx09, $mS5Yr) { goto gajq0; DPMgK: $pFknF->make($Pzx09); goto F0Am6; LaqNC: BizException::throwsIf('diffContentFile不存在', !file_exists($mS5Yr)); goto bZSN6; crCYl: BizException::throwsIf('调用 php artisan migrate 失败', 0 != $h0L7n); goto hzvBl; gajq0: BizException::throwsIf('package不存在', !file_exists($Pzx09)); goto LaqNC; N2lRY: $pFknF = new Zipper(); goto DPMgK; bZSN6: $YWLjt = @json_decode(file_get_contents($mS5Yr), true); goto WOrrV; ppfBr: if (!empty($YWLjt['add'])) { $dBz7d = array_merge($dBz7d, $YWLjt['add']); } goto OoBFV; vDsPn: $pFknF->close(); goto QsX0V; CWbqc: BizException::throwsIf('调用 php artisan modstart:module-install-all 失败', 0 != $h0L7n); goto BHwns; rIivC: try { $h0L7n = Artisan::call('migrate'); } catch (\Exception $fWY9h) { $h0L7n = -1; } goto crCYl; QsX0V: ModStart::clearCache(); goto rIivC; nc1YW: $dBz7d = array(); goto ppfBr; HsHUl: FileUtil::safeCleanLocalTemp($mS5Yr); goto wi1t0; j5teo: if (!empty($YWLjt['add'])) { goto qYtrX; oj3AJ: foreach ($YWLjt['add'] as $Jm77a) { goto KWLZO; XriM0: $VmuuB[] = "> {$Jm77a}"; goto PK4g5; z1Q8o: FileUtil::write(base_path($Jm77a), $MPmfx); goto XriM0; KWLZO: $MPmfx = $pFknF->getFileContent($Jm77a); goto z1Q8o; PK4g5: } goto FaxWK; FaxWK: $VmuuB[] = ''; goto S6a6S; qYtrX: $VmuuB[] = '新增文件：'; goto oj3AJ; S6a6S: } goto q2SRg; Co5ok: if (!empty($YWLjt['delete'])) { goto zijwu; s3DH3: $VmuuB[] = ''; goto vXUF0; OlWOg: foreach ($YWLjt['delete'] as $Jm77a) { if (file_exists($ooyHY = base_path($Jm77a))) { @unlink($ooyHY); $VmuuB[] = "> {$Jm77a}"; } } goto s3DH3; zijwu: $VmuuB[] = '删除文件：'; goto OlWOg; vXUF0: } goto vDsPn; wi1t0: return Response::generateSuccessData(array('logs' => $VmuuB)); goto dIybG; q2SRg: if (!empty($YWLjt['update'])) { goto IKUQm; ejRHh: $VmuuB[] = ''; goto lgeLo; IKUQm: $VmuuB[] = '修改文件：'; goto IHUAu; IHUAu: foreach ($YWLjt['update'] as $Jm77a) { goto aXGqM; UY8SC: FileUtil::write(base_path($Jm77a), $MPmfx); goto Jk4PD; aXGqM: $MPmfx = $pFknF->getFileContent($Jm77a); goto UY8SC; Jk4PD: $VmuuB[] = "> {$Jm77a}"; goto gWXzF; gWXzF: } goto ejRHh; lgeLo: } goto Co5ok; gVWcy: BizException::throwsIfResponseError($Ecj99); goto N2lRY; WOrrV: BizException::throwsIf('diffContent为空', empty($YWLjt)); goto nc1YW; hzvBl: $h0L7n = Artisan::call('modstart:module-install-all'); goto CWbqc; BHwns: FileUtil::safeCleanLocalTemp($Pzx09); goto HsHUl; OoBFV: if (!empty($YWLjt['update'])) { $dBz7d = array_merge($dBz7d, $YWLjt['update']); } goto s1ePt; s1ePt: $Ecj99 = FileUtil::filePathWritableCheck($dBz7d); goto gVWcy; F0Am6: $VmuuB = array(); goto j5teo; dIybG: } }