<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\AdminManager\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://modstart.com'; private static function baseRequest($i8iu_, $GpXwG = array(), $cUrpz = null) { return CurlUtil::postJSONBody(self::REMOTE_BASE . $i8iu_, $GpXwG, array('header' => array('api-token' => $cUrpz, 'X-Requested-With' => 'XMLHttpRequest'))); } public static function latest() { goto LK6lz; LK6lz: $gMg9x = self::baseRequest('/api/app/latest', array('app' => AppConstant::APP, 'version' => AppConstant::VERSION)); goto At48u; N6lnk: return $gMg9x['data']; goto HmYf_; At48u: BizException::throwsIfResponseError($gMg9x); goto N6lnk; HmYf_: } public static function downloadPackage($cUrpz, $WFzTb, $hAY2O, $U1vNQ) { goto GOmdu; JHXb3: BizException::throwsIfEmpty('安装包获取失败', $GpXwG); goto ZVH2l; ZVH2l: $Yjknd = FileUtil::generateLocalTempPath('zip'); goto eVnyV; cLbaH: BizException::throwsIf('文件MD5校验失败', md5_file($Yjknd) != $bQ1Td); goto qeZET; fpkyP: $MZdfD = $gMg9x['data']['package']; goto FTHPG; FTHPG: $bQ1Td = $gMg9x['data']['packageMd5']; goto hxKZC; eVnyV: file_put_contents($Yjknd, $GpXwG); goto cLbaH; y0FjO: $GpXwG = CurlUtil::getRaw($MZdfD); goto JHXb3; qeZET: $pboir = FileUtil::generateLocalTempPath('json'); goto pOGqY; hxKZC: $rFPP6 = $gMg9x['data']['diffContent']; goto y0FjO; G29ot: BizException::throwsIfResponseError($gMg9x); goto fpkyP; GOmdu: $gMg9x = self::baseRequest('/api/app/download_package', array('app' => $WFzTb, 'fromVersion' => $hAY2O, 'toVersion' => $U1vNQ), $cUrpz); goto G29ot; YSKKu: return Response::generateSuccessData(array('diffContentFile' => $pboir, 'package' => $Yjknd, 'packageSize' => filesize($Yjknd))); goto uBZN6; pOGqY: file_put_contents($pboir, $rFPP6); goto YSKKu; uBZN6: } public static function upgradePackage($MZdfD, $pboir) { goto A0Sol; zg6Ov: $sMu5I = new Zipper(); goto dcg0M; nPv5r: $sMu5I->close(); goto P6ol9; artq5: BizException::throwsIf('调用 php artisan migrate 失败', 0 != $yTeE1); goto Z7fR4; d174H: BizException::throwsIf('调用 php artisan modstart:module-install-all 失败', 0 != $yTeE1); goto fIX40; QgjSI: if (!empty($rFPP6['update'])) { goto nYe26; nqKLr: $bQ5pn[] = ''; goto CqIL1; nYe26: $bQ5pn[] = '修改文件：'; goto rG0B5; rG0B5: foreach ($rFPP6['update'] as $wjJPd) { goto k7Bpo; DMQPu: $bQ5pn[] = "> {$wjJPd}"; goto OB2hS; ti6Zy: FileUtil::write(base_path($wjJPd), $Ral1i); goto DMQPu; k7Bpo: $Ral1i = $sMu5I->getFileContent($wjJPd); goto ti6Zy; OB2hS: } goto nqKLr; CqIL1: } goto gLfDr; L2_UD: if (!empty($rFPP6['add'])) { $Gqf62 = array_merge($Gqf62, $rFPP6['add']); } goto Q0QQN; A0Sol: BizException::throwsIf('package不存在', !file_exists($MZdfD)); goto FtxGw; RWwkY: $bQ5pn = array(); goto eR3ie; DDWPu: try { $yTeE1 = Artisan::call('migrate'); } catch (\Exception $re7gC) { $yTeE1 = -1; } goto artq5; d3NYb: FileUtil::safeCleanLocalTemp($pboir); goto jPaH0; eR3ie: if (!empty($rFPP6['add'])) { goto uEmOr; WGS1J: foreach ($rFPP6['add'] as $wjJPd) { goto Gmyd8; i_MlQ: FileUtil::write(base_path($wjJPd), $Ral1i); goto yypaX; Gmyd8: $Ral1i = $sMu5I->getFileContent($wjJPd); goto i_MlQ; yypaX: $bQ5pn[] = "> {$wjJPd}"; goto vSIh2; vSIh2: } goto WSHIV; uEmOr: $bQ5pn[] = '新增文件：'; goto WGS1J; WSHIV: $bQ5pn[] = ''; goto fiXxx; fiXxx: } goto QgjSI; vENzk: $Gqf62 = array(); goto L2_UD; gLfDr: if (!empty($rFPP6['delete'])) { goto MHCt4; O4DWi: foreach ($rFPP6['delete'] as $wjJPd) { if (file_exists($sUL93 = base_path($wjJPd))) { @unlink($sUL93); $bQ5pn[] = "> {$wjJPd}"; } } goto Riuhp; Riuhp: $bQ5pn[] = ''; goto U683U; MHCt4: $bQ5pn[] = '删除文件：'; goto O4DWi; U683U: } goto nPv5r; FtxGw: BizException::throwsIf('diffContentFile不存在', !file_exists($pboir)); goto rl6ej; P6ol9: ModStart::clearCache(); goto DDWPu; NdbgJ: BizException::throwsIf('diffContent为空', empty($rFPP6)); goto vENzk; Q0QQN: if (!empty($rFPP6['update'])) { $Gqf62 = array_merge($Gqf62, $rFPP6['update']); } goto cQMFs; rl6ej: $rFPP6 = @json_decode(file_get_contents($pboir), true); goto NdbgJ; b46I9: BizException::throwsIfResponseError($gMg9x); goto zg6Ov; Z7fR4: $yTeE1 = Artisan::call('modstart:module-install-all'); goto d174H; fIX40: FileUtil::safeCleanLocalTemp($MZdfD); goto d3NYb; jPaH0: return Response::generateSuccessData(array('logs' => $bQ5pn)); goto eFEdc; dcg0M: $sMu5I->make($MZdfD); goto RWwkY; cQMFs: $gMg9x = FileUtil::filePathWritableCheck($Gqf62); goto b46I9; eFEdc: } }