<?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($EKog2, $xJzrK = array(), $GA_R3 = null) { return CurlUtil::postJSONBody(self::REMOTE_BASE . $EKog2, $xJzrK, array('header' => array('api-token' => $GA_R3, 'X-Requested-With' => 'XMLHttpRequest'))); } public static function latest() { goto nw0kj; bJQc8: BizException::throwsIfResponseError($yCUD1); goto DMD4b; nw0kj: $yCUD1 = self::baseRequest('/api/app/latest', array('app' => AppConstant::APP, 'version' => AppConstant::VERSION)); goto bJQc8; DMD4b: return $yCUD1['data']; goto V25yy; V25yy: } public static function downloadPackage($GA_R3, $NMaTV, $g_V3S, $Wgcnm) { goto AvcBh; cXDL0: BizException::throwsIfResponseError($yCUD1); goto r_l_A; yzXJQ: $mQcOS = FileUtil::generateLocalTempPath('zip'); goto nAYAA; Czx2A: BizException::throwsIfEmpty('安装包获取失败', $xJzrK); goto yzXJQ; AvcBh: $yCUD1 = self::baseRequest('/api/app/download_package', array('app' => $NMaTV, 'fromVersion' => $g_V3S, 'toVersion' => $Wgcnm), $GA_R3); goto cXDL0; EulB5: $xJzrK = CurlUtil::getRaw($HDfwB); goto Czx2A; pIqY6: return Response::generateSuccessData(array('diffContentFile' => $TiNKC, 'package' => $mQcOS, 'packageSize' => filesize($mQcOS))); goto QWNBb; nAYAA: file_put_contents($mQcOS, $xJzrK); goto HVA15; HVA15: BizException::throwsIf('文件MD5校验失败', md5_file($mQcOS) != $Yn3XW); goto mHYUb; mHYUb: $TiNKC = FileUtil::generateLocalTempPath('json'); goto i69FR; sbmX3: $Yn3XW = $yCUD1['data']['packageMd5']; goto Ecydz; r_l_A: $HDfwB = $yCUD1['data']['package']; goto sbmX3; i69FR: file_put_contents($TiNKC, $vddDn); goto pIqY6; Ecydz: $vddDn = $yCUD1['data']['diffContent']; goto EulB5; QWNBb: } public static function upgradePackage($HDfwB, $TiNKC) { goto NiVb1; e6zdh: $ac7RJ->close(); goto z9cNP; qbBS1: $vddDn = @json_decode(file_get_contents($TiNKC), true); goto INJt4; NiVb1: BizException::throwsIf('package不存在', !file_exists($HDfwB)); goto FFlee; LW1nl: $eVOe0 = array(); goto DR0Yg; mQxR0: $ac7RJ->make($HDfwB); goto CwUbh; z9cNP: ModStart::clearCache(); goto DP0ds; XkVki: BizException::throwsIf('调用 php artisan modstart:module-install-all 失败', 0 != $LAwgR); goto l8T1v; lYYNd: BizException::throwsIf('调用 php artisan migrate 失败', 0 != $LAwgR); goto yPQvh; CwUbh: $gS7dY = array(); goto zogmC; DP0ds: try { $LAwgR = Artisan::call('migrate'); } catch (\Exception $Q19lV) { $LAwgR = -1; } goto lYYNd; DR0Yg: if (!empty($vddDn['add'])) { $eVOe0 = array_merge($eVOe0, $vddDn['add']); } goto EdjyM; EdjyM: if (!empty($vddDn['update'])) { $eVOe0 = array_merge($eVOe0, $vddDn['update']); } goto vQ2XJ; Sb4X9: $ac7RJ = new Zipper(); goto mQxR0; xCKY1: if (!empty($vddDn['update'])) { goto MvF6g; qWHmm: foreach ($vddDn['update'] as $rZJie) { goto cIpXQ; cIpXQ: $ZA40Q = $ac7RJ->getFileContent($rZJie); goto diAXM; diAXM: FileUtil::write(base_path($rZJie), $ZA40Q); goto rkeNN; rkeNN: $gS7dY[] = "> {$rZJie}"; goto CgHkn; CgHkn: } goto y6uto; MvF6g: $gS7dY[] = '修改文件：'; goto qWHmm; y6uto: $gS7dY[] = ''; goto aWiWY; aWiWY: } goto Jj_ut; INJt4: BizException::throwsIf('diffContent为空', empty($vddDn)); goto LW1nl; Jj_ut: if (!empty($vddDn['delete'])) { goto iJrKX; CF0Ya: $gS7dY[] = ''; goto Jp0GH; iJrKX: $gS7dY[] = '删除文件：'; goto l7xKu; l7xKu: foreach ($vddDn['delete'] as $rZJie) { if (file_exists($v1O63 = base_path($rZJie))) { @unlink($v1O63); $gS7dY[] = "> {$rZJie}"; } } goto CF0Ya; Jp0GH: } goto e6zdh; vQ2XJ: $yCUD1 = FileUtil::filePathWritableCheck($eVOe0); goto DFs55; Ra1mA: return Response::generateSuccessData(array('logs' => $gS7dY)); goto tzHmU; NAhnL: FileUtil::safeCleanLocalTemp($TiNKC); goto Ra1mA; l8T1v: FileUtil::safeCleanLocalTemp($HDfwB); goto NAhnL; FFlee: BizException::throwsIf('diffContentFile不存在', !file_exists($TiNKC)); goto qbBS1; DFs55: BizException::throwsIfResponseError($yCUD1); goto Sb4X9; yPQvh: try { $LAwgR = Artisan::call('modstart:module-install-all'); } catch (\Exception $Q19lV) { $LAwgR = -1; } goto XkVki; zogmC: if (!empty($vddDn['add'])) { goto G3GGH; G3GGH: $gS7dY[] = '新增文件：'; goto EhTY3; z8gkg: $gS7dY[] = ''; goto nOGQa; EhTY3: foreach ($vddDn['add'] as $rZJie) { goto jqGiS; se1R8: $gS7dY[] = "> {$rZJie}"; goto zqwVi; jqGiS: $ZA40Q = $ac7RJ->getFileContent($rZJie); goto VrhT6; VrhT6: FileUtil::write(base_path($rZJie), $ZA40Q); goto se1R8; zqwVi: } goto z8gkg; nOGQa: } goto xCKY1; tzHmU: } }