<?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($Us1dU, $avcnU = array(), $MMmFM = null) { return CurlUtil::postJSONBody(self::REMOTE_BASE . $Us1dU, $avcnU, array('header' => array('api-token' => $MMmFM, 'X-Requested-With' => 'XMLHttpRequest'))); } public static function latest() { goto r67mi; ExHCe: return $rhLXE['data']; goto txmLG; OGwIB: BizException::throwsIfResponseError($rhLXE); goto ExHCe; r67mi: $rhLXE = self::baseRequest('/api/app/latest', array('app' => AppConstant::APP, 'version' => AppConstant::VERSION)); goto OGwIB; txmLG: } public static function downloadPackage($MMmFM, $IXDHb, $aYuf7, $vodoI) { goto u4o8T; AOmLd: $MtKsl = $rhLXE['data']['packageMd5']; goto siWcH; lO7aD: $kO40W = FileUtil::generateLocalTempPath('json'); goto oPC1E; DDYch: BizException::throwsIfResponseError($rhLXE); goto YMOSD; oPC1E: file_put_contents($kO40W, $jenmr); goto AjMV1; YMOSD: $pd0Ai = $rhLXE['data']['package']; goto AOmLd; WIGUb: file_put_contents($tHW_I, $avcnU); goto sRe6E; u4o8T: $rhLXE = self::baseRequest('/api/app/download_package', array('app' => $IXDHb, 'fromVersion' => $aYuf7, 'toVersion' => $vodoI), $MMmFM); goto DDYch; qP6Lv: $avcnU = CurlUtil::getRaw($pd0Ai); goto fOLj_; tWW1D: $tHW_I = FileUtil::generateLocalTempPath('zip'); goto WIGUb; fOLj_: BizException::throwsIfEmpty('安装包获取失败', $avcnU); goto tWW1D; sRe6E: BizException::throwsIf('文件MD5校验失败', md5_file($tHW_I) != $MtKsl); goto lO7aD; AjMV1: return Response::generateSuccessData(array('diffContentFile' => $kO40W, 'package' => $tHW_I, 'packageSize' => filesize($tHW_I))); goto uRpIf; siWcH: $jenmr = $rhLXE['data']['diffContent']; goto qP6Lv; uRpIf: } public static function upgradePackage($pd0Ai, $kO40W) { goto LPz43; qnfJS: $jenmr = @json_decode(file_get_contents($kO40W), true); goto iO8Sk; UxHIf: BizException::throwsIfResponseError($rhLXE); goto oD2La; iO8Sk: BizException::throwsIf('diffContent为空', empty($jenmr)); goto MAeSY; nekfX: $rhLXE = FileUtil::filePathWritableCheck($H2FF9); goto UxHIf; vGufA: BizException::throwsIf('调用 php artisan migrate 失败', 0 != $Jk1lG); goto YghSR; FDSPs: return Response::generateSuccessData(array('logs' => $G2Zzj)); goto umNbw; k0S0z: BizException::throwsIf('diffContentFile不存在', !file_exists($kO40W)); goto qnfJS; vuZcj: FileUtil::safeCleanLocalTemp($pd0Ai); goto wjw5f; YghSR: $Jk1lG = Artisan::call('modstart:module-install-all'); goto mRlSs; SBWla: if (!empty($jenmr['delete'])) { goto HplfT; PpuJI: foreach ($jenmr['delete'] as $bHKYd) { if (file_exists($OCvfG = base_path($bHKYd))) { @unlink($OCvfG); $G2Zzj[] = "> {$bHKYd}"; } } goto g7hp3; HplfT: $G2Zzj[] = '删除文件：'; goto PpuJI; g7hp3: $G2Zzj[] = ''; goto QQg86; QQg86: } goto Uehyt; UWp6N: try { $Jk1lG = Artisan::call('migrate'); } catch (\Exception $qoTNG) { $Jk1lG = -1; } goto vGufA; oD2La: $hd3MY = new Zipper(); goto rCDVm; qzrbw: $G2Zzj = array(); goto wtHXS; wjw5f: FileUtil::safeCleanLocalTemp($kO40W); goto FDSPs; ZtgMg: if (!empty($jenmr['add'])) { $H2FF9 = array_merge($H2FF9, $jenmr['add']); } goto X0y3G; MAeSY: $H2FF9 = array(); goto ZtgMg; mRlSs: BizException::throwsIf('调用 php artisan modstart:module-install-all 失败', 0 != $Jk1lG); goto vuZcj; rCDVm: $hd3MY->make($pd0Ai); goto qzrbw; lKlSx: if (!empty($jenmr['update'])) { goto gXOtR; bKv6D: foreach ($jenmr['update'] as $bHKYd) { goto ij7YR; ij7YR: $ybjC4 = $hd3MY->getFileContent($bHKYd); goto m9otn; fHXSy: $G2Zzj[] = "> {$bHKYd}"; goto lbtk6; m9otn: FileUtil::write(base_path($bHKYd), $ybjC4); goto fHXSy; lbtk6: } goto JEEIn; JEEIn: $G2Zzj[] = ''; goto A9mDS; gXOtR: $G2Zzj[] = '修改文件：'; goto bKv6D; A9mDS: } goto SBWla; Uehyt: $hd3MY->close(); goto iR3ON; wtHXS: if (!empty($jenmr['add'])) { goto u2l6p; u2l6p: $G2Zzj[] = '新增文件：'; goto Ja6PM; Ja6PM: foreach ($jenmr['add'] as $bHKYd) { goto Evzxw; Evzxw: $ybjC4 = $hd3MY->getFileContent($bHKYd); goto ajn6E; ajn6E: FileUtil::write(base_path($bHKYd), $ybjC4); goto bSPCT; bSPCT: $G2Zzj[] = "> {$bHKYd}"; goto n3BY1; n3BY1: } goto POCqo; POCqo: $G2Zzj[] = ''; goto aKwrP; aKwrP: } goto lKlSx; LPz43: BizException::throwsIf('package不存在', !file_exists($pd0Ai)); goto k0S0z; iR3ON: ModStart::clearCache(); goto UWp6N; X0y3G: if (!empty($jenmr['update'])) { $H2FF9 = array_merge($H2FF9, $jenmr['update']); } goto nekfX; umNbw: } }