fix comparing versions contain hyphen
This commit is contained in:
parent
6ef9f90beb
commit
967ef3e1b0
|
|
@ -97,7 +97,7 @@ class SetupController extends Controller
|
||||||
|
|
||||||
public function update()
|
public function update()
|
||||||
{
|
{
|
||||||
if (version_compare(config('app.version'), option('version', ''), '<=')) {
|
if (Utils::versionCompare(config('app.version'), option('version', ''), '<=')) {
|
||||||
// no updates available
|
// no updates available
|
||||||
return view('setup.locked');
|
return view('setup.locked');
|
||||||
}
|
}
|
||||||
|
|
@ -118,7 +118,7 @@ class SetupController extends Controller
|
||||||
|
|
||||||
// skip if the file is not valid or expired
|
// skip if the file is not valid or expired
|
||||||
if (!isset($matches[2]) ||
|
if (!isset($matches[2]) ||
|
||||||
version_compare($matches[2], config('app.version'), '<')) {
|
Utils::versionCompare($matches[2], config('app.version'), '<')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ class UpdateController extends Controller
|
||||||
if ($this->getUpdateInfo()) {
|
if ($this->getUpdateInfo()) {
|
||||||
$info['latest_version'] = $this->getUpdateInfo('latest_version');
|
$info['latest_version'] = $this->getUpdateInfo('latest_version');
|
||||||
|
|
||||||
$info['new_version_available'] = version_compare(
|
$info['new_version_available'] = Utils::versionCompare(
|
||||||
$info['latest_version'],
|
$info['latest_version'],
|
||||||
$info['current_version'], '>'
|
$info['current_version'], '>'
|
||||||
);
|
);
|
||||||
|
|
@ -95,7 +95,7 @@ class UpdateController extends Controller
|
||||||
{
|
{
|
||||||
$latest = $this->getUpdateInfo('latest_version');
|
$latest = $this->getUpdateInfo('latest_version');
|
||||||
|
|
||||||
return version_compare($latest, $this->currentVersion, '>') && $this->getReleaseInfo($latest);
|
return Utils::versionCompare($latest, $this->currentVersion, '>') && $this->getReleaseInfo($latest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function download(Request $request)
|
public function download(Request $request)
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ class BootServiceProvider extends ServiceProvider
|
||||||
throw new PrettyPageException(trans('setup.file.permission-error'), -1);
|
throw new PrettyPageException(trans('setup.file.permission-error'), -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version_compare(config('app.version'), option('version', ''), '>')) {
|
if (Utils::versionCompare(config('app.version'), option('version', ''), '>')) {
|
||||||
return redirect('/setup/update')->send();
|
return redirect('/setup/update')->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
use Log;
|
use Log;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use Storage as LaravelStorage;
|
use Storage as LaravelStorage;
|
||||||
use App\Exceptions\PrettyPageException;
|
use App\Exceptions\PrettyPageException;
|
||||||
|
|
||||||
|
|
@ -26,6 +27,43 @@ class Utils
|
||||||
return $ip;
|
return $ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function versionCompare($version1, $version2, $operator = null)
|
||||||
|
{
|
||||||
|
$versions = [$version1, $version2];
|
||||||
|
|
||||||
|
// pre-processing for version contains hyphen
|
||||||
|
foreach ([0, 1] as $offset) {
|
||||||
|
if (false !== ($result = self::parseVersionWithHyphen($versions[$offset]))) {
|
||||||
|
$versions[$offset] = $result;
|
||||||
|
} else {
|
||||||
|
$versions[$offset] = ['main' => $versions[$offset], 'sub' => ''];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version_compare($versions[0]['main'], $versions[1]['main'], '=')) {
|
||||||
|
// v3.2-pr < v3.2
|
||||||
|
if ($versions[0]['sub'] != "" || $versions[1]['sub'] != "") {
|
||||||
|
return version_compare($versions[0]['sub'], $versions[1]['sub'], $operator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return version_compare($versions[0]['main'], $versions[1]['main'], $operator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function parseVersionWithHyphen($version)
|
||||||
|
{
|
||||||
|
preg_match('/(.*)-(.*)/', $version, $matches);
|
||||||
|
|
||||||
|
if (isset($matches[2])) {
|
||||||
|
return [
|
||||||
|
'main' => $matches[1],
|
||||||
|
'sub' => $matches[2]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rename uploaded file
|
* Rename uploaded file
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @Author: printempw
|
|
||||||
* @Date: 2016-11-18 16:25:35
|
|
||||||
* @Last Modified by: printempw
|
|
||||||
* @Last Modified time: 2016-12-11 22:42:31
|
|
||||||
*/
|
|
||||||
|
|
||||||
Option::set('update_source', config('option')['update_source']);
|
|
||||||
Option::set('version', '3.2');
|
|
||||||
|
|
||||||
return [
|
|
||||||
'v3.2 新加入了插件系统,支持的插件请去程序发布帖查看'
|
|
||||||
];
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
* @Author: printempw
|
* @Author: printempw
|
||||||
* @Date: 2016-12-31 23:37:34
|
* @Date: 2016-12-31 23:37:34
|
||||||
* @Last Modified by: printempw
|
* @Last Modified by: printempw
|
||||||
* @Last Modified time: 2016-12-31 23:49:39
|
* @Last Modified time: 2017-01-02 16:22:32
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!Illuminate\Support\Str::startsWith(option('update_source'), 'http')) {
|
if (!Illuminate\Support\Str::startsWith(option('update_source'), 'http')) {
|
||||||
|
|
@ -20,4 +20,8 @@ foreach (config('options') as $key => $value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Option::set('version', '3.2-pr8');
|
Option::set('version', '3.2.0');
|
||||||
|
|
||||||
|
return [
|
||||||
|
'v3.2 新加入了插件系统,支持的插件请去程序发布帖查看'
|
||||||
|
];
|
||||||
Loading…
Reference in New Issue
Block a user