Check PHP version before updating

This commit is contained in:
Pig Fang 2019-07-05 14:48:12 +08:00
parent 4c2c74dafb
commit a36c31e5bd
9 changed files with 33 additions and 16 deletions

View File

@ -104,7 +104,7 @@ class MarketController extends Controller
protected function getAllAvailablePlugins()
{
$registryVersion = 1;
if (app()->environment('testing') || ! $this->registryCache) {
if (app()->runningUnitTests() || ! $this->registryCache) {
$registries = collect(explode(',', config('plugins.registry')));
$this->registryCache = $registries->map(function ($registry) use ($registryVersion) {
try {

View File

@ -67,8 +67,8 @@ class UpdateController extends Controller
protected function getUpdateInfo()
{
$acceptableSpec = 1;
if (! $this->info) {
$acceptableSpec = 2;
if (app()->runningUnitTests() || ! $this->info) {
try {
$json = $this->guzzle->request(
'GET',
@ -79,7 +79,7 @@ class UpdateController extends Controller
if (Arr::get($info, 'spec') == $acceptableSpec) {
$this->info = $info;
} else {
$this->error = trans('admin.update.spec');
$this->error = trans('admin.update.errors.spec');
}
} catch (Exception $e) {
$this->error = $e->getMessage();
@ -93,6 +93,12 @@ class UpdateController extends Controller
{
$this->getUpdateInfo();
$php = Arr::get($this->info, 'php');
if (Comparator::lessThan(PHP_VERSION, $php)) {
$this->error = trans('admin.update.errors.php', ['version' => $php]);
return false;
}
return Comparator::greaterThan(Arr::get($this->info, 'latest'), $this->currentVersion);
}
}

View File

@ -22,7 +22,7 @@ return [
'update_source' => env(
'UPDATE_SOURCE',
'https://dev.azure.com/blessing-skin/51010f6d-9f99-40f1-a262-0a67f788df32/_apis/git/'.
'repositories/a9ff8df7-6dc3-4ff8-bb22-4871d3a43936/Items?path=%2Fupdate.json'
'repositories/a9ff8df7-6dc3-4ff8-bb22-4871d3a43936/Items?path=%2Fupdate_2.json'
),
/*

View File

@ -126,8 +126,6 @@ update:
check-github: <a href=":url" target="_blank" class="el-button pull-right">Check GitHub Releases</a>
button: Update Now
spec: Current update source is not supported.
cautions:
title: Cautions
text: |
@ -141,6 +139,8 @@ update:
errors:
connection: "Unable to access to current update source. Details: :error"
spec: Current update source is not supported.
php: Your PHP version is too low to update. Requires :version or later.
download:
errors:

View File

@ -131,8 +131,6 @@ update:
check-github: <a href=":url" target="_blank" class="el-button pull-right">查看 GitHub Releases</a>
button: 马上升级
spec: 不支持当前的更新源。
cautions:
title: 注意事项
text: |
@ -146,6 +144,8 @@ update:
errors:
connection: 无法访问当前更新源。详细信息::error
spec: 不支持当前的更新源。
php: PHP 版本过低,至少需要 :version。
download:
errors:

View File

@ -16,6 +16,7 @@
- Optimized panel of changing theme color.
- Tweaked some links at closet page.
- Limited that only super administrators can visit update pages.
- Update source specification version has been changed to `2`.
## Fixed

View File

@ -16,6 +16,7 @@
- 优化「更改配色」的面板
- 调整衣柜页面上的某些链接
- 限制仅超级管理员才能访问升级页面
- 更新源信息 spec 版本更改为 `2`
## 修复

View File

@ -26,7 +26,7 @@ zip -9 -r blessing-skin-server-$RELEASE_TAG.zip \
mkdir dist
cd dist
cp ../blessing-skin-server-$RELEASE_TAG.zip blessing-skin-server-$RELEASE_TAG.zip
echo "{\"spec\":1,\"latest\":\"$RELEASE_TAG\",\"url\":\"https://dev.azure.com/blessing-skin/51010f6d-9f99-40f1-a262-0a67f788df32/_apis/git/repositories/a9ff8df7-6dc3-4ff8-bb22-4871d3a43936/Items?path=%2Fblessing-skin-server-$RELEASE_TAG.zip\"}" > update.json
echo "{\"spec\":2,\"php\":\"7.1.8\",\"latest\":\"$RELEASE_TAG\",\"url\":\"https://dev.azure.com/blessing-skin/51010f6d-9f99-40f1-a262-0a67f788df32/_apis/git/repositories/a9ff8df7-6dc3-4ff8-bb22-4871d3a43936/Items?path=%2Fblessing-skin-server-$RELEASE_TAG.zip\"}" > update_2.json
git init
git add .
git commit -m "Publish"

View File

@ -32,9 +32,17 @@ class UpdateControllerTest extends TestCase
// Missing `spec` field
$this->appendToGuzzleQueue([
new Response(200, [], json_encode(['latest' => '8.9.3', 'url' => ''])),
new Response(200, [], $this->mockFakeUpdateInfo('8.9.3', ['spec' => 0])),
// Weird. Don't remove the following line, or the tests will fail.
new Response(200, [], $this->mockFakeUpdateInfo('8.9.3', ['php' => '100.0.0'])),
]);
$this->get('/admin/update')->assertSee(trans('admin.update.spec'));
$this->get('/admin/update')->assertSee(trans('admin.update.errors.spec'));
// Low PHP version
$this->appendToGuzzleQueue([
new Response(200, [], $this->mockFakeUpdateInfo('8.9.3', ['php' => '100.0.0'])),
]);
$this->get('/admin/update')->assertSee(trans('admin.update.errors.php', ['version' => '100.0.0']));
// New version available
$this->appendToGuzzleQueue([
@ -91,12 +99,13 @@ class UpdateControllerTest extends TestCase
]);
}
protected function mockFakeUpdateInfo($version)
protected function mockFakeUpdateInfo(string $version, $extra = [])
{
return json_encode([
'spec' => 1,
return json_encode(array_merge([
'spec' => 2,
'php' => '7.1.8',
'latest' => $version,
'url' => "https://whatever.test/$version/update.zip",
]);
], $extra));
}
}