<?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($pbQhK, $U8wjN = array(), $Jqi9c = null) { return CurlUtil::postJSONBody(self::REMOTE_BASE . $pbQhK, $U8wjN, array('header' => array('api-token' => $Jqi9c, 'X-Requested-With' => 'XMLHttpRequest'))); } public static function latest() { goto K397c; WM7_B: return $Tbn6c['data']; goto TI9ND; K397c: $Tbn6c = self::baseRequest('/api/app/latest', array('app' => AppConstant::APP, 'version' => AppConstant::VERSION)); goto h1Ljo; h1Ljo: BizException::throwsIfResponseError($Tbn6c); goto WM7_B; TI9ND: } public static function downloadPackage($Jqi9c, $CEGfq, $zgdNX, $oOn5l) { goto o2fBU; NNJUs: file_put_contents($poSyi, $U8wjN); goto Gdk5a; iQuRD: $poSyi = FileUtil::generateLocalTempPath('zip'); goto NNJUs; Gdk5a: BizException::throwsIf('文件MD5校验失败', md5_file($poSyi) != $lRtMD); goto XHsCo; XHsCo: $EiUju = FileUtil::generateLocalTempPath('json'); goto ffbDy; beUQm: BizException::throwsIfResponseError($Tbn6c); goto CI4yF; oReZI: $lRtMD = $Tbn6c['data']['packageMd5']; goto GP2gy; nCkhw: $U8wjN = CurlUtil::getRaw($owryS); goto VpfcQ; GP2gy: $gFXZl = $Tbn6c['data']['diffContent']; goto nCkhw; owWzw: return Response::generateSuccessData(array('diffContentFile' => $EiUju, 'package' => $poSyi, 'packageSize' => filesize($poSyi))); goto BWxfD; ffbDy: file_put_contents($EiUju, $gFXZl); goto owWzw; CI4yF: $owryS = $Tbn6c['data']['package']; goto oReZI; o2fBU: $Tbn6c = self::baseRequest('/api/app/download_package', array('app' => $CEGfq, 'fromVersion' => $zgdNX, 'toVersion' => $oOn5l), $Jqi9c); goto beUQm; VpfcQ: BizException::throwsIfEmpty('安装包获取失败', $U8wjN); goto iQuRD; BWxfD: } public static function upgradePackage($owryS, $EiUju) { goto NR3M9; uGmzh: if (!empty($gFXZl['add'])) { $JzQME = array_merge($JzQME, $gFXZl['add']); } goto PiAOm; iOMXt: try { $NOH_v = Artisan::call('migrate'); } catch (\Exception $ZemkG) { $NOH_v = -1; } goto TCopw; hkoNa: BizException::throwsIf('diffContent为空', empty($gFXZl)); goto zk3Hw; NR3M9: BizException::throwsIf('package不存在', !file_exists($owryS)); goto WHKhE; i6Zgk: ModStart::clearCache(); goto iOMXt; GCxjd: FileUtil::safeCleanLocalTemp($owryS); goto Od9qH; THbnS: BizException::throwsIf('调用 php artisan modstart:module-install-all 失败', 0 != $NOH_v); goto GCxjd; Od9qH: FileUtil::safeCleanLocalTemp($EiUju); goto DnRt3; HU1kx: try { $NOH_v = Artisan::call('modstart:module-install-all'); } catch (\Exception $ZemkG) { $NOH_v = -1; } goto THbnS; TCopw: BizException::throwsIf('调用 php artisan migrate 失败', 0 != $NOH_v); goto HU1kx; SyysP: BizException::throwsIfResponseError($Tbn6c); goto Orn27; XA0ex: if (!empty($gFXZl['update'])) { goto zncA8; QRNXK: $QiA1t[] = ''; goto xoQdO; zncA8: $QiA1t[] = '修改文件：'; goto fbWnn; fbWnn: foreach ($gFXZl['update'] as $dG73t) { goto gU46z; USEkL: FileUtil::write(base_path($dG73t), $n16LT); goto JNgtl; JNgtl: $QiA1t[] = "> {$dG73t}"; goto QpXfo; gU46z: $n16LT = $ZPduJ->getFileContent($dG73t); goto USEkL; QpXfo: } goto QRNXK; xoQdO: } goto Mixrg; ALO1T: $Tbn6c = FileUtil::filePathWritableCheck($JzQME); goto SyysP; zk3Hw: $JzQME = array(); goto uGmzh; xiU4g: $QiA1t = array(); goto Jo51d; mnM8U: $gFXZl = @json_decode(file_get_contents($EiUju), true); goto hkoNa; WHKhE: BizException::throwsIf('diffContentFile不存在', !file_exists($EiUju)); goto mnM8U; DnRt3: return Response::generateSuccessData(array('logs' => $QiA1t)); goto j27dq; seoJk: $ZPduJ->close(); goto i6Zgk; HEaTg: $ZPduJ->make($owryS); goto xiU4g; PiAOm: if (!empty($gFXZl['update'])) { $JzQME = array_merge($JzQME, $gFXZl['update']); } goto ALO1T; Mixrg: if (!empty($gFXZl['delete'])) { goto CRleH; Q8Do7: $QiA1t[] = ''; goto Gl_oV; CRleH: $QiA1t[] = '删除文件：'; goto eN3jk; eN3jk: foreach ($gFXZl['delete'] as $dG73t) { if (file_exists($A1G3_ = base_path($dG73t))) { @unlink($A1G3_); $QiA1t[] = "> {$dG73t}"; } } goto Q8Do7; Gl_oV: } goto seoJk; Orn27: $ZPduJ = new Zipper(); goto HEaTg; Jo51d: if (!empty($gFXZl['add'])) { goto q39qZ; q39qZ: $QiA1t[] = '新增文件：'; goto PRMRa; bgPBW: $QiA1t[] = ''; goto zXxQC; PRMRa: foreach ($gFXZl['add'] as $dG73t) { goto ni0vC; sTx2i: FileUtil::write(base_path($dG73t), $n16LT); goto xMCPj; ni0vC: $n16LT = $ZPduJ->getFileContent($dG73t); goto sTx2i; xMCPj: $QiA1t[] = "> {$dG73t}"; goto DYLaZ; DYLaZ: } goto bgPBW; zXxQC: } goto XA0ex; j27dq: } }