<?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($tCUR6, $MGhSY = array(), $p23ja = null) { return CurlUtil::postJSONBody(self::REMOTE_BASE . $tCUR6, $MGhSY, array('header' => array('api-token' => $p23ja, 'X-Requested-With' => 'XMLHttpRequest'))); } public static function latest() { goto XXBvo; WQvIX: return $om_hh['data']; goto RIad9; XXBvo: $om_hh = self::baseRequest('/api/app/latest', array('app' => AppConstant::APP, 'version' => AppConstant::VERSION)); goto SmYEG; SmYEG: BizException::throwsIfResponseError($om_hh); goto WQvIX; RIad9: } public static function downloadPackage($p23ja, $oDLfz, $Bm01A, $GRVfW) { goto PqIM4; O3F3O: file_put_contents($JhjhO, $IL3gB); goto lMP1Y; BXxps: $MGhSY = CurlUtil::getRaw($qWHC7); goto QuDbm; j3WZl: $JhjhO = FileUtil::generateLocalTempPath('json'); goto O3F3O; lMP1Y: return Response::generateSuccessData(array('diffContentFile' => $JhjhO, 'package' => $CpeI2, 'packageSize' => filesize($CpeI2))); goto qlF91; AXEYd: $CpeI2 = FileUtil::generateLocalTempPath('zip'); goto Rtm7R; b4X3S: $qWHC7 = $om_hh['data']['package']; goto SfRFQ; Rtm7R: file_put_contents($CpeI2, $MGhSY); goto hIUXO; QuDbm: BizException::throwsIfEmpty('安装包获取失败', $MGhSY); goto AXEYd; MvFvm: $IL3gB = $om_hh['data']['diffContent']; goto BXxps; hIUXO: BizException::throwsIf('文件MD5校验失败', md5_file($CpeI2) != $PxKCQ); goto j3WZl; SfRFQ: $PxKCQ = $om_hh['data']['packageMd5']; goto MvFvm; uIWsW: BizException::throwsIfResponseError($om_hh); goto b4X3S; PqIM4: $om_hh = self::baseRequest('/api/app/download_package', array('app' => $oDLfz, 'fromVersion' => $Bm01A, 'toVersion' => $GRVfW), $p23ja); goto uIWsW; qlF91: } public static function upgradePackage($qWHC7, $JhjhO) { goto v8eI6; hY5cx: $om_hh = FileUtil::filePathWritableCheck($XTNOG); goto HkZoC; USC5B: if (!empty($IL3gB['update'])) { $XTNOG = array_merge($XTNOG, $IL3gB['update']); } goto hY5cx; qP0pf: BizException::throwsIf('调用 php artisan migrate 失败', 0 != $rx99h); goto hVXtv; dPWqS: ModStart::clearCache(); goto lAMIW; Mr_nI: if (!empty($IL3gB['add'])) { $XTNOG = array_merge($XTNOG, $IL3gB['add']); } goto USC5B; ZFtak: if (!empty($IL3gB['add'])) { goto tKDM5; GSDmy: $sjJrw[] = ''; goto wTQr5; Fgw89: foreach ($IL3gB['add'] as $SgkW3) { goto KUMbf; Vn9Wq: $sjJrw[] = "> {$SgkW3}"; goto kp_LX; KUMbf: $OfwYj = $S9cV0->getFileContent($SgkW3); goto ZaVv2; ZaVv2: FileUtil::write(base_path($SgkW3), $OfwYj); goto Vn9Wq; kp_LX: } goto GSDmy; tKDM5: $sjJrw[] = '新增文件：'; goto Fgw89; wTQr5: } goto Zm85x; kbyqv: return Response::generateSuccessData(array('logs' => $sjJrw)); goto Oxxtn; xUq2K: if (!empty($IL3gB['delete'])) { goto aUdYo; gKlJq: foreach ($IL3gB['delete'] as $SgkW3) { if (file_exists($pXscO = base_path($SgkW3))) { @unlink($pXscO); $sjJrw[] = "> {$SgkW3}"; } } goto hlzVc; hlzVc: $sjJrw[] = ''; goto GvQId; aUdYo: $sjJrw[] = '删除文件：'; goto gKlJq; GvQId: } goto ZOORI; a1z4O: FileUtil::safeCleanLocalTemp($qWHC7); goto xEqvp; Iwxiu: $XTNOG = array(); goto Mr_nI; QQyLe: $S9cV0->make($qWHC7); goto WNC5d; fVWKu: BizException::throwsIf('diffContentFile不存在', !file_exists($JhjhO)); goto pLsAM; hVXtv: $rx99h = Artisan::call('modstart:module-install-all'); goto auq5g; ZOORI: $S9cV0->close(); goto dPWqS; WNC5d: $sjJrw = array(); goto ZFtak; ndIhp: $S9cV0 = new Zipper(); goto QQyLe; HkZoC: BizException::throwsIfResponseError($om_hh); goto ndIhp; pLsAM: $IL3gB = @json_decode(file_get_contents($JhjhO), true); goto EWM_Z; Zm85x: if (!empty($IL3gB['update'])) { goto PdAul; PdAul: $sjJrw[] = '修改文件：'; goto ife5P; ife5P: foreach ($IL3gB['update'] as $SgkW3) { goto xTsrg; gPf7b: $sjJrw[] = "> {$SgkW3}"; goto SzHm6; YHyEn: FileUtil::write(base_path($SgkW3), $OfwYj); goto gPf7b; xTsrg: $OfwYj = $S9cV0->getFileContent($SgkW3); goto YHyEn; SzHm6: } goto uLi0H; uLi0H: $sjJrw[] = ''; goto BRMzF; BRMzF: } goto xUq2K; EWM_Z: BizException::throwsIf('diffContent为空', empty($IL3gB)); goto Iwxiu; auq5g: BizException::throwsIf('调用 php artisan modstart:module-install-all 失败', 0 != $rx99h); goto a1z4O; v8eI6: BizException::throwsIf('package不存在', !file_exists($qWHC7)); goto fVWKu; lAMIW: try { $rx99h = Artisan::call('migrate'); } catch (\Exception $se7TW) { $rx99h = -1; } goto qP0pf; xEqvp: FileUtil::safeCleanLocalTemp($JhjhO); goto kbyqv; Oxxtn: } }