<?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($MVJwq, $smBDO = array(), $h7611 = null) { return CurlUtil::postJSONBody(self::REMOTE_BASE . $MVJwq, $smBDO, array('header' => array('api-token' => $h7611, 'X-Requested-With' => 'XMLHttpRequest'))); } public static function latest() { goto CkxBm; CkxBm: $Gs3Xd = self::baseRequest('/api/app/latest', array('app' => AppConstant::APP, 'version' => AppConstant::VERSION)); goto EEgjd; EEgjd: BizException::throwsIfResponseError($Gs3Xd); goto KITeh; KITeh: return $Gs3Xd['data']; goto xBRv9; xBRv9: } public static function downloadPackage($h7611, $E1Gi8, $rmv8P, $iGHvN) { goto rYBgP; oCYRW: BizException::throwsIfResponseError($Gs3Xd); goto gIWdX; jCXRd: $fZgZn = $Gs3Xd['data']['diffContent']; goto l2utG; woIfs: $DNs9z = FileUtil::generateLocalTempPath('json'); goto gDy7u; R7S3m: $YDT3k = FileUtil::generateLocalTempPath('zip'); goto d1sir; gIWdX: $xAW3P = $Gs3Xd['data']['package']; goto XcbK6; S0lCg: BizException::throwsIfEmpty('安装包获取失败', $smBDO); goto R7S3m; d1sir: file_put_contents($YDT3k, $smBDO); goto DDVWQ; cclJp: return Response::generateSuccessData(array('diffContentFile' => $DNs9z, 'package' => $YDT3k, 'packageSize' => filesize($YDT3k))); goto dGnnj; XcbK6: $qWRiP = $Gs3Xd['data']['packageMd5']; goto jCXRd; DDVWQ: BizException::throwsIf('文件MD5校验失败', md5_file($YDT3k) != $qWRiP); goto woIfs; gDy7u: file_put_contents($DNs9z, $fZgZn); goto cclJp; l2utG: $smBDO = CurlUtil::getRaw($xAW3P); goto S0lCg; rYBgP: $Gs3Xd = self::baseRequest('/api/app/download_package', array('app' => $E1Gi8, 'fromVersion' => $rmv8P, 'toVersion' => $iGHvN), $h7611); goto oCYRW; dGnnj: } public static function upgradePackage($xAW3P, $DNs9z) { goto ylqBS; XpARM: try { $N3esS = Artisan::call('migrate'); } catch (\Exception $hSVcc) { $N3esS = -1; } goto Gvi2F; iZF65: $yUlGm->make($xAW3P); goto Du8eN; uwQT6: FileUtil::safeCleanLocalTemp($xAW3P); goto bJObN; l5D9T: $PzMnA = array(); goto ExXyy; Q833Q: if (!empty($fZgZn['update'])) { $PzMnA = array_merge($PzMnA, $fZgZn['update']); } goto Vq2q6; h2pzQ: BizException::throwsIf('调用 php artisan modstart:module-install-all 失败', 0 != $N3esS); goto uwQT6; wAiRo: if (!empty($fZgZn['update'])) { goto TIZWF; hjraa: foreach ($fZgZn['update'] as $x_XbT) { goto CVcw2; CVcw2: $eTwx_ = $yUlGm->getFileContent($x_XbT); goto zlsJH; zlsJH: FileUtil::write(base_path($x_XbT), $eTwx_); goto eKk55; eKk55: $zkKO0[] = "> {$x_XbT}"; goto DFfgB; DFfgB: } goto PWAfe; PWAfe: $zkKO0[] = ''; goto eIWoB; TIZWF: $zkKO0[] = '修改文件：'; goto hjraa; eIWoB: } goto FuO0y; oQEP2: $yUlGm = new Zipper(); goto iZF65; CUHVI: BizException::throwsIf('diffContent为空', empty($fZgZn)); goto l5D9T; FuO0y: if (!empty($fZgZn['delete'])) { goto sl8QW; aMbXx: foreach ($fZgZn['delete'] as $x_XbT) { if (file_exists($Kcl6E = base_path($x_XbT))) { @unlink($Kcl6E); $zkKO0[] = "> {$x_XbT}"; } } goto o0XTr; o0XTr: $zkKO0[] = ''; goto AlXDU; sl8QW: $zkKO0[] = '删除文件：'; goto aMbXx; AlXDU: } goto cFlse; bJObN: FileUtil::safeCleanLocalTemp($DNs9z); goto zLqJr; n2koq: $fZgZn = @json_decode(file_get_contents($DNs9z), true); goto CUHVI; Du8eN: $zkKO0 = array(); goto cAH9z; cAH9z: if (!empty($fZgZn['add'])) { goto iEJJW; xyiMl: foreach ($fZgZn['add'] as $x_XbT) { goto dIM3r; MGrH3: FileUtil::write(base_path($x_XbT), $eTwx_); goto jnzAl; jnzAl: $zkKO0[] = "> {$x_XbT}"; goto bLGVZ; dIM3r: $eTwx_ = $yUlGm->getFileContent($x_XbT); goto MGrH3; bLGVZ: } goto L6M1z; iEJJW: $zkKO0[] = '新增文件：'; goto xyiMl; L6M1z: $zkKO0[] = ''; goto o78rH; o78rH: } goto wAiRo; oydx0: ModStart::clearCache(); goto XpARM; n26gk: $N3esS = Artisan::call('modstart:module-install-all'); goto h2pzQ; ExXyy: if (!empty($fZgZn['add'])) { $PzMnA = array_merge($PzMnA, $fZgZn['add']); } goto Q833Q; zLqJr: return Response::generateSuccessData(array('logs' => $zkKO0)); goto ahUwB; ylqBS: BizException::throwsIf('package不存在', !file_exists($xAW3P)); goto tudMq; cFlse: $yUlGm->close(); goto oydx0; kLsVE: BizException::throwsIfResponseError($Gs3Xd); goto oQEP2; Gvi2F: BizException::throwsIf('调用 php artisan migrate 失败', 0 != $N3esS); goto n26gk; Vq2q6: $Gs3Xd = FileUtil::filePathWritableCheck($PzMnA); goto kLsVE; tudMq: BizException::throwsIf('diffContentFile不存在', !file_exists($DNs9z)); goto n2koq; ahUwB: } }