<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Tecmz\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://www.tecmz.com'; private static function baseRequest($i8iu_, $GpXwG = array(), $cUrpz = null) { return CurlUtil::postJSONBody(self::REMOTE_BASE . $i8iu_, $GpXwG, array('header' => array('api-token' => $cUrpz, 'X-Requested-With' => 'XMLHttpRequest'))); } public static function latest() { goto GOnOQ; O56Y1: return $gMg9x['data']; goto CnZQ2; TOC4k: BizException::throwsIfResponseError($gMg9x); goto O56Y1; GOnOQ: $gMg9x = self::baseRequest('/api/app/latest', array('app' => AppConstant::APP, 'version' => AppConstant::VERSION)); goto TOC4k; CnZQ2: } public static function downloadPackage($cUrpz, $WFzTb, $hAY2O, $U1vNQ) { goto CGGGM; mHac5: return Response::generateSuccessData(array('diffContentFile' => $pboir, 'package' => $Yjknd, 'packageSize' => filesize($Yjknd))); goto GqxqD; URsf0: file_put_contents($Yjknd, $GpXwG); goto WA8lo; uVP95: $GpXwG = CurlUtil::getRaw($MZdfD); goto i3XXs; yXCGs: $pboir = FileUtil::generateLocalTempPath('json'); goto nYC1k; RFWqg: $Yjknd = FileUtil::generateLocalTempPath('zip'); goto URsf0; RVE2X: BizException::throwsIfResponseError($gMg9x); goto E3Tyx; WA8lo: BizException::throwsIf('文件MD5校验失败', md5_file($Yjknd) != $bQ1Td); goto yXCGs; P_1Hk: $bQ1Td = $gMg9x['data']['packageMd5']; goto bwYbX; E3Tyx: $MZdfD = $gMg9x['data']['package']; goto P_1Hk; i3XXs: BizException::throwsIfEmpty('安装包获取失败', $GpXwG); goto RFWqg; nYC1k: file_put_contents($pboir, $rFPP6); goto mHac5; CGGGM: $gMg9x = self::baseRequest('/api/app/download_package', array('app' => $WFzTb, 'fromVersion' => $hAY2O, 'toVersion' => $U1vNQ), $cUrpz); goto RVE2X; bwYbX: $rFPP6 = $gMg9x['data']['diffContent']; goto uVP95; GqxqD: } public static function upgradePackage($MZdfD, $pboir) { goto c8WBg; wazt8: FileUtil::safeCleanLocalTemp($MZdfD); goto hfTSr; W9iLT: if (!empty($rFPP6['update'])) { goto rmdVr; rmdVr: $bQ5pn[] = '修改文件：'; goto Be1F3; Be1F3: foreach ($rFPP6['update'] as $wjJPd) { goto mwoMQ; mwoMQ: $Ral1i = $sMu5I->getFileContent($wjJPd); goto DUnqe; DUnqe: FileUtil::write(base_path($wjJPd), $Ral1i); goto j38jx; j38jx: $bQ5pn[] = "> {$wjJPd}"; goto sbPO2; sbPO2: } goto Ecv3t; Ecv3t: $bQ5pn[] = ''; goto aNjoj; aNjoj: } goto nR0Jb; VCftF: if (!empty($rFPP6['add'])) { $Gqf62 = array_merge($Gqf62, $rFPP6['add']); } goto R3p1v; dtxOX: BizException::throwsIf('调用 php artisan modstart:module-install-all 失败', 0 != $yTeE1); goto wazt8; kz2f9: return Response::generateSuccessData(array('logs' => $bQ5pn)); goto bnQj4; Txy3J: ModStart::clearCache(); goto Subqr; fmW9k: BizException::throwsIfResponseError($gMg9x); goto kgAU0; gnYEz: $sMu5I->close(); goto Txy3J; Subqr: try { $yTeE1 = Artisan::call('migrate'); } catch (\Exception $re7gC) { $yTeE1 = -1; } goto Aivvi; UqzVv: $sMu5I->make($MZdfD); goto DtRtq; hHLhY: BizException::throwsIf('diffContentFile不存在', !file_exists($pboir)); goto sAVGB; ug9Yf: try { $yTeE1 = Artisan::call('modstart:module-install-all'); } catch (\Exception $re7gC) { $yTeE1 = -1; } goto dtxOX; hfTSr: FileUtil::safeCleanLocalTemp($pboir); goto kz2f9; w_gl0: $Gqf62 = array(); goto VCftF; sAVGB: $rFPP6 = @json_decode(file_get_contents($pboir), true); goto BEmtJ; kgAU0: $sMu5I = new Zipper(); goto UqzVv; DtRtq: $bQ5pn = array(); goto x1DMM; R3p1v: if (!empty($rFPP6['update'])) { $Gqf62 = array_merge($Gqf62, $rFPP6['update']); } goto Bi_VO; c8WBg: BizException::throwsIf('package不存在', !file_exists($MZdfD)); goto hHLhY; Aivvi: BizException::throwsIf('调用 php artisan migrate 失败', 0 != $yTeE1); goto ug9Yf; nR0Jb: if (!empty($rFPP6['delete'])) { goto Mx32g; j3u0k: $bQ5pn[] = ''; goto LqIPM; Mx32g: $bQ5pn[] = '删除文件：'; goto G0v8B; G0v8B: foreach ($rFPP6['delete'] as $wjJPd) { if (file_exists($sUL93 = base_path($wjJPd))) { @unlink($sUL93); $bQ5pn[] = "> {$wjJPd}"; } } goto j3u0k; LqIPM: } goto gnYEz; Bi_VO: $gMg9x = FileUtil::filePathWritableCheck($Gqf62); goto fmW9k; x1DMM: if (!empty($rFPP6['add'])) { goto FRRd4; FRRd4: $bQ5pn[] = '新增文件：'; goto zJ97d; zJ97d: foreach ($rFPP6['add'] as $wjJPd) { goto EPEUR; EPEUR: $Ral1i = $sMu5I->getFileContent($wjJPd); goto Ql9mO; tynbh: $bQ5pn[] = "> {$wjJPd}"; goto B4PPR; Ql9mO: FileUtil::write(base_path($wjJPd), $Ral1i); goto tynbh; B4PPR: } goto P5q80; P5q80: $bQ5pn[] = ''; goto DQNY5; DQNY5: } goto W9iLT; BEmtJ: BizException::throwsIf('diffContent为空', empty($rFPP6)); goto w_gl0; bnQj4: } }