<?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($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 eDpi1; Zwr5a: return $Tbn6c['data']; goto J8Ln7; iZbbt: BizException::throwsIfResponseError($Tbn6c); goto Zwr5a; eDpi1: $Tbn6c = self::baseRequest('/api/app/latest', array('app' => AppConstant::APP, 'version' => AppConstant::VERSION)); goto iZbbt; J8Ln7: } public static function downloadPackage($Jqi9c, $CEGfq, $zgdNX, $oOn5l) { goto naXfT; rI6TY: BizException::throwsIf('文件MD5校验失败', md5_file($poSyi) != $lRtMD); goto vGQEh; ECyQ7: $owryS = $Tbn6c['data']['package']; goto Lonj7; naXfT: $Tbn6c = self::baseRequest('/api/app/download_package', array('app' => $CEGfq, 'fromVersion' => $zgdNX, 'toVersion' => $oOn5l), $Jqi9c); goto V7mn3; IVfXv: BizException::throwsIfEmpty('安装包获取失败', $U8wjN); goto fv3uJ; eEMAg: file_put_contents($poSyi, $U8wjN); goto rI6TY; kxJH2: return Response::generateSuccessData(array('diffContentFile' => $EiUju, 'package' => $poSyi, 'packageSize' => filesize($poSyi))); goto KCKLD; wuIlw: file_put_contents($EiUju, $gFXZl); goto kxJH2; N461p: $U8wjN = CurlUtil::getRaw($owryS); goto IVfXv; vGQEh: $EiUju = FileUtil::generateLocalTempPath('json'); goto wuIlw; aUBB8: $gFXZl = $Tbn6c['data']['diffContent']; goto N461p; V7mn3: BizException::throwsIfResponseError($Tbn6c); goto ECyQ7; Lonj7: $lRtMD = $Tbn6c['data']['packageMd5']; goto aUBB8; fv3uJ: $poSyi = FileUtil::generateLocalTempPath('zip'); goto eEMAg; KCKLD: } public static function upgradePackage($owryS, $EiUju) { goto Vbi3K; pBFVq: try { $NOH_v = Artisan::call('migrate'); } catch (\Exception $ZemkG) { $NOH_v = -1; } goto fRpwT; lw959: FileUtil::safeCleanLocalTemp($owryS); goto pC4PA; eG3lK: return Response::generateSuccessData(array('logs' => $QiA1t)); goto GfCt3; dfZzr: $ZPduJ->close(); goto Yz_WS; Lb2NP: $Tbn6c = FileUtil::filePathWritableCheck($JzQME); goto n2IbK; Vbi3K: BizException::throwsIf('package不存在', !file_exists($owryS)); goto KDiTa; X3YBZ: BizException::throwsIf('调用 php artisan modstart:module-install-all 失败', 0 != $NOH_v); goto lw959; lbKGE: $gFXZl = @json_decode(file_get_contents($EiUju), true); goto TOl96; G6nKT: $NOH_v = Artisan::call('modstart:module-install-all'); goto X3YBZ; Yz_WS: ModStart::clearCache(); goto pBFVq; nDmR4: if (!empty($gFXZl['update'])) { goto dZNP0; kJgoh: foreach ($gFXZl['update'] as $dG73t) { goto cs8Ku; cs8Ku: $n16LT = $ZPduJ->getFileContent($dG73t); goto cSOg5; cSOg5: FileUtil::write(base_path($dG73t), $n16LT); goto dkNrn; dkNrn: $QiA1t[] = "> {$dG73t}"; goto FiR75; FiR75: } goto W3FM2; W3FM2: $QiA1t[] = ''; goto sF0me; dZNP0: $QiA1t[] = '修改文件：'; goto kJgoh; sF0me: } goto W4OPs; WrO33: $ZPduJ = new Zipper(); goto cp1Se; W4OPs: if (!empty($gFXZl['delete'])) { goto QwmPX; N2QCt: $QiA1t[] = ''; goto KMcqo; Kqafg: foreach ($gFXZl['delete'] as $dG73t) { if (file_exists($A1G3_ = base_path($dG73t))) { @unlink($A1G3_); $QiA1t[] = "> {$dG73t}"; } } goto N2QCt; QwmPX: $QiA1t[] = '删除文件：'; goto Kqafg; KMcqo: } goto dfZzr; fRpwT: BizException::throwsIf('调用 php artisan migrate 失败', 0 != $NOH_v); goto G6nKT; KDiTa: BizException::throwsIf('diffContentFile不存在', !file_exists($EiUju)); goto lbKGE; n2IbK: BizException::throwsIfResponseError($Tbn6c); goto WrO33; TOl96: BizException::throwsIf('diffContent为空', empty($gFXZl)); goto zrbVn; JBGzx: if (!empty($gFXZl['add'])) { $JzQME = array_merge($JzQME, $gFXZl['add']); } goto g0l2f; T9xxa: if (!empty($gFXZl['add'])) { goto varDw; aYZhP: $QiA1t[] = ''; goto P2knw; sfhIa: foreach ($gFXZl['add'] as $dG73t) { goto vLEmg; XRebj: $QiA1t[] = "> {$dG73t}"; goto yAtr6; hJ_Fl: FileUtil::write(base_path($dG73t), $n16LT); goto XRebj; vLEmg: $n16LT = $ZPduJ->getFileContent($dG73t); goto hJ_Fl; yAtr6: } goto aYZhP; varDw: $QiA1t[] = '新增文件：'; goto sfhIa; P2knw: } goto nDmR4; zrbVn: $JzQME = array(); goto JBGzx; g0l2f: if (!empty($gFXZl['update'])) { $JzQME = array_merge($JzQME, $gFXZl['update']); } goto Lb2NP; cp1Se: $ZPduJ->make($owryS); goto apMqH; apMqH: $QiA1t = array(); goto T9xxa; pC4PA: FileUtil::safeCleanLocalTemp($EiUju); goto eG3lK; GfCt3: } }