<?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($tCUR6, $MGhSY = array(), $p23ja = null) { return CurlUtil::postJSONBody(self::REMOTE_BASE . $tCUR6, $MGhSY, array('header' => array('api-token' => $p23ja, 'X-Requested-With' => 'XMLHttpRequest'))); } public static function latest() { goto ZAax2; kVtqy: return $om_hh['data']; goto Vy__X; ZAax2: $om_hh = self::baseRequest('/api/app/latest', array('app' => AppConstant::APP, 'version' => AppConstant::VERSION)); goto cfmBG; cfmBG: BizException::throwsIfResponseError($om_hh); goto kVtqy; Vy__X: } public static function downloadPackage($p23ja, $oDLfz, $Bm01A, $GRVfW) { goto wXAi9; TN6bh: $qWHC7 = $om_hh['data']['package']; goto CQ3JB; TpUyG: BizException::throwsIfEmpty('安装包获取失败', $MGhSY); goto KsTgS; VCKlI: return Response::generateSuccessData(array('diffContentFile' => $JhjhO, 'package' => $CpeI2, 'packageSize' => filesize($CpeI2))); goto Ekzrc; wXAi9: $om_hh = self::baseRequest('/api/app/download_package', array('app' => $oDLfz, 'fromVersion' => $Bm01A, 'toVersion' => $GRVfW), $p23ja); goto ozJ7p; ozJ7p: BizException::throwsIfResponseError($om_hh); goto TN6bh; KsTgS: $CpeI2 = FileUtil::generateLocalTempPath('zip'); goto ni064; cyJHu: $IL3gB = $om_hh['data']['diffContent']; goto U39kz; rWsU8: file_put_contents($JhjhO, $IL3gB); goto VCKlI; CQ3JB: $PxKCQ = $om_hh['data']['packageMd5']; goto cyJHu; ni064: file_put_contents($CpeI2, $MGhSY); goto REWMn; REWMn: BizException::throwsIf('文件MD5校验失败', md5_file($CpeI2) != $PxKCQ); goto iSOUT; iSOUT: $JhjhO = FileUtil::generateLocalTempPath('json'); goto rWsU8; U39kz: $MGhSY = CurlUtil::getRaw($qWHC7); goto TpUyG; Ekzrc: } public static function upgradePackage($qWHC7, $JhjhO) { goto wp6zW; uU1CA: FileUtil::safeCleanLocalTemp($JhjhO); goto K2kYx; fPIw0: BizException::throwsIf('diffContentFile不存在', !file_exists($JhjhO)); goto shV5h; YeW5T: $om_hh = FileUtil::filePathWritableCheck($XTNOG); goto DBFFT; GY0rq: ModStart::clearCache(); goto pxQ5k; wp6zW: BizException::throwsIf('package不存在', !file_exists($qWHC7)); goto fPIw0; QKk0j: if (!empty($IL3gB['add'])) { $XTNOG = array_merge($XTNOG, $IL3gB['add']); } goto rw0c7; nDK26: $XTNOG = array(); goto QKk0j; TzYBk: if (!empty($IL3gB['add'])) { goto gRDfD; gRDfD: $sjJrw[] = '新增文件：'; goto SJ6O3; eTGGG: $sjJrw[] = ''; goto iWMgJ; SJ6O3: foreach ($IL3gB['add'] as $SgkW3) { goto rU18R; R0Rvk: $sjJrw[] = "> {$SgkW3}"; goto EuEhl; x6YAO: FileUtil::write(base_path($SgkW3), $OfwYj); goto R0Rvk; rU18R: $OfwYj = $S9cV0->getFileContent($SgkW3); goto x6YAO; EuEhl: } goto eTGGG; iWMgJ: } goto BDR0A; KaV7h: $S9cV0 = new Zipper(); goto Piha1; uw7qV: BizException::throwsIf('调用 php artisan migrate 失败', 0 != $rx99h); goto RPYae; O9fHL: FileUtil::safeCleanLocalTemp($qWHC7); goto uU1CA; BDR0A: if (!empty($IL3gB['update'])) { goto nhakf; nhakf: $sjJrw[] = '修改文件：'; goto FyDtm; WuXOi: $sjJrw[] = ''; goto R5Kod; FyDtm: foreach ($IL3gB['update'] as $SgkW3) { goto e3J1t; hgjUS: $sjJrw[] = "> {$SgkW3}"; goto v1cO8; wAi3W: FileUtil::write(base_path($SgkW3), $OfwYj); goto hgjUS; e3J1t: $OfwYj = $S9cV0->getFileContent($SgkW3); goto wAi3W; v1cO8: } goto WuXOi; R5Kod: } goto d2aq6; shV5h: $IL3gB = @json_decode(file_get_contents($JhjhO), true); goto OBVCt; Piha1: $S9cV0->make($qWHC7); goto dd1uP; iRtJr: BizException::throwsIf('调用 php artisan modstart:module-install-all 失败', 0 != $rx99h); goto O9fHL; vD3F2: $S9cV0->close(); goto GY0rq; OBVCt: BizException::throwsIf('diffContent为空', empty($IL3gB)); goto nDK26; RPYae: try { $rx99h = Artisan::call('modstart:module-install-all'); } catch (\Exception $se7TW) { $rx99h = -1; } goto iRtJr; dd1uP: $sjJrw = array(); goto TzYBk; pxQ5k: try { $rx99h = Artisan::call('migrate'); } catch (\Exception $se7TW) { $rx99h = -1; } goto uw7qV; rw0c7: if (!empty($IL3gB['update'])) { $XTNOG = array_merge($XTNOG, $IL3gB['update']); } goto YeW5T; K2kYx: return Response::generateSuccessData(array('logs' => $sjJrw)); goto AcyS2; d2aq6: if (!empty($IL3gB['delete'])) { goto SXZrl; SXZrl: $sjJrw[] = '删除文件：'; goto MRy_o; evSJ0: $sjJrw[] = ''; goto AEdb4; MRy_o: foreach ($IL3gB['delete'] as $SgkW3) { if (file_exists($pXscO = base_path($SgkW3))) { @unlink($pXscO); $sjJrw[] = "> {$SgkW3}"; } } goto evSJ0; AEdb4: } goto vD3F2; DBFFT: BizException::throwsIfResponseError($om_hh); goto KaV7h; AcyS2: } }