<?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($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 HQogx; VF9Pa: return $Gs3Xd['data']; goto W0oYK; HQogx: $Gs3Xd = self::baseRequest('/api/app/latest', array('app' => AppConstant::APP, 'version' => AppConstant::VERSION)); goto J6BJg; J6BJg: BizException::throwsIfResponseError($Gs3Xd); goto VF9Pa; W0oYK: } public static function downloadPackage($h7611, $E1Gi8, $rmv8P, $iGHvN) { goto F0o0S; OQis5: BizException::throwsIf('文件MD5校验失败', md5_file($YDT3k) != $qWRiP); goto REAq1; C0BjU: BizException::throwsIfResponseError($Gs3Xd); goto zNdY0; F0o0S: $Gs3Xd = self::baseRequest('/api/app/download_package', array('app' => $E1Gi8, 'fromVersion' => $rmv8P, 'toVersion' => $iGHvN), $h7611); goto C0BjU; nPGdF: BizException::throwsIfEmpty('安装包获取失败', $smBDO); goto stVwf; stVwf: $YDT3k = FileUtil::generateLocalTempPath('zip'); goto DyTzc; swoHA: $qWRiP = $Gs3Xd['data']['packageMd5']; goto AdN7v; aVsIr: file_put_contents($DNs9z, $fZgZn); goto qIoMr; AdN7v: $fZgZn = $Gs3Xd['data']['diffContent']; goto dx1nb; dx1nb: $smBDO = CurlUtil::getRaw($xAW3P); goto nPGdF; REAq1: $DNs9z = FileUtil::generateLocalTempPath('json'); goto aVsIr; zNdY0: $xAW3P = $Gs3Xd['data']['package']; goto swoHA; qIoMr: return Response::generateSuccessData(array('diffContentFile' => $DNs9z, 'package' => $YDT3k, 'packageSize' => filesize($YDT3k))); goto j3mjb; DyTzc: file_put_contents($YDT3k, $smBDO); goto OQis5; j3mjb: } public static function upgradePackage($xAW3P, $DNs9z) { goto PUswO; dsPC3: try { $N3esS = Artisan::call('migrate'); } catch (\Exception $hSVcc) { $N3esS = -1; } goto nj03X; PUswO: BizException::throwsIf('package不存在', !file_exists($xAW3P)); goto jr58K; GpSju: BizException::throwsIf('diffContent为空', empty($fZgZn)); goto N0L1y; OV20f: ModStart::clearCache(); goto dsPC3; jr58K: BizException::throwsIf('diffContentFile不存在', !file_exists($DNs9z)); goto j_64E; j_64E: $fZgZn = @json_decode(file_get_contents($DNs9z), true); goto GpSju; ZeQuD: $yUlGm = new Zipper(); goto guCZ1; KHJG3: if (!empty($fZgZn['add'])) { goto RICsW; L0V1o: foreach ($fZgZn['add'] as $x_XbT) { goto LS5f7; gFdEt: FileUtil::write(base_path($x_XbT), $eTwx_); goto RXZKD; LS5f7: $eTwx_ = $yUlGm->getFileContent($x_XbT); goto gFdEt; RXZKD: $zkKO0[] = "> {$x_XbT}"; goto YpIBG; YpIBG: } goto aOVzT; aOVzT: $zkKO0[] = ''; goto BvUck; RICsW: $zkKO0[] = '新增文件：'; goto L0V1o; BvUck: } goto VE2EN; guCZ1: $yUlGm->make($xAW3P); goto m3i3D; VE2EN: if (!empty($fZgZn['update'])) { goto CYxw1; SM8V9: $zkKO0[] = ''; goto HmHKO; CYxw1: $zkKO0[] = '修改文件：'; goto RltQ8; RltQ8: foreach ($fZgZn['update'] as $x_XbT) { goto EdTfM; bBdAv: FileUtil::write(base_path($x_XbT), $eTwx_); goto bXzh6; EdTfM: $eTwx_ = $yUlGm->getFileContent($x_XbT); goto bBdAv; bXzh6: $zkKO0[] = "> {$x_XbT}"; goto zQ0re; zQ0re: } goto SM8V9; HmHKO: } goto hL7q9; io1Aw: FileUtil::safeCleanLocalTemp($DNs9z); goto mK9BD; Qxhq7: $yUlGm->close(); goto OV20f; kC15i: try { $N3esS = Artisan::call('modstart:module-install-all'); } catch (\Exception $hSVcc) { $N3esS = -1; } goto Mpy1V; bo5Jt: if (!empty($fZgZn['update'])) { $PzMnA = array_merge($PzMnA, $fZgZn['update']); } goto tSLVH; tSLVH: $Gs3Xd = FileUtil::filePathWritableCheck($PzMnA); goto ASfiH; ASfiH: BizException::throwsIfResponseError($Gs3Xd); goto ZeQuD; oLcrs: FileUtil::safeCleanLocalTemp($xAW3P); goto io1Aw; N0L1y: $PzMnA = array(); goto EWlL8; hL7q9: if (!empty($fZgZn['delete'])) { goto Pb1xO; iDfS0: $zkKO0[] = ''; goto i8QzW; Pb1xO: $zkKO0[] = '删除文件：'; goto ECtrR; ECtrR: foreach ($fZgZn['delete'] as $x_XbT) { if (file_exists($Kcl6E = base_path($x_XbT))) { @unlink($Kcl6E); $zkKO0[] = "> {$x_XbT}"; } } goto iDfS0; i8QzW: } goto Qxhq7; nj03X: BizException::throwsIf('调用 php artisan migrate 失败', 0 != $N3esS); goto kC15i; Mpy1V: BizException::throwsIf('调用 php artisan modstart:module-install-all 失败', 0 != $N3esS); goto oLcrs; EWlL8: if (!empty($fZgZn['add'])) { $PzMnA = array_merge($PzMnA, $fZgZn['add']); } goto bo5Jt; m3i3D: $zkKO0 = array(); goto KHJG3; mK9BD: return Response::generateSuccessData(array('logs' => $zkKO0)); goto pSTnb; pSTnb: } }