mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
swip update
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.6.0-beta12');
|
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.6.0-beta13');
|
||||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2021-06-23');
|
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-02-14');
|
||||||
defined('IN_TRACKER') || define('IN_TRACKER', true);
|
defined('IN_TRACKER') || define('IN_TRACKER', true);
|
||||||
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||||
|
|||||||
+43
-40
@@ -182,29 +182,49 @@ class Update extends Install
|
|||||||
|
|
||||||
public function listVersions()
|
public function listVersions()
|
||||||
{
|
{
|
||||||
$client = new Client();
|
|
||||||
$url = "https://api.github.com/repos/xiaomlove/nexusphp/releases";
|
$url = "https://api.github.com/repos/xiaomlove/nexusphp/releases";
|
||||||
$response = $client->get($url, ['timeout' => 10,]);
|
$versions = $this->requestGithub($url);
|
||||||
if (($statusCode = $response->getStatusCode()) != 200) {
|
|
||||||
throw new \RuntimeException("获取版本列表失败,状态码:$statusCode");
|
|
||||||
}
|
|
||||||
if ($response->getBody()->getSize() <= 0) {
|
|
||||||
throw new \RuntimeException("获取版本列表失败,结果为空");
|
|
||||||
}
|
|
||||||
$bodyString = $response->getBody()->getContents();
|
|
||||||
$this->doLog("[LIST_VERSION_RESPONSE]: $bodyString");
|
|
||||||
$versions = json_decode($bodyString, true);
|
|
||||||
if (empty($versions) || !is_array($versions)) {
|
|
||||||
throw new \RuntimeException("获取版本列表结果异常");
|
|
||||||
}
|
|
||||||
return array_reverse($versions);
|
return array_reverse($versions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function downAndExtractCode($url)
|
public function getLatestCommit()
|
||||||
|
{
|
||||||
|
$url = "https://api.github.com/repos/xiaomlove/nexusphp/commits/php8";
|
||||||
|
return $this->requestGithub($url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function requestGithub($url)
|
||||||
|
{
|
||||||
|
$client = new Client();
|
||||||
|
$logPrefix = "请求 github: $url";
|
||||||
|
$response = $client->get($url, ['timeout' => 10,]);
|
||||||
|
if (($statusCode = $response->getStatusCode()) != 200) {
|
||||||
|
throw new \RuntimeException("$logPrefix 失败,状态码:$statusCode");
|
||||||
|
}
|
||||||
|
if ($response->getBody()->getSize() <= 0) {
|
||||||
|
throw new \RuntimeException("$logPrefix 失败,结果为空");
|
||||||
|
}
|
||||||
|
$bodyString = $response->getBody()->getContents();
|
||||||
|
$this->doLog("[REQUEST_GITHUB_RESPONSE]: $bodyString");
|
||||||
|
$results = json_decode($bodyString, true);
|
||||||
|
if (empty($results) || !is_array($results)) {
|
||||||
|
throw new \RuntimeException("$logPrefix 结果异常");
|
||||||
|
}
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function downAndExtractCode($url): bool
|
||||||
{
|
{
|
||||||
$arr = explode('/', $url);
|
$arr = explode('/', $url);
|
||||||
$basename = last($arr);
|
$basename = last($arr);
|
||||||
$suffix = '.tar.gz';
|
$isZip = false;
|
||||||
|
if (Str::contains($basename,'.zip')) {
|
||||||
|
$isZip = true;
|
||||||
|
$basename = strstr($basename, '.zip', true);
|
||||||
|
$suffix = ".zip";
|
||||||
|
} else {
|
||||||
|
$suffix = '.tar.gz';
|
||||||
|
}
|
||||||
$filename = sprintf('%s/nexusphp-%s-%s%s', sys_get_temp_dir(), $basename, date('YmdHis'), $suffix);
|
$filename = sprintf('%s/nexusphp-%s-%s%s', sys_get_temp_dir(), $basename, date('YmdHis'), $suffix);
|
||||||
$client = new Client();
|
$client = new Client();
|
||||||
$response = $client->request('GET', $url, ['sink' => $filename]);
|
$response = $client->request('GET', $url, ['sink' => $filename]);
|
||||||
@@ -223,36 +243,19 @@ class Update extends Install
|
|||||||
$this->doLog('SUCCESS_DOWNLOAD');
|
$this->doLog('SUCCESS_DOWNLOAD');
|
||||||
$extractDir = str_replace($suffix, "", $filename);
|
$extractDir = str_replace($suffix, "", $filename);
|
||||||
$command = "mkdir -p $extractDir";
|
$command = "mkdir -p $extractDir";
|
||||||
$result = exec($command, $output, $result_code);
|
$this->executeCommand($command);
|
||||||
$this->doLog(sprintf(
|
|
||||||
"command: %s, output: %s, result_code: %s, result: %s",
|
|
||||||
$command, json_encode($output), $result_code, $result
|
|
||||||
));
|
|
||||||
if ($result_code != 0) {
|
|
||||||
throw new \RuntimeException("创建解压目录:$extractDir 失败, result_code: $result_code");
|
|
||||||
}
|
|
||||||
|
|
||||||
$command = "tar -xf $filename -C $extractDir";
|
if ($isZip) {
|
||||||
$result = exec($command, $output, $result_code);
|
$command = "unzip $filename -d $extractDir";
|
||||||
$this->doLog(sprintf(
|
} else {
|
||||||
"command: %s, output: %s, result_code: %s, result: %s",
|
$command = "tar -xf $filename -C $extractDir";
|
||||||
$command, json_encode($output), $result_code, $result
|
|
||||||
));
|
|
||||||
if ($result_code != 0) {
|
|
||||||
throw new \RuntimeException("解压文件:$filename 到:$extractDir 失败, result_code: $result_code");
|
|
||||||
}
|
}
|
||||||
|
$this->executeCommand($command);
|
||||||
|
|
||||||
foreach (glob("$extractDir/*") as $path) {
|
foreach (glob("$extractDir/*") as $path) {
|
||||||
if (is_dir($path)) {
|
if (is_dir($path)) {
|
||||||
$command = sprintf('cp -Rf %s/* %s', $path, ROOT_PATH);
|
$command = sprintf('cp -Rf %s/* %s', $path, ROOT_PATH);
|
||||||
$result = exec($command, $output, $result_code);
|
$this->executeCommand($command);
|
||||||
$this->doLog(sprintf(
|
|
||||||
"command: %s, output: %s, result_code: %s, result: %s",
|
|
||||||
$command, json_encode($output), $result_code, $result
|
|
||||||
));
|
|
||||||
if ($result_code != 0) {
|
|
||||||
throw new \RuntimeException("复制错误, result_code: $result_code");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,54 +37,69 @@ if ($currentStep == 2) {
|
|||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
$error = $exception->getMessage();
|
$error = $exception->getMessage();
|
||||||
}
|
}
|
||||||
$versionHeader = [
|
if (!$isPost) {
|
||||||
'checkbox' => '选择',
|
$versionHeader = [
|
||||||
'tag_name' => '版本(标签)',
|
'checkbox' => '选择',
|
||||||
'name' => '名称',
|
'tag_name' => '版本(标签)',
|
||||||
'published_at' => '发布时间',
|
'name' => '名称',
|
||||||
];
|
'published_at' => '发布时间',
|
||||||
$tableRows[] = [
|
];
|
||||||
'checkbox' => sprintf('<input type="radio" name="version_url" value="manual"/>'),
|
|
||||||
'tag_name' => '手动更新',
|
|
||||||
'name' => '如若有改动不宜全量覆盖,请勾选此选项并确保已经手动更新了代码',
|
|
||||||
'published_at' => '---',
|
|
||||||
];
|
|
||||||
foreach ($versions as $version) {
|
|
||||||
if ($version['draft']) {
|
|
||||||
// continue;
|
|
||||||
}
|
|
||||||
$time = \Carbon\Carbon::parse($version['published_at']);
|
|
||||||
$time->tz = nexus_env('TIMEZONE');
|
|
||||||
$versionUrl = $version['tag_name'] . '|' . $version['tarball_url'];
|
|
||||||
$checked = !empty($_REQUEST['version_url']) && $_REQUEST['version_url'] == $versionUrl ? ' checked' : '';
|
|
||||||
$tableRows[] = [
|
$tableRows[] = [
|
||||||
'checkbox' => sprintf('<input type="radio" name="version_url" value="%s"%s/>', $versionUrl, $checked),
|
'checkbox' => sprintf('<input type="radio" name="version_url" value="manual"/>'),
|
||||||
'tag_name' => $version['tag_name'],
|
'tag_name' => '手动更新',
|
||||||
'name' => $version['name'],
|
'name' => '如若有改动不宜全量覆盖,请勾选此选项并确保已经手动更新了代码',
|
||||||
|
'published_at' => '---',
|
||||||
|
];
|
||||||
|
$latestCommit = $update->getLatestCommit();
|
||||||
|
$time = \Carbon\Carbon::parse($latestCommit['committer']['date']);
|
||||||
|
$time->tz = nexus_env('TIMEZONE');
|
||||||
|
$tableRows[] = [
|
||||||
|
'checkbox' => sprintf('<input type="radio" name="version_url" value="development"/>'),
|
||||||
|
'tag_name' => '最新开发代码',
|
||||||
|
'name' => "仅限开发测试!最新提交:" . $latestCommit['commit']['message'],
|
||||||
'published_at' => $time->format('Y-m-d H:i:s'),
|
'published_at' => $time->format('Y-m-d H:i:s'),
|
||||||
];
|
];
|
||||||
|
foreach ($versions as $version) {
|
||||||
|
if ($version['draft']) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$time = \Carbon\Carbon::parse($version['published_at']);
|
||||||
|
$time->tz = nexus_env('TIMEZONE');
|
||||||
|
$versionUrl = $version['tag_name'] . '|' . $version['tarball_url'];
|
||||||
|
$checked = !empty($_REQUEST['version_url']) && $_REQUEST['version_url'] == $versionUrl ? ' checked' : '';
|
||||||
|
$tableRows[] = [
|
||||||
|
'checkbox' => sprintf('<input type="radio" name="version_url" value="%s"%s/>', $versionUrl, $checked),
|
||||||
|
'tag_name' => $version['tag_name'],
|
||||||
|
'name' => $version['name'],
|
||||||
|
'published_at' => $time->format('Y-m-d H:i:s'),
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// dd($tableRows);
|
// dd($tableRows);
|
||||||
while ($isPost) {
|
while ($isPost) {
|
||||||
try {
|
try {
|
||||||
if (empty($_REQUEST['version_url'])) {
|
if (empty($_REQUEST['version_url'])) {
|
||||||
throw new \RuntimeException("没有选择版本");
|
throw new \RuntimeException("没有选择版本");
|
||||||
}
|
}
|
||||||
|
$downloadUrl = '';
|
||||||
if ($_REQUEST['version_url'] == 'manual') {
|
if ($_REQUEST['version_url'] == 'manual') {
|
||||||
$update->nextStep();
|
$update->nextStep();
|
||||||
}
|
} elseif ($_REQUEST['version_url'] == 'development') {
|
||||||
$versionUrlArr = explode('|', $_REQUEST['version_url']);
|
$downloadUrl = 'https://github.com/xiaomlove/nexusphp/archive/refs/heads/php8.zip';
|
||||||
$version = strtolower($versionUrlArr[0]);
|
} else {
|
||||||
$downloadUrl = $versionUrlArr[1];
|
$versionUrlArr = explode('|', $_REQUEST['version_url']);
|
||||||
if (\Illuminate\Support\Str::startsWith($version, 'v')) {
|
$version = strtolower($versionUrlArr[0]);
|
||||||
$version = substr($version, 1);
|
$downloadUrl = $versionUrlArr[1];
|
||||||
}
|
if (\Illuminate\Support\Str::startsWith($version, 'v')) {
|
||||||
$update->doLog("version: $version, downloadUrl: $downloadUrl, currentVersion: " . VERSION_NUMBER);
|
$version = substr($version, 1);
|
||||||
if (version_compare($version, VERSION_NUMBER, '<=')) {
|
}
|
||||||
throw new \RuntimeException("必须选择一个高于当前版本(" . VERSION_NUMBER . ")的");
|
$update->doLog("version: $version, downloadUrl: $downloadUrl, currentVersion: " . VERSION_NUMBER);
|
||||||
|
if (version_compare($version, VERSION_NUMBER, '<=')) {
|
||||||
|
throw new \RuntimeException("必须选择一个高于当前版本(" . VERSION_NUMBER . ")的");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$update->downAndExtractCode($downloadUrl);
|
$update->downAndExtractCode($downloadUrl);
|
||||||
|
|
||||||
$update->nextStep();
|
$update->nextStep();
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
$update->doLog($exception->getMessage() . $exception->getTraceAsString());
|
$update->doLog($exception->getMessage() . $exception->getTraceAsString());
|
||||||
|
|||||||
Reference in New Issue
Block a user