<?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($Mh8Wv, $q62oK = array(), $hTSDI = null) { return CurlUtil::postJSONBody(self::REMOTE_BASE . $Mh8Wv, $q62oK, array('header' => array('api-token' => $hTSDI, 'X-Requested-With' => 'XMLHttpRequest'))); } public static function latest() { goto RHaBW; SA3_c: return $oHb9_['data']; goto iZi1f; Dsf1k: BizException::throwsIfResponseError($oHb9_); goto SA3_c; RHaBW: $oHb9_ = self::baseRequest('/api/app/latest', array('app' => AppConstant::APP, 'version' => AppConstant::VERSION)); goto Dsf1k; iZi1f: } public static function downloadPackage($hTSDI, $o3M2b, $DH4Pd, $XzQvH) { goto R8fYB; e_qBy: $jveNw = $oHb9_['data']['package']; goto Ehhop; rsnM_: $ie1JD = FileUtil::generateLocalTempPath('zip'); goto RN8S_; gEy37: BizException::throwsIf('文件MD5校验失败', md5_file($ie1JD) != $a9kFA); goto o2DgQ; pIt2W: $yW_uT = $oHb9_['data']['diffContent']; goto Ud2dI; RN8S_: file_put_contents($ie1JD, $q62oK); goto gEy37; yCHGg: BizException::throwsIfEmpty('安装包获取失败', $q62oK); goto rsnM_; R8fYB: $oHb9_ = self::baseRequest('/api/app/download_package', array('app' => $o3M2b, 'fromVersion' => $DH4Pd, 'toVersion' => $XzQvH), $hTSDI); goto olNBg; Ehhop: $a9kFA = $oHb9_['data']['packageMd5']; goto pIt2W; olNBg: BizException::throwsIfResponseError($oHb9_); goto e_qBy; Ud2dI: $q62oK = CurlUtil::getRaw($jveNw); goto yCHGg; mlJjP: file_put_contents($gPtkf, $yW_uT); goto LkRxj; LkRxj: return Response::generateSuccessData(array('diffContentFile' => $gPtkf, 'package' => $ie1JD, 'packageSize' => filesize($ie1JD))); goto Zuys_; o2DgQ: $gPtkf = FileUtil::generateLocalTempPath('json'); goto mlJjP; Zuys_: } public static function upgradePackage($jveNw, $gPtkf) { goto CIcZg; rp_eK: $SMRjI = array(); goto hVLHu; EfLg0: BizException::throwsIf('调用 php artisan migrate 失败', 0 != $SvOVI); goto mvb3e; qB_5v: if (!empty($yW_uT['delete'])) { goto UPJ0Y; iRAb0: foreach ($yW_uT['delete'] as $obXaA) { if (file_exists($r6_O_ = base_path($obXaA))) { @unlink($r6_O_); $SMRjI[] = "> {$obXaA}"; } } goto Cd4Bu; UPJ0Y: $SMRjI[] = '删除文件：'; goto iRAb0; Cd4Bu: $SMRjI[] = ''; goto BxWuD; BxWuD: } goto Exa98; cTITB: $oHb9_ = FileUtil::filePathWritableCheck($rbfkm); goto Du5g4; fvNvu: FileUtil::safeCleanLocalTemp($jveNw); goto zuQAN; CIcZg: BizException::throwsIf('package不存在', !file_exists($jveNw)); goto QkBC0; mvb3e: try { $SvOVI = Artisan::call('modstart:module-install-all'); } catch (\Exception $cknMI) { $SvOVI = -1; } goto bBspx; bBspx: BizException::throwsIf('调用 php artisan modstart:module-install-all 失败', 0 != $SvOVI); goto fvNvu; hVLHu: if (!empty($yW_uT['add'])) { goto r3JEF; wDS2c: $SMRjI[] = ''; goto lfwFm; r3JEF: $SMRjI[] = '新增文件：'; goto gRhSB; gRhSB: foreach ($yW_uT['add'] as $obXaA) { goto uKPrJ; sTYcE: $SMRjI[] = "> {$obXaA}"; goto mKktl; zI9Hu: FileUtil::write(base_path($obXaA), $fKViA); goto sTYcE; uKPrJ: $fKViA = $OoGkc->getFileContent($obXaA); goto zI9Hu; mKktl: } goto wDS2c; lfwFm: } goto bdoct; zuQAN: FileUtil::safeCleanLocalTemp($gPtkf); goto J097k; ysbaA: $rbfkm = array(); goto E8fqm; J097k: return Response::generateSuccessData(array('logs' => $SMRjI)); goto cLXgg; HN1BK: $yW_uT = @json_decode(file_get_contents($gPtkf), true); goto ey5cW; OPGNy: ModStart::clearCache(); goto faoHV; faoHV: try { $SvOVI = Artisan::call('migrate'); } catch (\Exception $cknMI) { $SvOVI = -1; } goto EfLg0; bdoct: if (!empty($yW_uT['update'])) { goto jxVAb; jxVAb: $SMRjI[] = '修改文件：'; goto VKhxa; VKhxa: foreach ($yW_uT['update'] as $obXaA) { goto nvmis; QuIG2: FileUtil::write(base_path($obXaA), $fKViA); goto yWrIp; nvmis: $fKViA = $OoGkc->getFileContent($obXaA); goto QuIG2; yWrIp: $SMRjI[] = "> {$obXaA}"; goto kVU3_; kVU3_: } goto bHlVd; bHlVd: $SMRjI[] = ''; goto jIL7x; jIL7x: } goto qB_5v; ey5cW: BizException::throwsIf('diffContent为空', empty($yW_uT)); goto ysbaA; pZiHs: $OoGkc->make($jveNw); goto rp_eK; E8fqm: if (!empty($yW_uT['add'])) { $rbfkm = array_merge($rbfkm, $yW_uT['add']); } goto Cdejd; A15ll: $OoGkc = new Zipper(); goto pZiHs; QkBC0: BizException::throwsIf('diffContentFile不存在', !file_exists($gPtkf)); goto HN1BK; Cdejd: if (!empty($yW_uT['update'])) { $rbfkm = array_merge($rbfkm, $yW_uT['update']); } goto cTITB; Du5g4: BizException::throwsIfResponseError($oHb9_); goto A15ll; Exa98: $OoGkc->close(); goto OPGNy; cLXgg: } }