<?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($N0nrY, $Pg57y = array(), $gVIp7 = null) { return CurlUtil::postJSONBody(self::REMOTE_BASE . $N0nrY, $Pg57y, array('header' => array('api-token' => $gVIp7, 'X-Requested-With' => 'XMLHttpRequest'))); } public static function latest() { goto zwGf9; CmnD9: BizException::throwsIfResponseError($Ecj99); goto SoOLD; SoOLD: return $Ecj99['data']; goto QEGaZ; zwGf9: $Ecj99 = self::baseRequest('/api/app/latest', array('app' => AppConstant::APP, 'version' => AppConstant::VERSION)); goto CmnD9; QEGaZ: } public static function downloadPackage($gVIp7, $P0Pq4, $EVpLi, $VVfot) { goto xYXKF; j4EeT: $Pzx09 = $Ecj99['data']['package']; goto nijJ2; e9SCY: BizException::throwsIfEmpty('安装包获取失败', $Pg57y); goto V6_10; tXzvM: BizException::throwsIfResponseError($Ecj99); goto j4EeT; SayYx: $YWLjt = $Ecj99['data']['diffContent']; goto AvCaK; IrswS: file_put_contents($mS5Yr, $YWLjt); goto ofDly; ha828: $mS5Yr = FileUtil::generateLocalTempPath('json'); goto IrswS; nijJ2: $rGd6k = $Ecj99['data']['packageMd5']; goto SayYx; xYXKF: $Ecj99 = self::baseRequest('/api/app/download_package', array('app' => $P0Pq4, 'fromVersion' => $EVpLi, 'toVersion' => $VVfot), $gVIp7); goto tXzvM; vHhqT: BizException::throwsIf('文件MD5校验失败', md5_file($mTlfP) != $rGd6k); goto ha828; ofDly: return Response::generateSuccessData(array('diffContentFile' => $mS5Yr, 'package' => $mTlfP, 'packageSize' => filesize($mTlfP))); goto h0DJv; BmrbD: file_put_contents($mTlfP, $Pg57y); goto vHhqT; V6_10: $mTlfP = FileUtil::generateLocalTempPath('zip'); goto BmrbD; AvCaK: $Pg57y = CurlUtil::getRaw($Pzx09); goto e9SCY; h0DJv: } public static function upgradePackage($Pzx09, $mS5Yr) { goto EWtua; HspnC: if (!empty($YWLjt['update'])) { $dBz7d = array_merge($dBz7d, $YWLjt['update']); } goto bJgZz; O9zCc: if (!empty($YWLjt['add'])) { goto YmC37; YmC37: $VmuuB[] = '新增文件：'; goto uu8py; uu8py: foreach ($YWLjt['add'] as $Jm77a) { goto auIFs; sDSDD: FileUtil::write(base_path($Jm77a), $MPmfx); goto UzrOA; UzrOA: $VmuuB[] = "> {$Jm77a}"; goto zbDzJ; auIFs: $MPmfx = $pFknF->getFileContent($Jm77a); goto sDSDD; zbDzJ: } goto PDjlV; PDjlV: $VmuuB[] = ''; goto xT_LF; xT_LF: } goto jTn72; yKleV: BizException::throwsIfResponseError($Ecj99); goto ahz5p; tG8VN: BizException::throwsIf('调用 php artisan modstart:module-install-all 失败', 0 != $h0L7n); goto XKCQo; GiBcd: BizException::throwsIf('diffContent为空', empty($YWLjt)); goto AEEk4; ahz5p: $pFknF = new Zipper(); goto X_UaQ; XKCQo: FileUtil::safeCleanLocalTemp($Pzx09); goto fJ4d4; NyFEz: $VmuuB = array(); goto O9zCc; AEEk4: $dBz7d = array(); goto Yjx66; iR1tV: $pFknF->close(); goto H5pEY; aeBZo: BizException::throwsIf('调用 php artisan migrate 失败', 0 != $h0L7n); goto WPuyP; bJgZz: $Ecj99 = FileUtil::filePathWritableCheck($dBz7d); goto yKleV; fJ4d4: FileUtil::safeCleanLocalTemp($mS5Yr); goto lh22M; WPuyP: try { $h0L7n = Artisan::call('modstart:module-install-all'); } catch (\Exception $fWY9h) { $h0L7n = -1; } goto tG8VN; EWtua: BizException::throwsIf('package不存在', !file_exists($Pzx09)); goto KuIsk; reRFf: try { $h0L7n = Artisan::call('migrate'); } catch (\Exception $fWY9h) { $h0L7n = -1; } goto aeBZo; Yjx66: if (!empty($YWLjt['add'])) { $dBz7d = array_merge($dBz7d, $YWLjt['add']); } goto HspnC; H5pEY: ModStart::clearCache(); goto reRFf; jTn72: if (!empty($YWLjt['update'])) { goto IT07w; fbdTS: $VmuuB[] = ''; goto VtdNV; IT07w: $VmuuB[] = '修改文件：'; goto ad1Mb; ad1Mb: foreach ($YWLjt['update'] as $Jm77a) { goto iToZZ; RX6n0: $VmuuB[] = "> {$Jm77a}"; goto NfwR9; iToZZ: $MPmfx = $pFknF->getFileContent($Jm77a); goto NVFO2; NVFO2: FileUtil::write(base_path($Jm77a), $MPmfx); goto RX6n0; NfwR9: } goto fbdTS; VtdNV: } goto C7pfM; C7pfM: if (!empty($YWLjt['delete'])) { goto CrSoc; CrSoc: $VmuuB[] = '删除文件：'; goto pO13R; pO13R: foreach ($YWLjt['delete'] as $Jm77a) { if (file_exists($ooyHY = base_path($Jm77a))) { @unlink($ooyHY); $VmuuB[] = "> {$Jm77a}"; } } goto gWaZM; gWaZM: $VmuuB[] = ''; goto BE3AN; BE3AN: } goto iR1tV; rCRtd: $YWLjt = @json_decode(file_get_contents($mS5Yr), true); goto GiBcd; X_UaQ: $pFknF->make($Pzx09); goto NyFEz; lh22M: return Response::generateSuccessData(array('logs' => $VmuuB)); goto FdQ0X; KuIsk: BizException::throwsIf('diffContentFile不存在', !file_exists($mS5Yr)); goto rCRtd; FdQ0X: } }