<?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($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 SyGB0; SyGB0: $ZrjxR = self::baseRequest('/api/app/latest', array('app' => AppConstant::APP, 'version' => AppConstant::VERSION)); goto fq9P5; fq9P5: BizException::throwsIfResponseError($ZrjxR); goto oxP6D; oxP6D: return $ZrjxR['data']; goto cKH6R; cKH6R: } public static function downloadPackage($ufeje, $WXVE3, $QUpeI, $GPX1G) { goto kIiiF; WJpve: $HX5uI = $ZrjxR['data']['packageMd5']; goto jCwPy; YCpcy: $dFEzs = FileUtil::generateLocalTempPath('json'); goto vh8l9; GQEiG: return Response::generateSuccessData(array('diffContentFile' => $dFEzs, 'package' => $EilHX, 'packageSize' => filesize($EilHX))); goto lbqXy; sQNZU: BizException::throwsIfEmpty('安装包获取失败', $cwaKT); goto WFyic; NftDC: file_put_contents($EilHX, $cwaKT); goto p_Sub; YMUdD: $scQcd = $ZrjxR['data']['package']; goto WJpve; jCwPy: $LZDno = $ZrjxR['data']['diffContent']; goto PxD2S; kIiiF: $ZrjxR = self::baseRequest('/api/app/download_package', array('app' => $WXVE3, 'fromVersion' => $QUpeI, 'toVersion' => $GPX1G), $ufeje); goto F3GJy; vh8l9: file_put_contents($dFEzs, $LZDno); goto GQEiG; WFyic: $EilHX = FileUtil::generateLocalTempPath('zip'); goto NftDC; F3GJy: BizException::throwsIfResponseError($ZrjxR); goto YMUdD; PxD2S: $cwaKT = CurlUtil::getRaw($scQcd); goto sQNZU; p_Sub: BizException::throwsIf('文件MD5校验失败', md5_file($EilHX) != $HX5uI); goto YCpcy; lbqXy: } public static function upgradePackage($scQcd, $dFEzs) { goto cBS40; rI5Md: $LZDno = @json_decode(file_get_contents($dFEzs), true); goto zAyoT; hNBoL: $BYMEd = array(); goto MUR4n; nkhX0: BizException::throwsIf('调用 php artisan modstart:module-install-all 失败', 0 != $ppEQn); goto tQQLm; cBS40: BizException::throwsIf('package不存在', !file_exists($scQcd)); goto Imx6W; c_9AD: return Response::generateSuccessData(array('logs' => $Krz8K)); goto muLew; JKSGT: FileUtil::safeCleanLocalTemp($dFEzs); goto c_9AD; hyADO: $ApDyX->close(); goto W8JSb; mH9_T: if (!empty($LZDno['add'])) { goto zqoTX; zqoTX: $Krz8K[] = '新增文件：'; goto BWzF8; Ertls: $Krz8K[] = ''; goto Gjalx; BWzF8: foreach ($LZDno['add'] as $okURS) { goto EVfJW; EVfJW: $V0Dls = $ApDyX->getFileContent($okURS); goto kzdXy; zZ1TS: $Krz8K[] = "> {$okURS}"; goto d9GnL; kzdXy: FileUtil::write(base_path($okURS), $V0Dls); goto zZ1TS; d9GnL: } goto Ertls; Gjalx: } goto ym7eJ; YorqT: $ApDyX = new Zipper(); goto Tohi6; EO4Wd: try { $ppEQn = Artisan::call('migrate'); } catch (\Exception $RWZxh) { $ppEQn = -1; } goto IonY3; ym7eJ: if (!empty($LZDno['update'])) { goto mw6d2; mw6d2: $Krz8K[] = '修改文件：'; goto tYQIg; hpBGt: $Krz8K[] = ''; goto Kjc1Z; tYQIg: foreach ($LZDno['update'] as $okURS) { goto XYECx; UJfDB: $Krz8K[] = "> {$okURS}"; goto cnBot; XYECx: $V0Dls = $ApDyX->getFileContent($okURS); goto eHglH; eHglH: FileUtil::write(base_path($okURS), $V0Dls); goto UJfDB; cnBot: } goto hpBGt; Kjc1Z: } goto ig2fH; pOg8c: $ppEQn = Artisan::call('modstart:module-install-all'); goto nkhX0; Hr9KK: if (!empty($LZDno['update'])) { $BYMEd = array_merge($BYMEd, $LZDno['update']); } goto m0hB9; Tohi6: $ApDyX->make($scQcd); goto QBCmG; IonY3: BizException::throwsIf('调用 php artisan migrate 失败', 0 != $ppEQn); goto pOg8c; ig2fH: if (!empty($LZDno['delete'])) { goto HJqKA; uKs2q: $Krz8K[] = ''; goto pMjZk; gpx7_: foreach ($LZDno['delete'] as $okURS) { if (file_exists($dZDNw = base_path($okURS))) { @unlink($dZDNw); $Krz8K[] = "> {$okURS}"; } } goto uKs2q; HJqKA: $Krz8K[] = '删除文件：'; goto gpx7_; pMjZk: } goto hyADO; tQQLm: FileUtil::safeCleanLocalTemp($scQcd); goto JKSGT; W8JSb: ModStart::clearCache(); goto EO4Wd; MUR4n: if (!empty($LZDno['add'])) { $BYMEd = array_merge($BYMEd, $LZDno['add']); } goto Hr9KK; m0hB9: $ZrjxR = FileUtil::filePathWritableCheck($BYMEd); goto huSES; zAyoT: BizException::throwsIf('diffContent为空', empty($LZDno)); goto hNBoL; huSES: BizException::throwsIfResponseError($ZrjxR); goto YorqT; QBCmG: $Krz8K = array(); goto mH9_T; Imx6W: BizException::throwsIf('diffContentFile不存在', !file_exists($dFEzs)); goto rI5Md; muLew: } }