<?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($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 GrAFm; GrAFm: $rhLXE = self::baseRequest('/api/app/latest', array('app' => AppConstant::APP, 'version' => AppConstant::VERSION)); goto Bzv8G; Bzv8G: BizException::throwsIfResponseError($rhLXE); goto uFjbs; uFjbs: return $rhLXE['data']; goto rq0nQ; rq0nQ: } public static function downloadPackage($MMmFM, $IXDHb, $aYuf7, $vodoI) { goto LnUfh; mjYbb: BizException::throwsIf('文件MD5校验失败', md5_file($tHW_I) != $MtKsl); goto cK5xs; LnUfh: $rhLXE = self::baseRequest('/api/app/download_package', array('app' => $IXDHb, 'fromVersion' => $aYuf7, 'toVersion' => $vodoI), $MMmFM); goto cWFgy; ZvGiJ: BizException::throwsIfEmpty('安装包获取失败', $avcnU); goto gwyHx; cK5xs: $kO40W = FileUtil::generateLocalTempPath('json'); goto q32IX; vNlCX: file_put_contents($tHW_I, $avcnU); goto mjYbb; z0QGT: $jenmr = $rhLXE['data']['diffContent']; goto W5yBY; W5yBY: $avcnU = CurlUtil::getRaw($pd0Ai); goto ZvGiJ; q32IX: file_put_contents($kO40W, $jenmr); goto EC1RC; EC1RC: return Response::generateSuccessData(array('diffContentFile' => $kO40W, 'package' => $tHW_I, 'packageSize' => filesize($tHW_I))); goto gIm3O; gbMPO: $pd0Ai = $rhLXE['data']['package']; goto r34Hn; cWFgy: BizException::throwsIfResponseError($rhLXE); goto gbMPO; r34Hn: $MtKsl = $rhLXE['data']['packageMd5']; goto z0QGT; gwyHx: $tHW_I = FileUtil::generateLocalTempPath('zip'); goto vNlCX; gIm3O: } public static function upgradePackage($pd0Ai, $kO40W) { goto CWPdG; dytd3: BizException::throwsIf('diffContentFile不存在', !file_exists($kO40W)); goto rSSAu; W_3jk: $hd3MY = new Zipper(); goto diqh2; roXm1: try { $Jk1lG = Artisan::call('modstart:module-install-all'); } catch (\Exception $qoTNG) { $Jk1lG = -1; } goto aFFR5; Jkyu5: BizException::throwsIf('调用 php artisan migrate 失败', 0 != $Jk1lG); goto roXm1; s8VDY: if (!empty($jenmr['delete'])) { goto XeMkm; tedT2: $G2Zzj[] = ''; goto vrkvX; XeMkm: $G2Zzj[] = '删除文件：'; goto TLnsN; TLnsN: foreach ($jenmr['delete'] as $bHKYd) { if (file_exists($OCvfG = base_path($bHKYd))) { @unlink($OCvfG); $G2Zzj[] = "> {$bHKYd}"; } } goto tedT2; vrkvX: } goto mHqly; qnb6R: return Response::generateSuccessData(array('logs' => $G2Zzj)); goto kW_wV; rSSAu: $jenmr = @json_decode(file_get_contents($kO40W), true); goto ubWVK; W8T1U: if (!empty($jenmr['add'])) { $H2FF9 = array_merge($H2FF9, $jenmr['add']); } goto ikvQJ; iYwh1: if (!empty($jenmr['add'])) { goto JrWjz; JrWjz: $G2Zzj[] = '新增文件：'; goto F523m; PJr34: $G2Zzj[] = ''; goto koRid; F523m: foreach ($jenmr['add'] as $bHKYd) { goto CuTEv; SOSnc: FileUtil::write(base_path($bHKYd), $ybjC4); goto Ss2D7; Ss2D7: $G2Zzj[] = "> {$bHKYd}"; goto cTkCr; CuTEv: $ybjC4 = $hd3MY->getFileContent($bHKYd); goto SOSnc; cTkCr: } goto PJr34; koRid: } goto lOIoC; r2GV4: FileUtil::safeCleanLocalTemp($pd0Ai); goto OXoWA; diqh2: $hd3MY->make($pd0Ai); goto vCwOb; vCwOb: $G2Zzj = array(); goto iYwh1; CWPdG: BizException::throwsIf('package不存在', !file_exists($pd0Ai)); goto dytd3; JvN4Z: $H2FF9 = array(); goto W8T1U; R_bTV: BizException::throwsIfResponseError($rhLXE); goto W_3jk; aFFR5: BizException::throwsIf('调用 php artisan modstart:module-install-all 失败', 0 != $Jk1lG); goto r2GV4; AX5K0: try { $Jk1lG = Artisan::call('migrate'); } catch (\Exception $qoTNG) { $Jk1lG = -1; } goto Jkyu5; ubWVK: BizException::throwsIf('diffContent为空', empty($jenmr)); goto JvN4Z; mHqly: $hd3MY->close(); goto jGnEe; lOIoC: if (!empty($jenmr['update'])) { goto qoQEs; qoQEs: $G2Zzj[] = '修改文件：'; goto PoZfJ; h8Yig: $G2Zzj[] = ''; goto hEb8w; PoZfJ: foreach ($jenmr['update'] as $bHKYd) { goto LHd9l; osyDT: $G2Zzj[] = "> {$bHKYd}"; goto M5ClR; fMER5: FileUtil::write(base_path($bHKYd), $ybjC4); goto osyDT; LHd9l: $ybjC4 = $hd3MY->getFileContent($bHKYd); goto fMER5; M5ClR: } goto h8Yig; hEb8w: } goto s8VDY; OXoWA: FileUtil::safeCleanLocalTemp($kO40W); goto qnb6R; pe0w3: $rhLXE = FileUtil::filePathWritableCheck($H2FF9); goto R_bTV; ikvQJ: if (!empty($jenmr['update'])) { $H2FF9 = array_merge($H2FF9, $jenmr['update']); } goto pe0w3; jGnEe: ModStart::clearCache(); goto AX5K0; kW_wV: } }