<?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($dXFTb, $cwaKT = array(), $ufeje = null) { return CurlUtil::postJSONBody(self::REMOTE_BASE . $dXFTb, $cwaKT, array('header' => array('api-token' => $ufeje, 'X-Requested-With' => 'XMLHttpRequest'))); } public static function latest() { goto w_g0l; Wokvi: return $ZrjxR['data']; goto VpP6T; sbua7: BizException::throwsIfResponseError($ZrjxR); goto Wokvi; w_g0l: $ZrjxR = self::baseRequest('/api/app/latest', array('app' => AppConstant::APP, 'version' => AppConstant::VERSION)); goto sbua7; VpP6T: } public static function downloadPackage($ufeje, $WXVE3, $QUpeI, $GPX1G) { goto Tvi6w; OlbTg: $HX5uI = $ZrjxR['data']['packageMd5']; goto cUB70; kKTfJ: BizException::throwsIfResponseError($ZrjxR); goto BX3Ut; W01Zj: $cwaKT = CurlUtil::getRaw($scQcd); goto v00aO; hsDJu: file_put_contents($dFEzs, $LZDno); goto ETcsR; BX3Ut: $scQcd = $ZrjxR['data']['package']; goto OlbTg; cUB70: $LZDno = $ZrjxR['data']['diffContent']; goto W01Zj; Tvi6w: $ZrjxR = self::baseRequest('/api/app/download_package', array('app' => $WXVE3, 'fromVersion' => $QUpeI, 'toVersion' => $GPX1G), $ufeje); goto kKTfJ; knsec: $dFEzs = FileUtil::generateLocalTempPath('json'); goto hsDJu; nTvHk: $EilHX = FileUtil::generateLocalTempPath('zip'); goto bpK6d; puCz5: BizException::throwsIf('文件MD5校验失败', md5_file($EilHX) != $HX5uI); goto knsec; v00aO: BizException::throwsIfEmpty('安装包获取失败', $cwaKT); goto nTvHk; bpK6d: file_put_contents($EilHX, $cwaKT); goto puCz5; ETcsR: return Response::generateSuccessData(array('diffContentFile' => $dFEzs, 'package' => $EilHX, 'packageSize' => filesize($EilHX))); goto toa5S; toa5S: } public static function upgradePackage($scQcd, $dFEzs) { goto q5hNG; wlDj3: $LZDno = @json_decode(file_get_contents($dFEzs), true); goto lPlHu; gQhSi: if (!empty($LZDno['update'])) { $BYMEd = array_merge($BYMEd, $LZDno['update']); } goto c4n1x; zp455: if (!empty($LZDno['add'])) { $BYMEd = array_merge($BYMEd, $LZDno['add']); } goto gQhSi; T4beI: BizException::throwsIf('调用 php artisan migrate 失败', 0 != $ppEQn); goto Mu1rE; U2vji: $ApDyX->make($scQcd); goto V6hiV; W9fbb: ModStart::clearCache(); goto i3PYM; kMBsB: FileUtil::safeCleanLocalTemp($scQcd); goto aDYgo; q5hNG: BizException::throwsIf('package不存在', !file_exists($scQcd)); goto jPSJp; PCZzk: BizException::throwsIfResponseError($ZrjxR); goto APifG; DFzdt: if (!empty($LZDno['delete'])) { goto gnzqy; dW40Z: foreach ($LZDno['delete'] as $okURS) { if (file_exists($dZDNw = base_path($okURS))) { @unlink($dZDNw); $Krz8K[] = "> {$okURS}"; } } goto fC8e8; fC8e8: $Krz8K[] = ''; goto hIK3q; gnzqy: $Krz8K[] = '删除文件：'; goto dW40Z; hIK3q: } goto bIp4o; bIp4o: $ApDyX->close(); goto W9fbb; aDYgo: FileUtil::safeCleanLocalTemp($dFEzs); goto B5iVn; B5iVn: return Response::generateSuccessData(array('logs' => $Krz8K)); goto dG9ZZ; APifG: $ApDyX = new Zipper(); goto U2vji; sH39c: $BYMEd = array(); goto zp455; tGYOa: if (!empty($LZDno['add'])) { goto k5GEE; BrVok: $Krz8K[] = ''; goto YRSue; soANh: foreach ($LZDno['add'] as $okURS) { goto ZLEiz; FwIH8: $Krz8K[] = "> {$okURS}"; goto F__ks; r7aLG: FileUtil::write(base_path($okURS), $V0Dls); goto FwIH8; ZLEiz: $V0Dls = $ApDyX->getFileContent($okURS); goto r7aLG; F__ks: } goto BrVok; k5GEE: $Krz8K[] = '新增文件：'; goto soANh; YRSue: } goto A9ZYv; i3PYM: try { $ppEQn = Artisan::call('migrate'); } catch (\Exception $RWZxh) { $ppEQn = -1; } goto T4beI; A9ZYv: if (!empty($LZDno['update'])) { goto HNZ0u; F4zQi: foreach ($LZDno['update'] as $okURS) { goto uegbQ; uegbQ: $V0Dls = $ApDyX->getFileContent($okURS); goto QvUlV; SfZDf: $Krz8K[] = "> {$okURS}"; goto L1V_S; QvUlV: FileUtil::write(base_path($okURS), $V0Dls); goto SfZDf; L1V_S: } goto d3aCc; d3aCc: $Krz8K[] = ''; goto f1Bnd; HNZ0u: $Krz8K[] = '修改文件：'; goto F4zQi; f1Bnd: } goto DFzdt; lPlHu: BizException::throwsIf('diffContent为空', empty($LZDno)); goto sH39c; Mu1rE: try { $ppEQn = Artisan::call('modstart:module-install-all'); } catch (\Exception $RWZxh) { $ppEQn = -1; } goto Fr2gL; V6hiV: $Krz8K = array(); goto tGYOa; c4n1x: $ZrjxR = FileUtil::filePathWritableCheck($BYMEd); goto PCZzk; jPSJp: BizException::throwsIf('diffContentFile不存在', !file_exists($dFEzs)); goto wlDj3; Fr2gL: BizException::throwsIf('调用 php artisan modstart:module-install-all 失败', 0 != $ppEQn); goto kMBsB; dG9ZZ: } }