<?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($Mh8Wv, $q62oK = array(), $hTSDI = null) { return CurlUtil::postJSONBody(self::REMOTE_BASE . $Mh8Wv, $q62oK, array('header' => array('api-token' => $hTSDI, 'X-Requested-With' => 'XMLHttpRequest'))); } public static function latest() { goto OGa03; OGa03: $oHb9_ = self::baseRequest('/api/app/latest', array('app' => AppConstant::APP, 'version' => AppConstant::VERSION)); goto Z2Inj; Z2Inj: BizException::throwsIfResponseError($oHb9_); goto xrzUF; xrzUF: return $oHb9_['data']; goto rXpm9; rXpm9: } public static function downloadPackage($hTSDI, $o3M2b, $DH4Pd, $XzQvH) { goto Pwh9d; mP13U: $gPtkf = FileUtil::generateLocalTempPath('json'); goto h8oG7; LCBQ9: $a9kFA = $oHb9_['data']['packageMd5']; goto vRcUx; h8oG7: file_put_contents($gPtkf, $yW_uT); goto Vf5_b; xOP8t: $ie1JD = FileUtil::generateLocalTempPath('zip'); goto X0qok; X0qok: file_put_contents($ie1JD, $q62oK); goto QhDwQ; Vf5_b: return Response::generateSuccessData(array('diffContentFile' => $gPtkf, 'package' => $ie1JD, 'packageSize' => filesize($ie1JD))); goto nadXX; tLCJZ: BizException::throwsIfEmpty('安装包获取失败', $q62oK); goto xOP8t; Pwh9d: $oHb9_ = self::baseRequest('/api/app/download_package', array('app' => $o3M2b, 'fromVersion' => $DH4Pd, 'toVersion' => $XzQvH), $hTSDI); goto Iuj2M; wI5PX: $q62oK = CurlUtil::getRaw($jveNw); goto tLCJZ; QhDwQ: BizException::throwsIf('文件MD5校验失败', md5_file($ie1JD) != $a9kFA); goto mP13U; Jf3Lm: $jveNw = $oHb9_['data']['package']; goto LCBQ9; vRcUx: $yW_uT = $oHb9_['data']['diffContent']; goto wI5PX; Iuj2M: BizException::throwsIfResponseError($oHb9_); goto Jf3Lm; nadXX: } public static function upgradePackage($jveNw, $gPtkf) { goto mYNYE; g4W3e: BizException::throwsIf('diffContent为空', empty($yW_uT)); goto CQK02; DRD02: BizException::throwsIf('diffContentFile不存在', !file_exists($gPtkf)); goto ytVg6; HqSSp: BizException::throwsIf('调用 php artisan modstart:module-install-all 失败', 0 != $SvOVI); goto OSZFe; DCcjV: $SvOVI = Artisan::call('modstart:module-install-all'); goto HqSSp; SHGll: $OoGkc->make($jveNw); goto KaL0x; NPOPB: if (!empty($yW_uT['update'])) { goto R1iPM; R1iPM: $SMRjI[] = '修改文件：'; goto krZX0; EBeJU: $SMRjI[] = ''; goto IZGw8; krZX0: foreach ($yW_uT['update'] as $obXaA) { goto LLsIt; e7_Aw: FileUtil::write(base_path($obXaA), $fKViA); goto dH2Ju; dH2Ju: $SMRjI[] = "> {$obXaA}"; goto CZe1R; LLsIt: $fKViA = $OoGkc->getFileContent($obXaA); goto e7_Aw; CZe1R: } goto EBeJU; IZGw8: } goto Db06y; DUniW: $OoGkc = new Zipper(); goto SHGll; awjce: $oHb9_ = FileUtil::filePathWritableCheck($rbfkm); goto r1rO4; AckLD: FileUtil::safeCleanLocalTemp($gPtkf); goto fF0sx; WCmWA: $OoGkc->close(); goto AtJgd; KaL0x: $SMRjI = array(); goto wIUxT; AWz34: if (!empty($yW_uT['update'])) { $rbfkm = array_merge($rbfkm, $yW_uT['update']); } goto awjce; wIUxT: if (!empty($yW_uT['add'])) { goto Ci5H3; Ci5H3: $SMRjI[] = '新增文件：'; goto irxA6; U1eEu: $SMRjI[] = ''; goto rBg_m; irxA6: foreach ($yW_uT['add'] as $obXaA) { goto OJZxf; cr4En: FileUtil::write(base_path($obXaA), $fKViA); goto hDOTc; hDOTc: $SMRjI[] = "> {$obXaA}"; goto wgsx8; OJZxf: $fKViA = $OoGkc->getFileContent($obXaA); goto cr4En; wgsx8: } goto U1eEu; rBg_m: } goto NPOPB; fF0sx: return Response::generateSuccessData(array('logs' => $SMRjI)); goto THnit; CQK02: $rbfkm = array(); goto zrwSC; zrwSC: if (!empty($yW_uT['add'])) { $rbfkm = array_merge($rbfkm, $yW_uT['add']); } goto AWz34; WSsz5: BizException::throwsIf('调用 php artisan migrate 失败', 0 != $SvOVI); goto DCcjV; q_SG8: try { $SvOVI = Artisan::call('migrate'); } catch (\Exception $cknMI) { $SvOVI = -1; } goto WSsz5; r1rO4: BizException::throwsIfResponseError($oHb9_); goto DUniW; AtJgd: ModStart::clearCache(); goto q_SG8; mYNYE: BizException::throwsIf('package不存在', !file_exists($jveNw)); goto DRD02; OSZFe: FileUtil::safeCleanLocalTemp($jveNw); goto AckLD; ytVg6: $yW_uT = @json_decode(file_get_contents($gPtkf), true); goto g4W3e; Db06y: if (!empty($yW_uT['delete'])) { goto IxXUL; IxXUL: $SMRjI[] = '删除文件：'; goto Rlc30; ZoA3l: $SMRjI[] = ''; goto Yx1nE; Rlc30: foreach ($yW_uT['delete'] as $obXaA) { if (file_exists($r6_O_ = base_path($obXaA))) { @unlink($r6_O_); $SMRjI[] = "> {$obXaA}"; } } goto ZoA3l; Yx1nE: } goto WCmWA; THnit: } }